Is there a way to change the closure of a python function?

Gregory Ewing greg.ewing at canterbury.ac.nz
Wed Sep 28 01:27:26 EDT 2016


Lawrence D’Oliveiro wrote:
> On Wednesday, September 28, 2016 at 3:35:58 AM UTC+13, Peter Otten wrote:
> 
>>is Python actually a "functional language"?
> 
> Yes <https://groups.google.com/d/msg/comp.lang.python/P1Edc4eJNkY/D5KBo7skAgAJ>.

No, not according to what the term "functional language"
usually means.

Languages described as "functional" usually incorporate
all or most of the following characteristics:

* No side effects (new variable bindings may be created, but
   existing ones cannot be changed; no mutable data structures).

* Lazy evaluation by default.

* Syntactic support for currying.

* Syntactic support for case-analysis-style definition of
   functions, by matching the arguments against a series of
   patterns.

* A standard library geared towards a programming style
   that makes heavy use of higher-order functions.

Python has none of these features. It's possible to use a
subset of Python in a functional way, but it goes against the
grain, and without all the above support from the ecosystem
it's clumsier than it would be in a real functional language.

Some parts of Python, such as list comprehensions, have a
functional flavour, but Python is predominantly an imperative
language.

-- 
Greg



More information about the Python-list mailing list