Re: identifiers and modules
- From: Per Bothner <per@xxxxxxxxxxx>
- Date: Sun, 01 Jan 2006 00:16:33 GMT
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/ .
- Follow-Ups:
- Re: identifiers and modules
- From: Anton van Straaten
- Re: identifiers and modules
- From: Ulrich Hobelmann
- Re: identifiers and modules
- From: Pascal Costanza
- Re: identifiers and modules
- From: Joe Marshall
- Re: identifiers and modules
- Prev by Date: Re: Invariants in a loop
- Next by Date: Re: cdr with dotted pair
- Previous by thread: Help with Dr. Scheme- Negative integers/Rational numbers
- Next by thread: Re: identifiers and modules
- Index(es):