Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Someone's very happy to have authored Clojure's for special form.


Clojure's `for` is ~80 lines of code, and isn't particularly accessible. My goal here wasn't to reinvent the wheel, but to give an example of a not-totally-trivial macro that does something neat. :)

(Clojure is simply my lisp of choice. This could be just as easily implemented in elisp, which does not have this built in.)

[edit] For those interested, here's an elisp version: https://gist.github.com/4430934


I can appreciate the fun of doing things like implementing a list comprehension and the excitement of both applying macros in a useful way and being able to tell other people about it. I found the tone of the linked article to sound self impressed to a point I personally found distasteful, and after reviewing it again I don't see any mention of Clojure's built in for special form, and thusly reacted in a snarky manner.

But everyone should get an opportunity to see what you can do with things like macros, how useful list comprehensions are in general, and how a homoiconic language can make the simple things slightly less intuitive but the hard things vastly more tractable. I certainly have no business in detracting from your enjoyment of Clojure, so please don't allow me to.

Instead of being snarky may I offer some constructive criticism:

1) You don't mention the Clojure `for` special form, which is a built in list comprehension. 2) There's a significant amount baked into Clojure's `for` special form. How does it compare to your macro? After reviewing the macro again I think you'll find there's some differing behaviors over when members of seqs are realized and bound between your implementation and that in clojure.core. 3) I think reflecting on what the real power here is: that you are able to dictate the hows and whys of evaluation at what time, and discussing that matter, can make more salient the power of LISPs.

Please do continue to enjoy what you are building and what you learn, and don't let the jaded musings of crotchety old men like me get in your way!


I enjoyed the article but was also a little bummed `for` wasn't mentioned at all.

Minor nit: `for` is a macro in the clojure.core namespace, not a special form. Special forms in Clojure are these: http://clojure.org/special_forms


I really appreciate the thoughtful response and constructive criticism! I think that much of it is valid.

All of this actually fell out of a desire to better understand Clojure's `for`, which is a piece of code I would have run away from not too long ago. (Earlier versions of this post made significant mention of `for` and its implementation; that it was totally stricken from the final version was, I think, an unfortunate product of editing.)

I'll certainly think more on your second and third points.


It's a nice post/example. Obviously useful, not that trivial, or at least something you might not have thought of doing if you're just beginning to grok macros, but simple enough so that you can do a pretty detailed explanation of it without going on forever.

Mentioning that there is a `for` form might be nice, just so it's clear that you don't have to do (something like) this in order to do list comprehension in Clojure. Kind of disagree with aredington's 2nd and 3rd points though. Those might be fine things to write some stuff about, but I don't know that that post really needs them.

Like, I don't think every post on macro stuff must deal with "macros and evaluation". It's an interesting topic and all, but as it is I like that the post is more like, here's a macro and look how we can use it to turn code like this into code like that. Without getting into every topic that that touches on.


How does he at all sound self-impressed? I just read the article twice and still don't understand this comment.


Your blog post should probably at least mention clojure.core/for, so that new Clojurists can use that in real projects, after they are done learning.


Yes, exactly. I am confused. Why use Clojure for the example, when Clojure already has this built in? I don't know all of the Lisp's, but if one of them does not have this, it would make sense to offer the example in that language.

Having said that, there is probably some educational value in writing out what a special form would look like if it was not a special form, so in that regard, yes, this is interesting to look at.


Because he is just showing an example of macros, not giving a tutorial on how to add list comprehensions to Clojure.


`for` is a macro, not a special form. Special forms are these: http://clojure.org/special_forms


Without monads?)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: