Re: identifiers and modules



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.

If the former, then there are many reasons to allow it.

And they are? -- --Per Bothner per@xxxxxxxxxxx http://per.bothner.com/ .