Tutorial 3


Library file function definitions: Problems:







Prog not implemented:

-> (defun prog-length (L)
	(prog ((sum 0))
		again
			(cond ((atom L) (return sum)))
			(setq sum (1+ sum))
			(setq L (cdr L))
			(go again)))

-> (prog-length '(4 3 2 1 5))


Problem 1:

1. (third (the quick brown fox))

   CAUSE: Missing quote in front of list
   SOLUTION: (third '(the quick brown fox))

2. (list 2 and 2 is 4)

   CAUSE: Missing quote around 'and' and 'is'
   SOLUTION: (list 2 'and 2 'is 4)


3. (cdr (car '(a b c)))

        CAUSE: cdr needs a list as input
        SOLUTION: (cdr (list (car '(a b c))))

4.  (+ 1 '(length (list t t t t)))

   CAUSE: Unnecessary quote before 'length' function.
   SOLUTION: (+ 1 (length (list t t t t)))

5. (evenp (+ 4.0 2.0))

   CAUSE: evenp requires parameters to be integers.
   SOLUTION: (evenp (+ 4 2))

6. (cons 'mary (betty carolyn))

   CAUSE: Missing quote in front of list.
   SOLUTION: (cons 'mary '(betty carolyn))

7. (append '(a b c) 'd)
  
   ERROR: No error, just incorrect answer (A B C .D)
   CAUSE: Missing brackets around 'd': append really wants 2 lists
   SOLUTION: (append '(a b c) '(d))

8. (cons 'mary (list betty carolyn))

   CAUSE: Missing quotes in front of atoms
   SOLUTION:  (cons 'mary (list 'betty 'carolyn))

9. (1+ '(cdr (2 3 4)))

   CAUSE: The function 1+ cannot increment elements 
of a list b iteself
   SOLUTION: (1+ (car '(2 3 4)))


10.   (setq x length (a b c))
  
   CAUSE: Missing backets around length and quote around list
   SOLUTION: (setq x (length '(a b c)))