Many thanks for all the replies.
Paul
On Thu, Mar 15, 2012 at 10:49 PM, Stuart Campbell wrote:
> Almost, but you do need to resolve the symbols to functions when you
> evaluate the operation:
>
> (defn arith [x y]
> (map (fn [op] [((resolve op) x y) (list op x y)]) '[+ - / *]))
>
> Regards,
> S
Almost, but you do need to resolve the symbols to functions when you
evaluate the operation:
(defn arith [x y]
(map (fn [op] [((resolve op) x y) (list op x y)]) '[+ - / *]))
Regards,
Stuart
On 16 March 2012 02:52, Jack Moffitt wrote:
> > If I apply the following function to 4 and 6
> >
> > (
Tassilo Horn writes:
>> As an aside, when playing around with quoting and unquoting, I
>> noticed that the result of ('+ 3 5) is 5. I'm not sure what I would
>> have expected (maybe an error?) but it wasn't the third item of the
>> list. Is there any reason for this?
>
> Symbol implements AFn an
Paul Carey writes:
> Hi
>
> If I apply the following function to 4 and 6
>
> (defn arith [x y]
> (map (fn [op] [(op x y) `(~op ~x ~y)]) [+ - / *]))
>
> I'd like to get a result of the form
>
> ([10 (+ 4 6)] [-2 (- 4 6)] ...)
>
> but instead I get something like
> ([10 (# 4 6)] ...
>
> How do I
> As an aside, when playing around with quoting and unquoting, I noticed
> that the result of ('+ 3 5) is 5. I'm not sure what I would have
> expected (maybe an error?) but it wasn't the third item of the list.
> Is there any reason for this?
>From http://clojure.org/data_structures:
Symbols, ju
> If I apply the following function to 4 and 6
>
> (defn arith [x y]
> (map (fn [op] [(op x y) `(~op ~x ~y)]) [+ - / *]))
>
> I'd like to get a result of the form
>
> ([10 (+ 4 6)] [-2 (- 4 6)] ...)
>
> but instead I get something like
> ([10 (# 4 6)] ...
You want to quote the [+ - / *] so it doe
Hi
If I apply the following function to 4 and 6
(defn arith [x y]
(map (fn [op] [(op x y) `(~op ~x ~y)]) [+ - / *]))
I'd like to get a result of the form
([10 (+ 4 6)] [-2 (- 4 6)] ...)
but instead I get something like
([10 (# 4 6)] ...
How do I output the var as written (I'd also be happy
Hi
If I apply the following function to 4 and 6
(defn arith [x y]
(map (fn [op] [(op x y) `(~op ~x ~y)]) [+ - / *]))
I'd like to get a result of the form
([10 (+ 4 6)] [-2 (- 4 6)] ...)
but instead I get something like
([10 (# 4 6)] ...
How do I output the var as written (I'd also be happy w