better lambda support in the future?

Steven Bethard steven.bethard at gmail.com
Fri Dec 17 18:46:50 EST 2004


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.  OCaml is compiled, but 
functions are first class objects, and nested scopes are accessible:

# let f x =
      let g y =
         x + y
      in
         g;;
val f : int -> int -> int = <fun>
# f(1);;
- : int -> int = <fun>
# f(1)(2);;
- : int = 3

Note that the type of f is a function that takes an int and returns a 
function that takes an int and returns an int.  OCaml handles nested 
scopes appropriately, and successfully compiles the function f (and 
infers the appropriate types).  So the issue is not static compilation, 
but functions as first class objects.

Of course, many statically compiled languages, e.g. C, C++, Java, do not 
provide functions as first class objects, so the confusion is not 
unnatural...

Steve



More information about the Python-list mailing list