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
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>
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
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
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
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
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
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,
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
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
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
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))
#
12 matches
Mail list logo