[erlang-questions] Style wars: junk comments

Richard O'Keefe ok@REDACTED
Wed Sep 12 23:59:15 CEST 2012

On 12/09/2012, at 11:48 PM, Fred Hebert wrote:

> This is the approach I like the most.
> It's something I picked up when working with Scheme, where functions can contain the definitions of their helpers within them, which made the code much clearer to me.

Scheme and ML have features that make this rather more useful
than it is in languages like Clean and Haskell.  In ML you can
       <private definitions>
       <public definitions>

and this has the effect that the things defined in
<private definitions> are visible in <public
definitions>, but not outside, while the things
defined in <public definitions> are visible outside.
For example, you might have

      fun rebalance t = ...
      fun add k v t = ...
      fun del k t = ...

Scheme lets you hack this by doing
   (define add)
   (define del)
   (letrec ((rebalance (lambda (t) ...))
     (set! add (lambda (k v t) ...))
     (set! del (lambda (k t) ...))

I see this quite a lot in Scheme.
If Joe's still thinking about Erlang 2, I hope he'll consider
the functionality of local-in-end.

More information about the erlang-questions mailing list