[racket-dev] for loops with interleaved escape continuations

From: Sam Tobin-Hochstadt (samth at cs.indiana.edu)
Date: Tue Jul 1 18:46:19 EDT 2014

I disagree strongly that this is un-rackety. Consider the following loop:

(define v ....)
(let loop ([i 100])
 (define e (vector-ref v i))
 (cond [(zero? i) null]
           [(= 999 e) null]
           [(even? e) (loop (add1 i))]
           [else (cons e (loop add1 i))]))

I don't think that's un-Rackety.

Here's that loop with break/continue:

(for/list ([i (in-range 100 0 -1)])
  (define e (vector-ref v i))
  (cond [(= 999 e) (break)]
           [(even? e) (continue)]
           [else e]))

I don't think that's un-Rackety either.

Sam

On Tue, Jul 1, 2014 at 10:59 PM, Neil Van Dyke <neil at neilvandyke.org> wrote:
> If adding break&continue features to your fancy iteration syntax, I propose
> that any uses of these features in source code be somehow very prominent.
>
> For example, perhaps there is a keyword that must be at the top of the fancy
> iteration form, something like
> "#:enable-continue-here-because-programmer-cannot-be-bothered-to-write-this-in-idiomatic-racket".
>
> This prominence warns readers of the code to be on the lookout for surprise
> control flow (like they would on the rare occasion that they saw a "call/ec"
> around a loop).  It also hints to newbie programmers that they are
> discouraged from simply transliterating syntax from other languages (rather
> than learning better control flow and structuring techniques).
>
> Neil V.
>
>
> _________________________
>   Racket Developers list:
>   http://lists.racket-lang.org/dev
>

Posted on the dev mailing list.