> On Aug 16, 2018, at 8:22 AM, Robert Girault <rfrancoisgira...@gmail.com> 
> wrote:
> 
> I think I'd write your example like this.
> 
> (define (foo x)
>  (local ((define y (f x))
>          (define z (g y))
>          (define p (h z)))
>    (bar p)))
> 
> (If I knew what f, g, h do, I might write it differently.  If they're
> all only for computing p, local expresses the fact.)
> 
> I was educated by HtDP 1st edition:
>  
> https://htdp.org/2018-01-06/Book/part_three.html#%28part._sec~3alocal-definitions%29


Thanks for the up-vote but let me explain the “local” rationale here and vote 
for the ‘inner define’ variant. 

I added ‘local’ to the TEACHING languages for semantic consistency. This 
decision was based on my inner semanticist rather than mass psychology of 
students but with psychology in mind. 

1. A series of global (in the sense of 'module level') defines have a certain 
semantics (both static and dynamic). If you experiment using global defines and 
then move them into the innards of a function, you want the _exact_ _same_ 
semantics. So 

  (define a (A 0))
  (define b (B 1))
  (define c (C 2))

would become 

  (define (f x)
    (define a (A 0))
    (define b (B 1))
    (define c (C 2))
    . . . )

This works well and fine for many but _not all_ sequences. For some you got a 
different error message .. and I consider rare but feasible failure in a 
teaching setting _insidious_. So I decided to come up with a construct that 
preserves the exact same semantics. 

2. There is a secondary but minor reason. Internal defines introduce a new 
syntactic category into the language while ‘local’ defines simply extend the 
syntactic category of expressions. I like keeping the number of syntactic 
categories small. And I was afraid that once I opened the door, we’d get many 
things. 

3. Since I made this decision, we also changed Racket’s behavior so that it 
signals undefined defines (during evaluation) uniformly. For all I know the 
semantic rationale (pt. 1) no longer applies, only the syntactic one (pt. 2). 

4. While the teaching languages share syntax with Racket (as in #lang racket), 
they are not Racket. 

;; - - - 

In Racket programs for the world, possibly real, you want to avoid rightward 
drift. Indenting deeper and deeper makes code appear ‘ugly’ to many eyes, 
especially those used to other languages. But I will say this is also the one 
point about ‘ugly’-syntax languages that I have learned to appreciate (plus 
some concision in names). 

Internal defines are thus much more preferable than local, let, letrec, and 
similar constructs. See the Style Guide, where I spelled this out in a bit more 
detail. 

— Matthias


Style Guide https://docs.racket-lang.org/style/index.html



-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to