Re: Resolving vars and quoting

2012-03-18 Thread Paul Carey
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

Re: Resolving vars and quoting

2012-03-15 Thread Stuart Campbell
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 > > > > (

Re: Resolving vars and quoting

2012-03-15 Thread Tassilo Horn
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

Re: Resolving vars and quoting

2012-03-15 Thread Tassilo Horn
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

Re: Resolving vars and quoting

2012-03-15 Thread Stuart Halloway
> 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

Re: Resolving vars and quoting

2012-03-15 Thread Jack Moffitt
> 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

Resolving vars and quoting

2012-03-15 Thread Paul Carey
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

Resolving vars and quoting

2012-03-15 Thread Paul Carey
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