[erlang-questions] Local namespaces in case/try

Richard O'Keefe ok@REDACTED
Wed Jul 11 03:35:07 CEST 2012


On 10/07/2012, at 10:00 PM, Dmitry Groshev wrote:

> Exactly what I was talking about. I can't see any sense in bloating the code with nonsensical functions

It isn't the functions that are nonsensical, it is
using the same variable with two different meanings
which is in the strict literal sense of the word nonsensical.

Give us a serious example!
Show us some code that is easier to read if you do this!

Yes, other functional languages have nested variable scopes within a
single function (although the semantics is often defined in terms of
nested functions), BUT those languages require you to introduce new
bindings with keywords

    (define (f X)
      (let ((R) (E))              ;;; HERE!
        (let ((V (do-something)))
          (case (car V)
            ((result) (set! R (cadr V)))
            ((error)  (set! E (cadr V))))))
      (let ((R) (E))              ;;; HERE!
          (case (car V)
            ((result) (set! R (cadr V)))
            ((error)  (set! E (cadr V)))))))

Lisp and Scheme have LET and LET*.
ML has let.
Haskell has let and where.

If you want Lisp-Flavoured Erlang, it exists.




More information about the erlang-questions mailing list