hikari-no-yume / Firth

Firth is a functional, strongly dynamically-typed, concatenative stack-oriented programming language.
Other
29 stars 2 forks source link

Should def allow shadowing? #11

Closed hikari-no-yume closed 9 years ago

hikari-no-yume commented 9 years ago

i.e., is the following valid, or not?

/foo 2 def.
[
    /foo 3 def.
    foo print.
]
foo print.

def definitely won't allow redefinition of a variable within a scope. But within a new scope, can a variable be created with the same name as a scope lower in the stack, thus shadowing it?

Not allowing shadowing would make the compiler's job easier, since you then couldn't, say, change the meaning of def.

hikari-no-yume commented 9 years ago

Note: the interpreter and specification are currently in conflict here. The interpreter forbids shadowing, while the specification requires it!

hikari-no-yume commented 9 years ago

After reading Guido van Rossum's excellent post on Python's True, False and None and how they are literals, not variables, I remember why shadowing is good. If you forbid it, you're making all new stdlib additions into reserved words, and that's awful for backwards-compatibility. So, shadowing shall be allowed.

hikari-no-yume commented 9 years ago

Oops, I forgot that the interpreter actually did allow shadowing. My memory was bad. Anyway, the issue is resolved!