Steven Bethard wrote:
Jeff Shannon wrote:
It occurs to me that, in a statically compiled language, function definitions all happen before the program starts, and thus that definition can't be affected by other variables (i.e. an outer function's parameters).
I think you might be confusing static compilation in a language with lack of first-class functions in a language.
Hm, possibly. I must confess that my direct knowledge is limited to a fairly narrow set of languages, and that C and C++ are the only statically-compiled languages I've used. Still, I'm not sure that it's just a matter of functions as first-class objects. Would OCaml (or some other static language) have something that's equivalent to this?
def f(x): if x < 0: def g(y): return y * -1 else: def g(y): return y return g
foo = f(1)
Here, nested scopes are not enough. Only one of these functions is created, and which one that is depends on the run-time value of the function parameter. A compiler couldn't know this ahead of time. I suppose it might be able to do something by compiling both of them, (though I'm not sure how it'd track two different functions with the same name in the same namespace...) but that seems a bit questionable to me...
Jeff Shannon Technician/Programmer Credit International
-- http://mail.python.org/mailman/listinfo/python-list