Re: Variadic arguments and macros

2010-07-08 Thread Michael Wood
On 8 July 2010 07:47, Laurent PETIT wrote: > > > 2010/7/8 Pedro Teixeira >> >> What's the idiomatic way to handle cases where one has a macro rather >> than a function? >> >> For example: >> >> intent is as follows but does not work: >> (def args [false true false]) >> (apply or args) >> >> >> al

Re: Variadic arguments and macros

2010-07-07 Thread Laurent PETIT
2010/7/8 Pedro Teixeira > > What's the idiomatic way to handle cases where one has a macro rather > than a function? > > For example: > > intent is as follows but does not work: > (def args [false true false]) > (apply or args) > > > alternatives? > > a> (eval `(or @~args)) > big no-no. > > b>

Re: Variadic arguments and macros

2010-07-07 Thread Pedro Teixeira
What's the idiomatic way to handle cases where one has a macro rather than a function? For example: intent is as follows but does not work: (def args [false true false]) (apply or args) alternatives? a> (eval `(or @~args)) b> (reduce #(or %1 %2) args) any recommended? thanks, Pedro On J

Re: Variadic arguments and macros

2010-07-07 Thread Laurent PETIT
2010/7/7 Cameron : > Thanks everyone! I certainly have my solution; but, I'm still a bit > confused. Here's another example... > > user=> (defmacro foo [coll] `(map identity ~coll)) > #'user/foo > user=> (foo (list 1 2 3)) > (1 2 3) > > In this example, I pass an explicit list and all I have to do

Re: Variadic arguments and macros

2010-07-07 Thread Cameron
Thanks everyone! I certainly have my solution; but, I'm still a bit confused. Here's another example... user=> (defmacro foo [coll] `(map identity ~coll)) #'user/foo user=> (foo (list 1 2 3)) (1 2 3) In this example, I pass an explicit list and all I have to do is unquote 'coll'. How is passing a

Re: Variadic arguments and macros

2010-07-07 Thread Cameron
Thanks for all the replies everyone, I certainly have a solution now. But I am still a little confused. Take this slight variation... user=> (defmacro foo [coll] `(map identity ~coll)) #'user/foo user=> (foo [1 2 3 `(+ 1 1)]) (1 2 3 (clojure.core/+ 1 1)) In this one, I am passing an explicit list

Re: Variadic arguments and macros

2010-07-07 Thread Jason Wolfe
Hi Cameron, On Jul 7, 9:49 am, Cameron wrote: > Hello all! Today, I've either discovered a bug, or I've discovered a > flaw in my understanding of macros. Most likely the latter :-) Could > anyone set me straight? > > While this is not the macro I was trying to write, it falls over in > the same

Re: Variadic arguments and macros

2010-07-07 Thread Nicolas Oury
Of course I meant (map identity (1 2)) On Wed, Jul 7, 2010 at 6:03 PM, Nicolas Oury wrote: > If you macroexpand the first foo in (foo 1 2), you will see something like > (1 2) > > when this gets evaluated, Clojure is not happy about 1 not being a > function. > > > On Wed, Jul 7, 2010 at 5:49 PM,

Re: Variadic arguments and macros

2010-07-07 Thread miner
I think you're missing a quote in your original macro. You wrote: (defmacro foo [& xs] `(map identity ~xs)) Try this in a REPL: user=> (macroexpand-1 '(foo 1 2)) (clojure.core/map clojure.core/identity (1 2)) That shows you that it's going to try to evaluate the form (1 2). The original complai

Re: Variadic arguments and macros

2010-07-07 Thread Nicolas Oury
If you macroexpand the first foo in (foo 1 2), you will see something like (1 2) when this gets evaluated, Clojure is not happy about 1 not being a function. On Wed, Jul 7, 2010 at 5:49 PM, Cameron wrote: > Hello all! Today, I've either discovered a bug, or I've discovered a > flaw in my unders

Re: Variadic arguments and macros

2010-07-07 Thread David Nolen
On Wed, Jul 7, 2010 at 12:49 PM, Cameron wrote: > Hello all! Today, I've either discovered a bug, or I've discovered a > flaw in my understanding of macros. Most likely the latter :-) Could > anyone set me straight? > > While this is not the macro I was trying to write, it falls over in > the sam

Variadic arguments and macros

2010-07-07 Thread Cameron
Hello all! Today, I've either discovered a bug, or I've discovered a flaw in my understanding of macros. Most likely the latter :-) Could anyone set me straight? While this is not the macro I was trying to write, it falls over in the same place. (user=> (defmacro foo [& xs] `(map identity ~xs)) #