Python
- This article deals with Python as it relates to esoteric programming. For more general information, see the Wikipedia article on Python.
Python, while not always a serious language, is far from an esoteric one. It is a general purpose programming language emphasising readability, and has found a number of uses from statistical analysis, to writing automation scripts, to implementing esoteric language interpreters. Its key traits are the aforementioned legible code, semantic indentation, and a variety of libraries created for it.
It spawned partially formed from the mind of Guido van Rossum in the 1980s. It is fully bootstrapped and a common gateway language for learners who are new to programming, in part because it is high-level enough to resemble English, and in part because it minimises the boilerplate code one needs to memorise.
While languages like Forth and Lisp have been influential to esolangs predominantly because the languages are inspired by how the languages work, Python is more in the Perl category of practical languages, which are often used to implement an esolang. Esolangs based on images like StegFuck is usually implemented in Python, because there are lots of packages for image processing (e.g. the Python Imaging Library and OpenCV) for this language. Esolangs that need arbitrary integer size are also usually implemented in Python.
Lambda
Python is often criticized for a weak lambda syntax. However, Python is complete for lambda-expressions! For example, habnabit 2015 implements a basic chat server in a single lambda expression.
Closure Quirk
As one of its exceptions to lexical scoping, Python has a quirky behavior for closing over scoped names. User:Corbin gave the following example in 2017:
>>> l = [(lambda y: x + y) for x in range(5)] >>> [f(0) for f in l] [4, 4, 4, 4, 4]
This is known as the "lambda quirk" or "closure quirk". Relatives of Python like Monte do not have it:
▲> [for f in ([for x in (0..!5) fn y { x + y }]) f(0)] Result: [0, 1, 2, 3, 4]
The genesis of closure quirk is likely in one of the many Lisps which inspired Python, although it is not clear which one to blame. It does not occur in Standard ML, another language whose descendants also inspired Python; for example, Corbin 2017 shows that it does not occur in Haskell:
Prelude> [ f 0 | f <- [ (x +) | x <- [0..4] ] ] [0,1,2,3,4]