Suggestions for macro

2009-10-09 Thread nilamo
Hey all. I'm pretty new to Clojure, and wanted to try my hand at writing a macro. 'dowhile' is nothing special, but I'd still like to hear any comments/ suggestions you may have. (defmacro dowhile [body test] `(do ~body (while ~test ~body))) A test shows... (macroexpand-1 '(dowhile (dosync

Re: Suggestions for macro

2009-10-09 Thread Howard Lewis Ship
I'd tend to code this so that the test was the first form, and then any number of additional remaining forms become the body, in an implicit do. Obviously, if you're writing something like this, its for side effects. In addition, I'd wrap the body in an annonymous function, defined in a let, so

Re: Suggestions for macro

2009-10-09 Thread nilamo
That does look better. I had trouble with the anonymous func, however. After working it out, here's what I think the problem is, as well as what I did about it. ~...@body expands the body (which is a list) so that the elements of the list are represented without the surrounding parens.