Lets make λ as alternative keyword for lambda

Make λ a keyword with identical meaning to lambda.
Keyword λ would be more readable because it is shorter than lambda, besides lambda basically means λ.

Now that almost every PC can type non ASCII characters, we have snippets in every serious editor & we have formatters like Autopep & Black, I don’t see any reason to restrict code to English alphabet.

Because almost nobody used non-englis characters in code (outside of strings), this will not have significant impact on existing codebase.

Also almost every monospace font support Greek letters.

I also see this as an opportunity. Who knows what people can come up with if this will become accepted practice.

I :green_heart::snake:!

This would break existing code. The following is currently valid:

>>> λ=4
>>> {λ:3}
{4: 3}

Which is different from:

>>> {lambda: 3}
{<function <lambda> at 0x6fffffe9f4c0>}

And even if it did work, I’m not sure it would be worth the hassle of a requiring a soft keyword.

1 Like

Hi Chuck, and welcome!

Aside from people who can read Greek, and some mathematicians and physicists, how is λ “more readable” than lambda? Lambda is a word that
anyone familiar with English can sound out, type, and google for. For most people, λ is a mystery symbol, as strange and exotic as Ⴋ (U+10AB).

“Shorter” is not always more readable. Do you name all your modules, functions, classes and methods one-letter names?

from c import d
v = d()
v.a(None)
p(l(v))

Compare:

from collections import deque
values = deque()
values.append(None)
print(len(values))

PCs don’t type. Human beings type. How do I type the letter λ, without copying it from somewhere else, or calling up a special Character Map application, searching for lambda, and copying from that?

That’s a serious question, please answer. I’ve just been copying it from your post, which is annoying.

I doubt that reducing the keyword from six letters (lambda) to one (λ) is going to change to Python ecosystem that much. Lambdas will still be
restricted to a single expression, and mostly useful for key functions and callbacks. Just saving five letters is not going to make lambdas more useful or more popular.

6 Likes

On Ubuntu (and other X11 Linux), type ctrl+shift+U, then the Unicode hex (eg b0 for the degree symbol °, or 03BB for the lambda symbol λ), then space or enter.

On Windows, hold Alt then type the Unicode decimal (eg 192 for °).

See Unicode input - Wikipedia for your OS

On any platform, press this key sequence: L, A, M, B, D, A

Oh look! It’s easy to remember.

Why do people seem to think that memorizing codepoint numbers is an acceptable way to enter symbols?!?

If you have Compose key sequences, an AltGr key, or any other decently-memorable input method, then sure; but askiing programmers to memorize the codepoints for symbols is a TERRIBLE way to encourage adoption of a feature.

1 Like

I know Julia has an editor that allows you to input special characters with a slash, so /lambda would turn into λ. I guess the idea is to make the code look more like mathmatical notation, but I think it’s a terrible idea because it encourages single-letter variable names. Not every language needs to look like APL :slight_smile:

Wait, you expect people to memorise hex or decimal codes for this feature???

That’s the complete 180° opposite of a user-friendly feature. I don’t know whether to laugh or cry.

But in the spirit of experimentation, I tried your instructions in my email client, the Python interactive interpreter, and my usual text editor, and it does seem to work.

Oh I completely disagree with the proposal, primarily for Eric’s reason above, but you asked a question and I assumed you didn’t know the answer. Personally, I only have memorised degree ° (b0) and plus-minus ± (b1) which are useful while coding (for comments and report mark-up) in my industry.

On Window you can also use win + . to enter any unicode character.
If your editor support LaTeX snippets (ussually there is extrention to that) you can use \lambda + tab to autocomplete.

No, I expect people to write lambda as they always have, but I also expect editors/formaters to change it to λ.

I believed most people who use python knows what λ is as much as π. Would you say that there is difference in readability between from math import π and from math import pi? Well maybe I’m just biased, I don’t know.

sounds more like an editor feature, than a language feature

and it is already possible, for example for vscode

1 Like

Or a font feature, which is also already possible.

That would be this kind of logic applicable to APL or Perl. The natural logical consequence of this type of reasoning is an unreadable abomination of very terse write-only notation galore:


λ is easy to remember and write. But so is π. And so is . And Ø. Why stop at lambdas?

I feel like presumption of syntax additions as readable pseudocode expressed in ASCII is a brilliant rule of thumb that Python has, and I really hope that Python will not abandon it as it evolves. It’s extremely mentally undemanding to write, and extremely easy to read.

1 Like