News for hackers. Stuff that matters.
Re:Stop writing lambda expressions in Python by bunderbunder on Thursday September 27, 2018 @05:27PM (#18088882)
FWIW, in many languages, "lambda expressions" and "anonymous functions" are two similar but different things. Specifically, a lambda expression is a shorthand syntax for writing anonymous functions whose body consists of a single expression.

Which is pretty much what you get in Python.

Re:Stop writing lambda expressions in Python by another-cuppa on Thursday September 27, 2018 @05:30PM (#18088922)
Lambdas aren't single expression functions in Lisp.
Re:Stop writing lambda expressions in Python by bunderbunder on Friday September 28, 2018 @10:17AM (#18093530)
Haha, I had assumed someone would mention that.

But most Lisps are pretty rough-and-ready about these sorts of things. IIRC, Scheme requires the body of the lambda to be a single expression, doesn't it? And then you just cheat your way out of it with (begin ...).

Re:Stop writing lambda expressions in Python by another-cuppa on Friday September 28, 2018 @01:57PM (#18095477)
If it did it would be annoying to type progn all the time and someone would make a macro...
Re:Stop writing lambda expressions in Python by lispm on Friday September 28, 2018 @10:29AM (#18093639)
> IIRC, Scheme requires the body of the lambda to be a single expression, doesn't it?

No, it doesn't require it.

Re:Stop writing lambda expressions in Python by kbp on Sunday September 30, 2018 @04:32PM (#18108239)
It used to, though. From the original Scheme paper: Note that in SCHEME, unlike MacLISP, the body of a LAMBDA expression is not an implicit PROGN.
Re:Stop writing lambda expressions in Python by lispm on Monday October 01, 2018 @03:38AM (#18110678)
Changed in the early/mid 80s I think. AI Memo 848 (Revised Revised Report) from 1985 has it already as an 'essential special form': (lambda (var1 ...) expr1 expr2 ...)

R1RS does not permit it. And: In the the R1RS syntax BNF there is a (DEFINE (<identifier> <identifier list>) <form>) with one form. But later in the document it is a '<form list>'... Then the LAMBDA syntax has a BODY, but it is only a FORM...

Re:Stop writing lambda expressions in Python by ken on Thursday September 27, 2018 @06:28PM (#18089392)
Which languages?
Re:Stop writing lambda expressions in Python by noblethrasher on Thursday September 27, 2018 @10:17PM (#18090484)
C# offers three different ways to denote an anonymous function: Anonymous delegates, lambda expressions, and statement-bodied lambdas. Each of them are true closures and can be used to construct a "method" of a given delegate type (i.e. any one of them can be used to as a value for a given variable — interestingly, in any case, an anonymous method must be assigned to a variable (or parameter) before you can use it, unlike, say, the anonymous functions of Lisp, JavaScript, F#, or even the criminally underrated VB).

But they have some important difference:

1) Anonymous delegates (introduced in C# 2.0) allow you to elide the formal parameters when defining a method of a given type if the body of the method doesn't use those parameters. Even though this construct is basically obsolete, I still use it just for this feature.

2) Lambda expressions can be automatically transformed into expression trees, which means that you can use them to construct (awesomely powerful) fexprs[1]. But, they can't contain statements, which means you can't use them for any kind of imperative code. These are the most equivalent to Python's lambda as far as that limitation is concerned.

3) Statement-bodied Lambdas can contain statements (as the name implies), but the language won't convert them into expression trees for (you can do it manually – tedious but not at all hard). At the time that the lambda expression feature was introduced (as a member of the constellation of features that made up LINQ), the framework didn't even contain expression classes that corresponded to most of the imperative constructs, but that changed with the advent of C# 4.0 which implemented a meta-object protocol[2].

Another implementation detail (last time I checked, which has been a while) is that anonymous delegates get turned into instances of System.Multicast delegate, whereas a lambda expression either gets turned into a class with a method that corresponds to the lambda expression (and fields that correspond to closed over variables), or into an expression tree, depending on the class of the variable to which it's being assigned.

[1] https://en.wikipedia.org/wiki/Fexpr

[2] https://en.wikipedia.org/wiki/Metaobject

Re:Stop writing lambda expressions in Python by jcelerier on Friday September 28, 2018 @02:36AM (#18091453)
Always heard them called lambda expressions in c++.