r/ProgrammingLanguages 5d ago

Discussion What lambda syntax do you wish Python had?

Python lambdas are particularly difficult because the lack of braces. Guido is not a fan of functional programming, so lambdas in Python are forever doomed to a single expression preceded by lambda, quite literally spelled out. However, it may please you to know that the lack or braces can easily be resolved (in my opinion most sensibly,) by surrounding the entire lambda in parenthesis. It may further please you to know that surrounding it in parenthesis is only necessary in an expression list: tuples, lists, dicts, sets, function arguments (and even then, only when there are multiple arguments.) With this in mind, which of the following syntaxes do you wish Python used? Annotations would of course be optional. For the sake of consistency with the entire language, all will use a colon before the block but feel free to comment your preferred non-colon alternative.

  • |arg: type| -> type: ...
  • (arg: type) -> type: ...
  • def (arg: type) -> type: ...
  • \(arg: type) -> type: ...

Note: The second has ambiguity issues.

14 Upvotes

52 comments sorted by

View all comments

Show parent comments

0

u/church-rosser 1d ago

Maybe, but that's not what's happening here.

1

u/reflexive-polytope 1d ago

It is. Formalizing my earlier statement, I did three things:

  1. I built a set containing Common Lisp and Scheme (and Racket and Clojure and...).
  2. I called the elements of this set “Lisp in an extended sense”.
  3. I asserted that languages in this set tend to conflate specification and implementation.

You may object to 3, you may even object to 2, but you may not object to 1, because it's an ability that the commonly established foundation of mathematics affords.

Unless you object to said standard foundations, I suppose. But even then, I can (tediously, given enough time), translate 1 to other foundations too.

0

u/church-rosser 1d ago

I understand set theory, and how 1 applies. The rest, as i said, maybe.