[racket-dev] Short-circuiting comprehensions

From: John Clements (clements at brinckerhoff.org)
Date: Fri Sep 14 16:28:58 EDT 2012

On Sep 14, 2012, at 1:14 PM, Robby Findler wrote:

> My $0.02: I find #:while and #:when to be too close, and #:until and
> #:unless even closer.

More bike-shedding: I agree. In response to eli: I find the difficulty of reading "break-when" to be an adequate cost to pay to highlight the difference between "just skip this one" and "stop the loop completely".

Just to add my own tint to the can of paint, I would personally drop #:break-unless completely, and just make do with #:break-when, which I find quite a bit more readable. (To be fair, I'd also be very happy getting rid of "unless" altogether; I nearly always find (when (not …) …) more readable.


John

> 
> Robby
> 
> On Fri, Sep 14, 2012 at 2:30 PM, Eli Barzilay <eli at barzilay.org> wrote:
>> 5 hours ago, Carl Eastlund wrote:
>>> 
>>> Has this been brought up before?  I can't recall.  Does anyone else
>>> run into the same issue?
>> 
>> (I think that I brought this up when the comprehensions were first
>> discussed, pointing at the similar tool I have in Swindle which makes
>> implementing them very easy.)
>> 
>> 
>> Four hours ago, Matthew Flatt wrote:
>>> 
>>> 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?
>> 
>> Sorry for the bike-shedding, but to me that `#:break-unless' is even
>> harder to read than `#:until'.  Possible explanation: "break unless"
>> makes me parse two words and figure out how they combine, and "while"
>> is something that I know without doing so.
>> 
>> Another point to consider in favor of `#:while' and `#:until' is that
>> they're extremely common names, so they're unlikely to be *that*
>> problematic.
>> 
>> (I intentionally left the typo in the first sentence as a
>> demonstration of how it's confusing to read...)
>> 
>> 
>> A different point is that maybe there should also be a `while' and
>> `until' looping constructs in the language?  (Whatever they're
>> called.)  Every once in a while (ahem) I want that when I write:
>> 
>>  (let loop ()
>>     (when (more-work-to-do)
>>       (work!)))
>> 
>> And it looks like this:
>> 
>>  (for (#:while (more-work-to-do))
>>    (work!))
>> 
>> would not work in the same way that (for () (work!)) doesn't loop
>> forever(?).
>> 
>> --
>>          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
>>                    http://barzilay.org/                   Maze is Life!
>> 
>> _________________________
>>  Racket Developers list:
>>  http://lists.racket-lang.org/dev
> _________________________
>  Racket Developers list:
>  http://lists.racket-lang.org/dev

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4800 bytes
Desc: not available
URL: <http://lists.racket-lang.org/dev/archive/attachments/20120914/c12c6b34/attachment.p7s>

Posted on the dev mailing list.