[racket] Nested scope in D vs Racket
On Aug 23, John Clements wrote:
> "Hopefully we can agree that the value of this program is 8 (the
> left x in the addition evaluates to 5, the right x is given the
> value 3 by the inner with, so the sum is 8). The refined
> substitution algorithm, however, converts this expression into
>
> {with {x 5} {+ 5 {with {x 3} 5}}}
>
> [...]"
>
> Many students say to me, "but... you're not allowed to define the
> same name twice!"
Purely anecdotal, but I know that part very well -- and I've never got
such a comment.
IMO all of this is a by-product of something that wasn't mentioned in
this thread yet: that in "imperative" languages the preferred style is
to define few variables and bang new values into them, whereas in
functional languages you would do your best to avoid it. Since a
typical D hacker comes from the former crowd, they'll look at a
(let ([x 3])
...
(let ([x (foo x)])
...)
...)
and groan at the redundant overloading of the same name[*], maybe at the
same level that a Racket programmer would groan at mutating x.
This is also related to the fact that in those curly languages code is
very flat, unlike functional code[**]. See "a cancerous function that's
grown out of control" in the explanation for this D feature (in the
second URL mentioned at the beginning).
[*] And obviously preferring the single variable + banging new values
leads to talking about things like x_i for the value of x at step i in
the code -- but who cares about that...
[**] Easy way to catch students with this mentality: they'll use a tab
or 8 spaces for an indentation level...
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://barzilay.org/ Maze is Life!