[racket-dev] Short-circuiting comprehensions

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Fri Sep 14 11:40:19 EDT 2012

I think this is a good idea. The technique to implement it is embedded
in `for/vector' (to handle a vector length), and I can generalize that
and move it into `for...'.

Also, I think the names `#:while' and `#:until' are too close to
`#:when' and `#:unless'. I suggest `#:break-when' and `#:break-unless'.
Compare:

 > (for*/list ([j 2] [i 10] #:when (i . < . 5)) i)
 '(0 1 2 3 4 0 1 2 3 4)
 > (for*/list ([j 2] [i 10] #:break-unless (i . < . 5)) i)
 '(0 1 2 3 4)

I imagine that `#:break-when' and `#:break-unless' are allowed among
the clauses much like `#:when' and `#:unless', but also allowed at the
end of the body. Is that what you had in mind?


At Fri, 14 Sep 2012 10:09:52 -0400, Carl Eastlund wrote:
> I would like the for/... comprehension macros to have #:while and #:until
> clauses similar to the #:when and #:unless clauses.  I often find I want to
> short-circuit the sequence at some point, but there is no elegant way to do
> it.  I could probably write sequence-while and sequence-until, but I don't
> want to move this condition into the sequence any more than I want to write
> sequence-filter instead of #:when or #:unless.
> 
> Has this been brought up before?  I can't recall.  Does anyone else run
> into the same issue?
> 
> Carl Eastlund
> _________________________
>   Racket Developers list:
>   http://lists.racket-lang.org/dev

Posted on the dev mailing list.