[Python-ideas] allow `lambda' to be spelled λ
stephanh42 at gmail.com
Tue Jul 12 08:38:22 EDT 2016
Here is my speculative language idea for Python:
Allow the following alternative spelling of the keyword `lambda':
(That is "Unicode Character 'GREEK SMALL LETTER LAMDA' (U+03BB).")
I have been using the Vim "conceal" functionality with a rule which visually
replaces lambda with λ when editing Python files. I find this a great
readability since λ is visually less distracting while still quite
(The fact that λ is syntax-colored as a keyword also helps with this.)
However, at the moment the nice syntax is lost when looking at the file
through another editor or viewer.
Therefore I would really like this to be an official part of the Python
I know people have been clamoring for shorter lambda-syntax in the past, I
think this is
a nice minimal extension.
lst.sort(key=lambda x: x.lookup_first_name())
lst.sort(key=λ x: x.lookup_first_name())
# Church numerals
zero = λ f: λ x: x
one = λ f: λ x: f(x)
two = λ f: λ x: f(f(x))
(Yes, Python is my favorite Scheme dialect. Why did you ask?)
Note that a number of other languages already allow this. (Racket, Haskell).
You can judge the aesthetics of this on your own code with the following
* The lambda keyword is quite long and distracts from the "meat" of the
Replacing it by a single-character keyword improves readability.
* The resulting code resembles more closely mathematical notation (in
particular, lambda-calculus notation),
so it brings Python closer to being "executable pseudo-code".
* The alternative spelling λ/lambda is quite intuitive (at least to anybody
who knows Greek letters.)
For your convenience already noticed here:
* Introducing λ is introducing TIMTOWTDI.
* Hard to type with certain editors.
But note that the old syntax is still available.
Easy to fix by upgrading to VIM ;-)
* Will turn a pre-existing legal identifier λ into a keyword.
Needless to say, my personal opinion is that the advantages outweigh the
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas