Re: identifiers and modules



Per Bothner wrote:
Anton van Straaten wrote:

Per Bothner wrote:

Rebinding a variable name in an inner block is most likely an error.
Do you have a reason why a language should allow it?

Are you suggesting that something like the following should not be allowed:


(let ((foo (initial-value)))
  ...
  (let ((foo (transform-value foo)))
     ...))


Well, my suspicion is that the arguments for allowing it are weaker than
the reasons for prohibiting it.

In addition to selecting different names, there is also the alternative
of using assignment:

(set! foo (transform-value foo))

Note this isn't really enough less "functional" than the original - many
compiler will treat them equivalently.  And if you're arguing for
readability, then I think error-proneness trumps that.

Certainly many beginners (who do not understand the difference between
declaration, initialization, and assignment) will write legal code
that doesn't do what they intend.  And experienced programmers
working on a large nested function can easily use the wrong variable
when two variables have the same name.

Given that allowing an inner declaration to override an outer
(but still lexical) declaration provides no additional functionality.
the tradeoff favors removing that source of mistakes.

Excellent observation! I wasn't even aware that this restriction exists in Java, and I have never had any problem with it.


Enforcing this in a Lisp/Scheme dialect would remove the problem of accidental nameclashes completely (not only in macros).


Thanks, Pascal

--
My website: http://p-cos.net
Closer to MOP & ContextL:
http://common-lisp.net/project/closer/
.