[racket-dev] Nest resurrection

From: Eli Barzilay (eli at barzilay.org)
Date: Tue Sep 7 08:57:58 EDT 2010

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

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.


          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

Posted on the dev mailing list.