Sorry, that should be

(defmacro listen
  [[topic-sym topic-name] & body]
  `(on-message ~topic-name
     (fn [~topic-sym] (~@body)))))

On Thu Jan 01 2015 at 11:01:53 PM Michael Blume <[email protected]>
wrote:

> If it were me I'd avoid making 'topic a "magic symbol" and let the user
> choose a symbol to bind. It'd look something like
>
> (defmacro listen
>   [[topic-sym topic-name] & body]
>   `(on-message ~topicname
>      (fn [~topic-name] (~@body)))))
>
> (listen [topic "topic-test"] (println topic "test))
>
> this way it's relatively clear to the reader what the symbol is bound to
> and where.
>
>
> On Wed Dec 31 2014 at 1:41:41 PM Tobias Kortkamp <
> [email protected]> wrote:
>
>>
>> On 12/31/2014 18:56, rogergl wrote:
>> > To make this work I had to replace the symbol 'topic in the body with
>> > the gensym symbol. Is this the right way to do this ?
>>
>> Your macro is too complicated. You don't need to gensym a symbol in this
>> case. Instead just quote a symbol before unquoting it (note the ~'), so
>> that it appears as is in the resulting form:
>>
>>   (defmacro listen
>>     [topic expression]
>>     `(on-message ~topic (fn [~'topic] ~expression)))
>>
>> Your example then expands to
>>
>>   (on-message "topic-test" (fn [topic] (println topic "test")))
>>
>>
>>
>>
>>
>>
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to [email protected]
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> 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
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to