tags:

views:

130

answers:

2

I now have a problem on using "reduce" to implement my own version of copy-list. This is what I have done:

(defun my-copy-list (lst)  
  (reduce #'(lambda (x y)  
              (cons x y)) 
          lst :initial-value nil :from-end t))

However, my teacher said there is no need to use that lambda, I am confused on this. How may we achieve the same functionality without using that lambda (but must use 'reduce'). Thanks a lot.

+2  A: 

this is what cons does: it takes two values and pairs them.

this is what (lambda (x y) (cons x y)) does: it takes two values and pairs them.

Jimmy
+11  A: 

What your teacher means is that you're defining this function

(lambda (x y) (cons x y))

But there's already a function that exists to do that -- cons itself. So instead of passing your lambda as an argument to reduce, you could just pass cons.

mquander