I like most of that and don't object to the rest, except for leaving out a version of #:break-unless. Especially because "break" is already a negative word. Just like #:unless (bad?) is more natural than #:when (not (bad?)), #:<something> (ok-to-continue?) is more natural than #:break (not (ok-to-continue?)). I'd suggest "#:continue", but in C-like languages I believe that means something different.<br>
<br>Actually, we could make the whole thing more positive (or, ironically, less negative) by going with #:do-while and #:do-until, something like that. It brings back the nicely mnemonic "while" and "until", is hard to confuse with "when" and "unless", and "do" isn't that much extra to read. And it's positive, so it doesn't reverse the meaning of the second word.<br>
<br clear="all">Carl Eastlund<br>
<br><div class="gmail_quote">On Fri, Sep 14, 2012 at 4:25 PM, Matthew Flatt <span dir="ltr"><<a href="mailto:mflatt@cs.utah.edu" target="_blank">mflatt@cs.utah.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">At Fri, 14 Sep 2012 15:30:22 -0400, Eli Barzilay wrote:<br>
> Four hours ago, Matthew Flatt wrote:<br>
> ><br>
> > Also, I think the names `#:while' and `#:until' are too close to<br>
> > `#:when' and `#:unless'. I suggest `#:break-when' and `#:break-unless'.<br>
> > Compare:<br>
> ><br>
> > > (for*/list ([j 2] [i 10] #:when (i . < . 5)) i)<br>
> > '(0 1 2 3 4 0 1 2 3 4)<br>
> > > (for*/list ([j 2] [i 10] #:break-unless (i . < . 5)) i)<br>
> > '(0 1 2 3 4)<br>
> ><br>
> > I imagine that `#:break-when' and `#:break-unless' are allowed among<br>
> > the clauses much like `#:when' and `#:unless', but also allowed at the<br>
> > end of the body. Is that what you had in mind?<br>
><br>
> Sorry for the bike-shedding, but to me that `#:break-unless' is even<br>
> harder to read than `#:until'. Possible explanation: "break unless"<br>
> makes me parse two words and figure out how they combine, and "while"<br>
> is something that I know without doing so.<br>
<br>
</div>After trying out various options, I agree that `break-when' is too many<br>
words. I'm currently trying just `break' and dropping `break-unless',<br>
and that feels better.<br>
<div class="im"><br>
At Fri, 14 Sep 2012 11:49:20 -0400, Carl Eastlund wrote:<br>
> I agree that #:while and #:until are easily confused with #:when and<br>
> #:unless. I slightly prefer #:stop- to #:break- as a prefix here, it seems<br>
> a more natural word.<br>
<br>
</div>I like "break" because it goes with "for", it avoids potential<br>
confusion with "stop" in `stop-after' and `stop-before', and it is more<br>
clearly different from "final" (which is used below).<br>
<br>
> I like the idea of allowing these clauses at the end<br>
<div class="im">> of the body to give a notion of stopping after the current iteration.<br>
<br>
</div>It turns out that allowing `#:break' at the very end of the body causes<br>
problems with scope and composition.<br>
<br>
Imagine trying to implement `for/set' by wrapping its body in an<br>
expansion to `for/fold'. Maybe you can look from the end of the body<br>
and skip back over `#:break' clauses, but now imagine that the last<br>
form before `break' expands to a combination of a definition and an<br>
expression, and the `#:break' clause wants to refer to the identifier<br>
that is bound in the expansion. We could probably make all that work<br>
with `local-expand' and internal-definition contexts, but that gets<br>
complicated.<br>
<br>
Requiring an expression at the end of a `for' body --- while allowing<br>
`#:break' clauses otherwise interspersed in the body --- avoids<br>
composition and scope problems. Macros still have to do a little work<br>
to juggle `#:break' clauses, but a `split-for-body' helper function is<br>
straightforward to use.<br>
<br>
Meanwhile, to support breaking after the current element, I'm trying<br>
out `#:final'. A `#:final' clause is like `#:break', except that it<br>
ends the loop after the next run of the body. (The two kinds of clauses<br>
closely related to `stop-before' and `stop-after'.)<br>
<br>
> (for/list ([i 10]) #:break (= i 2) i)<br>
'(0 1)<br>
> (for/list ([i 10]) #:final (= i 2) i)<br>
'(0 1 2)<br>
<br>
> (for ([book '("Guide" "Story" "Reference")]<br>
#:break (equal? book "Story")<br>
[chapter '("Intro" "Details" "Conclusion")])<br>
(printf "~a ~a\n" book chapter))<br>
Guide Intro<br>
Guide Details<br>
Guide Conclusion<br>
<br>
> (for* ([book '("Guide" "Story" "Reference")]<br>
[chapter '("Intro" "Details" "Conclusion")])<br>
#:break (and (equal? book "Story")<br>
(equal? chapter "Conclusion"))<br>
(printf "~a ~a\n" book chapter))<br>
Guide Intro<br>
Guide Details<br>
Guide Conclusion<br>
Story Intro<br>
Story Details<br>
<br>
> (for* ([book '("Guide" "Story" "Reference")]<br>
[chapter '("Intro" "Details" "Conclusion")])<br>
#:final (and (equal? book "Story")<br>
(equal? chapter "Conclusion"))<br>
(printf "~a ~a\n" book chapter))<br>
Guide Intro<br>
Guide Details<br>
Guide Conclusion<br>
Story Intro<br>
Story Details<br>
Story Conclusion<br>
<br>
> (for ([book '("Guide" "Story" "Reference")]<br>
#:final (equal? book "Story")<br>
[chapter '("Intro" "Details" "Conclusion")])<br>
(printf "~a ~a\n" book chapter))<br>
Guide Intro<br>
Guide Details<br>
Guide Conclusion<br>
Story Intro<br>
<br>
<br>
</blockquote></div><br>