And of course ,it still run in constant stack space just like normal recur form.
P.S. I think adrian's advice is good, please forgive my poor english,and i changes the description to ' a macro to define clojure functions with pattern match just like erlang or elixir. 2014-09-15 0:26 GMT+08:00 dennis zhuang <[email protected]>: > Hi Herwig > > Actually,defun just define a variadic arguments function,so it doesn't > have different arities. And when using defun macro ,it walk through the > body forms, find 'recur' forms and replace them with (recur (vector > ...arguments)) instead. > > A macroexpand-1 result of accum: > > > (macroexpand-1 > > '(defun accum > > ([0 ret] ret) > > ([n ret] (recur (dec n) (+ n ret))) > > ([n] (recur n 0)))) > > => > > > (clojure.core/defn > > accum > > {:arglists '([0 ret] [n ret] [n])} > > [& args__4602__auto__] > > (clojure.core.match/match > > [(clojure.core/vec args__4602__auto__)] > > [[0 ret]] > > (do ret) > > [[n ret]] > > (do (recur (vector (dec n) (+ n ret)))) > > [[n]] > > (do (recur (vector n 0))))) > > > The core procedure is at > https://github.com/killme2008/defun/blob/master/src/defun.clj#L97-107 > > > > 2014-09-15 0:15 GMT+08:00 Herwig Hochleitner <[email protected]>: > >> Hi Dennis, >> >> marrying core.match to defn is a pretty neat idea. Thanks for releasing >> it! >> >> I see that you actually extended defn in that you made it possible to >> recur between different arities. >> Can you give a quick rundown on how you made that work? Are the arities >> still separate IFn arities? Does it still run in constant stack space? >> >> kind regards >> >> PS @adrian: If you feel like "Friendly advice" ing someone, why not do so >> in a private email? >> >> -- >> 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. >> > > > > -- > 庄晓丹 > Email: [email protected] [email protected] > Site: http://fnil.net > Twitter: @killme2008 > > > -- 庄晓丹 Email: [email protected] [email protected] Site: http://fnil.net Twitter: @killme2008 -- 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.
