Ryan Neufeld wrote:
> I've been working on learning Clojure after taking a course in Common
> Lisp and I am having some troubles translating a particular Common
> Lisp function to Clojure that uses mapping.
> 
> We're defining a function that takes a function and two lists and
> applies the function to each two items in the lists. Not particularly
> safe or anything, but decent for learning.
> 
> In CL:
> (defun parallel (F L1 L2)
>   (mapcar #'(lambda (x y) (funcall F x y)) L1 L2))
> 
> (parallel '+ '(1 2 3) '(4 5 6))  ;; => (5 7 9)  ;; Working correctly
> 
> My attempt in Clojure:
> (defn parallel [F L1 L2] (map (fn [x y] (F x y)) L1 L2))
> -- OR --
> (defn parallel [F L1 L2] (map F L1 L2))
> 
> however...
> (parallel '+ '(1 2 3) '(4 5 6))  => (4 5 6)
> 
> I gleaned what I could from the Clojure wiki but I'm still missing
> something.
> 
> Any pointers on where I am going wrong?

You've almost got it -- just don't quote the +:

  user> (parallel + '(1 2 3) '(4 5 6))
  (5 7 9)

By quoting the + you were passing in the symbol, not the function.

Dean


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to