Jeff Shannon <[EMAIL PROTECTED]> writes: > Steven Bethard wrote: > 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)
This is really no different than: def f(x): if x < 0: g = -y else: g = y return g The only difference is that you're binding the variable g to a y type instead of a function type. That's what "first class functions" means. You can treat functions like any other object, assign them to variables, pass them as parameters, and so on. <mike -- Mike Meyer <[EMAIL PROTECTED]> http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list