Thinking about it again,

Is qualifying this as a non-bug, a known limitation the best that can
be said about it ?

Could the implementation be improved to handle this case, or is there
a theoretical reason I've not thought about that prevents doing this
for the general case ?

Thanks,

-- 
Laurent

2009/4/24 Christophe Grand <christo...@cgrand.net>:
>
> Hi Kevin!
>
> Your (let [dummy 0] ...) is a single expression and, as such, is entirely 
> compiled before being executed.
> But to properly compile (add 1 (mul magic x)) 'add need to have a value and 
> it will not have a value until the (compiled) expression is executed.
> So, for this expression, its compilation depends on its execution that 
> requires its compilation...
>
> Thus a macro can on only be used in subsequent op-level expression, not in 
> its own.
>
> I just learnt this lesson again: 
> http://clj-me.blogspot.com/2009/04/vicious-bug.html
>
> hth,
>
> Christophe
>
> ke...@ksvanhorn.com a écrit :
>> I have more information on this now, and it is definitely a bug in
>> Clojure -- defmacro within a let doesn't work correctly.  Consider the
>> following file:
>>
>> --- BEGIN foo1a.coj ---
>> (ns com.ksvanhorn.foo1a)
>>
>> (let [dummy 0]
>>   (defmacro add [& args] `(unchecked-add ~...@args))
>>   (defmacro mul [& args] `(unchecked-multiply ~...@args))
>>   (let [magic 1812433253
>>               x 5489
>>               v (add 1 (mul magic x))]
>>         (println (str "v: " v))))
>> --- END ---
>>
>> If I type "(use 'com.ksvanhorn.foo1a)" at the REPL, I get
>>
>>   v: (clojure.core/unchecked-add 1 (clojure.core/unchecked-multiply
>> 1812433253 5489))
>>
>> printed out and nil returned, but if I just type
>>
>>   (uncheck-add 1 (unchecked-multiply 1812433253 5489))
>>
>> I get 1301868182.
>>
>> Although in this case the defmacro doesn't need to be inside the let,
>> I actually have a real need for doing defmacro inside a let -- I have
>> a computed constant that I want to use in several places, and one of
>> those places is in the macro definition.
>>
>> >
>>
>>
>
>
> --
> Professional: http://cgrand.net/ (fr)
> On Clojure: http://clj-me.blogspot.com/ (en)
>
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to