[racket-dev] Nest resurrection

From: Carl Eastlund (cce at ccs.neu.edu)
Date: Tue Sep 7 11:22:16 EDT 2010

On Tue, Sep 7, 2010 at 8:57 AM, Eli Barzilay <eli at barzilay.org> wrote:
> At some point after the Racket rename, `racket/nest' was dropped, and
> every once in a while I run into a case where I really miss it.  So
> here's a shot at what went wrong and an alternative vesion.
>
> My guess is that the main thing that made it difficult to use is the
> fact that it used the usual let-style grouping, which can be difficult
> to follow when the forms in it are themselves using the same kind of
> grouping.  The result is a kind of code that encourages parenophobia:
>
>  (nest ([let ([x 5])]
>         [let ([x (+ x x)])]
>         [for ([x (in-range x)])]
>         [when (even? x)])
>   (printf "x = ~s\n" x))
>
> At some point not too long ago, there was discussion of various tricks
> people use to reduce such rightward drift.  I remember one reader that
> was starting a new parenthesized expression on every `/', so
>
>  (a b / c d / e f)  --reads-as-->  (a b (c d (e f)))
>
> IIRC, Haskell also has a `$' thing with the purpose of doing just
> this.
>
> So how about using a non-alphabetic name (reduces clutter that breaks
> reading) and using it also for the separators instead of the
> paren-of-parens thing that makes that mess?  Using `$', it would look
> like this:
>
>  ($ let ([x 5])
>   $ let ([x (+ x x)])
>   $ for ([x (in-range x)])
>   $ when (even? x)
>   (printf "x = ~s\n" x))
>
> for the above expression.
>
> Opinions?
>
> --
>          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
>                    http://barzilay.org/                   Maze is Life!

FWIW, I think "nest" seems less like a macro to me and more like a
reader syntax.  It's like our period-based infix notation; it just
shuffles around s-expressions syntactically, it doesn't mess with
bindings or anything else to do with semantics of an expression.

--Carl


Posted on the dev mailing list.