On Tue, Mar 24, 2009 at 9:55 AM, Konrad Hinsen
<[email protected]> wrote:
>
> On Mar 24, 2009, at 15:44, Mark Volkmann wrote:
>
>> I'm wondering if there is a way to avoid that using a macro. The hard
>> part is printing the expression. The following doesn't work. It
>> outputs "3 = 3".
>>
>> (defmacro dump2 [expr]
>> `(let [value# ~expr]
>> (pr ~expr)
>> (println " =" value#)))
>> (dump2 (+ 1 2))
>
> All it takes to make it work is a slight modification:
>
> (defmacro dump [expr]
> `(let [value# ~expr]
> (pr (quote ~expr))
> (println " =" value#)))
>
> (dump (+ 1 2))
>
> prints:
>
> (+ 1 2) = 3
Thanks! It looks like I don't need the let now. Does a macro have to
evaluate to one form? For example, this works, but it seems I can't
drop the do.
(defmacro dump [expr]
`(do
(print (quote ~expr))
(println " =" ~expr)))
--
R. Mark Volkmann
Object Computing, Inc.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---