Late-binding of function defaults (was Re: What is a function parameter =[] for?)

Steven D'Aprano steve at pearwood.info
Wed Nov 25 19:31:27 EST 2015


On Thu, 26 Nov 2015 09:41 am, BartC wrote:

> Maybe you're too familiar with it. But the idea of executing the
> function and other definitions in a file, instead of they just being
> there, is novel.


It really, truly isn't. Your viewpoint is clouded by too much immersion in
crippled languages. *Old and obsolete versions* of crippled languages.
Dynamic creation of functions goes back to the 1950s.

Functions in Python are *first class values*, just like ints, strings, lists
etc. That means functions can be passed around as arguments, assigned to
variables, returned from functions, and created on the fly as needed. This
is not an innovation from Python -- Python rarely, if ever, innovates. By
the time any feature hits Python (yes, even significant indentation) it has
typically been proven in at least one other language.

Languages with first class functions include Perl, Javascript, Lua, PHP,
Tcl/Tk, Io, Go, Rust, Maple, Mathematica, Smalltalk, Swift, and varied mix
of old (Smalltalk and Perl) and new (Rust and Swift).

It is almost unthinkable to imagine a functional programming language
without this feature, and sure enough Scala, Haskell, ML, Clojure, and
Scheme have it -- as does Lisp, which is the second oldest high level
language in existence. Only Fortran is older.

Delphi (a variant on Pascal/Algol) has supported them since 2009. C++, C#
and Objective C have support for first class functions. Even Java 8 and
above includes this feature.

In 2015, it's hard to think of any non-obsolete, non-toy language which
doesn't treat functions as first-class values, including creating them on
the fly. Fortran and C perhaps.



-- 
Steven




More information about the Python-list mailing list