[Python-ideas] allow `lambda' to be spelled λ
Sven R. Kunze
srkunze at mail.de
Tue Jul 12 16:21:26 EDT 2016
Completely matches my opinion. Thanks.
On 12.07.2016 20:36, tritium-list at sdamon.com wrote:
>
> For better or worse, except for string literals which can be anything
> as long as you set a coding comment, python is pure ascii which
> simplifies everything. Lambda is not in the first 128 characters of
> Unicode, so it is highly unlikely to be accepted.
>
> ·‘Lambda’ is exactly as discouraging to type as it needs to be. A
> more likely to be accepted alternate keyword is ‘whyareyounotusingdef’
>
> ·Python doesn’t attempt to look like mathematical formula
>
> ·‘Lambda’ spelling is intuitive to most people who program
>
> ·TIMTOWTDI isn’t a religious edict. Python is more pragmatic than that.
>
> ·It’s hard to type in ALL editors unless your locale is set to
> (ancient?) Greek.
>
> ·… What are you doing to have an identifier outside of
> ‘[A-Za-z_][A-Za-z0-9_]+’?
>
> *From:*Python-ideas
> [mailto:python-ideas-bounces+tritium-list=sdamon.com at python.org] *On
> Behalf Of *Stephan Houben
> *Sent:* Tuesday, July 12, 2016 8:38 AM
> *To:* python-ideas at python.org
> *Subject:* [Python-ideas] allow `lambda' to be spelled λ
>
> 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/8dc0dc3e/attachment.html>
More information about the Python-ideas
mailing list