all function arguments will be evaluated .... so, 123 was printed On Thu, May 3, 2012 at 4:06 AM, thomas <[email protected]> wrote:
> the arguments to randomly-fn are evaluated before the macro-expansion of > randomly kicks in. > (that's what macros are for: control if, where and how often an expression > is evaluated) > So why would you need randomly-fn anyway? > You can just write > > randomly (print 1) (print 2) (print 3)) > > and this works. > > > Am 02.05.2012 um 16:09 schrieb 金山: > > > I defined a macro like this: > > (defmacro randomly [& exprs] > > (let [len (count exprs) > > ind (rand-int len) > > conditions (map #(list '= ind %) (range len))] > > `(cond ~@(interleave conditions exprs)))) > > > > and then defined a function : > > (defn randomly-fn [& exprs] > > (randomly exprs)) > > > > I think there may be a mistake because of the randomly-fn didn't work > > as expected. > > > > (randomly-fn (print 1) (print 2) (print 3)) > > > > expected: > > 1 or 2 or 3. > > but returned: > > 123 > > > > where is the mistake? > > > > -- > > 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 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 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
