Nothing is wrong with do block.    I just thought maybe there is some 
trick....

Fair enough.


On Tuesday, 21 August 2012 15:55:04 UTC+1, lpetit wrote:
>
> Hello, 
>
> What's wrong with having 2 fns inside the top level do ?
>
> In Clojure, top level dos are split so that their children forms are 
> evaluated in sequence, as if you would have written them without the do.
>
> HTH,
>
> -- 
> Laurent
>
> 2012/8/21 Maris <maris.o...@gmail.com <javascript:>>
>
>> I want a macro that generates two defn's.
>>
>> (defn vote-suspend [this] (deref (.state this)))
>> (defn vote-resume [this state] (reset! (.state this) state))
>>
>> I have written this:
>>
>> (defmacro suspendable [prefix]
>>   `(do (defn ~(symbol (str prefix "suspend")) [~'this] (deref (.state 
>> ~'this)))
>>        (defn ~(symbol (str prefix "resume")) [~'this ~'state] (reset! 
>> (.state ~'this) ~'state))))
>>
>> It works but it has both defn's in *do *block*.*
>>
>> (*do* (clojure.core/defn vote-suspend [this] (clojure.core/deref (.state 
>> this))) (clojure.core/defn vote-resume [this state] (clojure.core/reset! 
>> (.state this) state)))
>>
>>
>> is it possible to generate defn's without *do* ?
>>
>>
>> I tried this:
>>
>> (defmacro suspendable [prefix]
>>   (list `(defn ~(symbol (str prefix "suspend")) [~'this] (deref (.state 
>> ~'this)))
>>         `(defn ~(symbol (str prefix "resume")) [~'this ~'state] (reset! 
>> (.state ~'this) ~'state))))
>>
>> But it creates parentheses around defn:
>>
>> user>  (macroexpand-1  '(suspendable vote-))
>> ((clojure.core/defn vote-suspend [this] (clojure.core/deref (.state 
>> this))) (clojure.core/defn vote-resume [this state] (clojure.core/reset! 
>> (.state this) state)))
>>
>>
>> Maybe splice it?
>>
>> (defmacro suspendable [prefix]
>>   ~@(list `(defn ~(symbol (str prefix "suspend")) [~'this] (deref (.state 
>> ~'this)))
>>           `(defn ~(symbol (str prefix "resume")) [~'this ~'state] (reset! 
>> (.state ~'this) ~'state))))
>>
>> *Attempting to call unbound fn: #'clojure.core/unquote-splicing*      
>>
>> *unquote-splicing* must be inside syntax-quote block, right ?    
>>
>> This creates parentheses again:
>>
>> (defmacro suspendable [prefix]
>>   `( ~@(list `(defn ~(symbol (str prefix "suspend")) [~'this] (deref 
>> (.state ~'this)))
>>             `(defn ~(symbol (str prefix "resume")) [~'this ~'state] 
>> (reset! (.state ~'this) ~'state)))))
>>
>> Is it not possible to return two sexp's from a macro ?
>>
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@googlegroups.com<javascript:>
>> Note that posts from new members are moderated - please be patient with 
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+u...@googlegroups.com <javascript:>
>> 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 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