Are there languages where the scope is defined in such a way that does not extend to the enclosed functions? In other words is there a language where a code like the following (Python-like syntax):
>>> x = 3
>>> def fact(n):
... print x
... return reduce(lambda u, v: u*v, xrange(1, n+1), 1)
...
would give an error because x is not defined inside the function fact
?
In general, are there languages where the scope of any function wouldn't include functions defined within it?
Edit: Thanks for the informative comments. The reason I thought about this is that the situation of an internal function having access to all the environment provided by its containing functions sounds suspiciously close to me to the situation described by Joe Armstrong in his argument against OOP:
Because the problem with object-oriented languages is they’ve got all this implicit environment that they carry around with them. You wanted a banana but what you got was a gorilla holding the banana and the entire jungle.
Also relevant is that I hear that the language Newspeak doesn't has no global namespace, though I have no idea how it works.
I can imagine the issue, raised in Brian's comment below, of built-in functions (functions imported from __builtins__
in Pythonspeak or System in many other languages) be introduced artificially by the interpreter/compiler in every function. After all they are almost always treated specially in the language in the first place. Another option is to have them as methods of an object passed as a parameter to the function or imported as a module from within.