|
CS 3723/3721 Programming Languages Spring 2005 Recitation 11 Lisp: Functions and mapcar Week 11: Apr 4-8 Due (on time): 2005-04-11 23:59:59 Due (late): 2005-04-15 23:59:59 |
Recitation 11 must be submitted
following directions at: submissions with deadlines
|
Trying out recursion in C/C++/Java:
(defun addvec (list) (cond ((null list) 0) (t (+ (car list) (addvec (cdr list)))) ))along with vecmul above to define an inner product function innprod. [For example, (innprod '(1 2 3) '(7 8 9)) returns 1*7 + 2*8 + 3*9 or 50. Hint: this is very easy.]
> (mapcar '1+ '(1 2 3)) > (mapcar '+ '(1 2 3) '(8 10 12)) > (mapcar '* '(1 2 3) '(8 10 12)) > (mapcar 'car '((a b c) (x y z) (r s t))) > (mapcar 'cdr '((a b c) (x y z) (r s t))) > (apply '+ '(2 4 6 8)) > (apply '* '(1 2 3 4 5)) > (apply 'list '(a b c d))
(defun innprod (x y) (apply '+ (mapcar '* x y)) )
Contents of submission
for Recitation 11: Last Name, First Name; Course Number; Recitation Number. Answers to questions 1 through 10 above.
|