On Wed, Dec 10, 2008 at 8:05 PM, Ryan Neufeld <[EMAIL PROTECTED]> 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)

Works for me:

user=> (map + [1 2 3] [4 5 6])
(5 7 9)
user=> (defn parallel [f l1 l2] (map (fn [x y] (f x y)) l1 l2))
#'user/parallel
user=> (parallel + '(1 2 3) '(4 5 6))
(5 7 9)
user=> (defn parallel [f l1 l2] (map f l1 l2))
#'user/parallel
user=> (parallel + '(1 2 3) '(4 5 6))
(5 7 9)
user=>

The problem seems to be that you are quoting the +.  Not sure why this is, but:

user=> ('+ 1 4)
4
user=>

> I gleaned what I could from the Clojure wiki but I'm still missing
> something.
>
> Any pointers on where I am going wrong?

-- 
Michael Wood <[EMAIL PROTECTED]>

--~--~---------~--~----~------------~-------~--~----~
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