What speaks against two defns in a do. It works as if you write two defns in normal code. Actually I find this very useful to do because you don't have additionally complexity for returning multiple sexps Am 21.08.2012 16:42 schrieb "Maris" <maris.orbid...@gmail.com>:
> 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 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 -- 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