[Python-ideas] allow `lambda' to be spelled λ

Ryan Gonzalez rymg19 at gmail.com
Tue Jul 12 20:17:33 EDT 2016


Doesn't this kind of violate Python's "one way to do it"?

(Also, sorry for the top post; I'm on mobile right now...)

--
Ryan
[ERROR]: Your autotools build scripts are 200 lines longer than your
program. Something’s wrong.
http://kirbyfan64.github.io/
On Jul 12, 2016 7:38 AM, "Stephan Houben" <stephanh42 at gmail.com> wrote:

> Hi list,
>
> 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).")
>
> Background:
>
> 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
> improvement in
> readability since λ is visually less distracting while still quite
> distinctive.
> (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
> syntax.
>
> I know people have been clamoring for shorter lambda-syntax in the past, I
> think this is
> a nice minimal extension.
>
>
> Example code:
>
>   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
> sed command.
>
>   sed 's/\<lambda\>/λ/g'
>
> Advantages:
>
> * The lambda keyword is quite long and distracts from the "meat" of the
> lambda expression.
>   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.)
>
>
> Disadvantages:
>
> 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.
>   So backward-incompatible.
>
> Needless to say, my personal opinion is that the advantages outweigh the
> disadvantages. ;-)
>
> Greetings,
>
> Stephan
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160712/a9bc2ccc/attachment.html>


More information about the Python-ideas mailing list