Dear all,

I've got a re-implementation of the for-macro sitting around here that
removes this limitation (and others, the vector can't be empty either,
if I remember correctly). The implementation also adds the sorting and
grouping functionality described in Wadler and Jones' paper
"comprehensive comprehensions" (http://research.microsoft.com/~simonpj/
papers/list-comp/list-comp.pdf).

I'd be happy to post the code if anyone's interested, however:
- it's based on an old version of Clojure (Dec '08, pre "lazier
seqs"), so it might need some work.
- I implemented a complete parser (Hutton's monadic parser
combinators, http://www.cs.nott.ac.uk/~gmh/bib.html#monparsing) to
parse the binding vector and I'm not sure if that would make sense in
clojure.core (Although I think so, since `for` isn't the only macro in
core with a custom "mini-parser").

Regards,
  --Chris

On 23 Okt., 21:18, Chouser <[email protected]> wrote:
> On Fri, Oct 23, 2009 at 3:16 PM, Howard Lewis Ship <[email protected]> wrote:
>
>
>
> > I like to try and keep my level of nesting under control, and this
> > often involves hiding or re-structuring the let macro. The for macro
> > can implicitly assemble a let macro for you, but with a limitation
> > that the :let clause can't be first:
>
> > 1:5 user=> (for [:let [z [:foo :bar]] x z] (name x))
> > java.lang.IllegalStateException: Can't pop empty vector (repl-1:5)
> > 1:6 user=> (for [x [:foo :bar] :let [z (name x)]] z)
> > ("foo" "bar")
> > 1:7 user=>
>
> > Is this limitation intentional?  Could the error message be improved?
>
> It's not an intentional limitation.  One hint of this is that
> :let, :while, and :when all work perfectly fine at the beginning
> of a doseq.
>
> Improving the error message would be easy.  On the other hand,
> a patch to support them at the beginning of a 'for' should be
> possible.  I think it might be worthwhile, particulary for macros
> that generate 'for' forms.  The machinery inside a 'for'
> expansion is hard to do yourself.
>
> Rich, would you consider a patch to support this?
>
> --Chouser
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to