[racket-dev] Code micro-level organization

From: Laurent (laurent.orseau at gmail.com)
Date: Thu May 31 13:23:32 EDT 2012

(sorry for the bad indentation, writing s-exps on a phone predictive
keyboard is painful...)
Le 31 mai 2012 19:21, "Laurent" <laurent.orseau at gmail.com> a écrit :

> How about a define* that is exactly like let* without the additional
> indentation level?
> E.g.:
>
> (define*
> [↑ "foo bar baz"]
> [↑ (substring ↑ 3 8)]
> [str (string-trim ↑)]
> [↑ (regexp-match? #rx"^[a-z].*[a-z]$" str)])
> (and ↑ (string-append "*" str "*"))
>
> Laurent
>
> Le 31 mai 2012 19:04, "Neil Toronto" <neil.toronto at gmail.com> a écrit :
> >
> > On 05/30/2012 03:40 PM, Eli Barzilay wrote:
> >>
> >> Now, lets imagine that instead of a simple `<>' hole, there are two
> >> kinds of holes with an "up" or a "down" direction -- this leads to
> >> this kind of a syntax:
> >>
> >>   (○ "foo bar baz"
> >>      (substring ↑ 3 8)
> >>      (string-trim ↑)
> >>      (let ([str ↑]) ↓)
> >>      (and (regexp-match? #rx"^[a-z].*[a-z]$" str) ↓)
> >>      (string-append "*" str "*"))
> >>
> >> where you can read `↑' as "the above" and `↓' as "the below".
> >
> >
> > It seems like `↑' is another way to not name expressions (i.e. a
> "pointless style" :D), and `↓' is handled just fine by internal
> definitions. This is equivalent, currently defined, has less nesting, and
> avoids a rename:
> >
> >   (define orig-str "foo bar baz")
> >   (define sub (substring orig-str 3 8))
> >   (define str (string-trim sub))
> >   (define m (regexp-match? #rx"^[a-z].*[a-z]$" str))
> >   (and m (string-append "*" str "*"))
> >
> > A `define*' form like Jay (and I) want would make these kinds of things
> less error-prone and allow names to be reused:
> >
> >   (define* ↑ "foo bar baz")
> >   (define* ↑ (substring ↑ 3 8))
> >   (define* str (string-trim ↑))
> >   (define* ↑ (regexp-match? #rx"^[a-z].*[a-z]$" str))
> >   (and ↑ (string-append "*" str "*"))
> >
> > It's still pretty wordy, though. Even if I had `define*' I'd be tempted
> to go with my current favorite idiom, which trades wordiness for a nesting
> level:
> >
> > (let* ([↑    "foo bar baz"]
> >       [↑    (substring ↑ 3 8)]
> >       [str  (string-trim ↑)]
> >       [↑    (regexp-match? #rx"^[a-z].*[a-z]$" str)])
> >  (and ↑ (string-append "*" str "*")))
> >
> > I occasionally get annoyed by how deeply these can get nested. I feel
> your pain, man.
> >
> > Neil ⊥
> >
> > _________________________
> >  Racket Developers list:
> >  http://lists.racket-lang.org/dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/dev/archive/attachments/20120531/a5525688/attachment.html>

Posted on the dev mailing list.