Question on lambdas

Rustom Mody rustompmody at gmail.com
Tue Dec 9 01:44:37 EST 2014


On Tuesday, December 9, 2014 5:28:49 AM UTC+5:30, Ben Finney wrote:
> memilanuk writes:
> 
> > What I'm having trouble finding a concrete answer to is the difference
> > between:
> 
> (Note that where you write “some_func” the syntax requires an
> expression, not a function. I've changed your examples to be clear).
> 
> > lambda: some_expr
> 
> This creates a new function which expects zero parameters. The function,
> when called, will return the value of ‘some_expr’.
> 
> > lambda x: some_expr
> 
> This creates a new function which expects one positional parameter named
> ‘x’. The function, when called, will return the value of ‘some_expr’.
> 
> > lambda x=some_value: some_expr
> 
> This creates a new function which expects one parameter named ‘x’, which
> parameter has a default value of ‘some_value’. The function, when
> called, will return the value of ‘some_expr’.
> 
> > Any help would be greatly appreciated.
> 
> Hope that helps.
> 
> It's best to remember that ‘lambda’ is syntactic sugar for creating a
> function; the things it creates are not special in any way, they are
> normal functions, not “lambdas”.

This is a good thing to remember (and better than most of the λ-calculus memes
floating around the net).

> What is different is that the function starts with no name bound to it,
> and the syntax allows only a single expression as the body of the
> function.

Cant quarrel with this as a fact but its the wrong emphasis IMHO:
Its not that lambdas are functions without names -- so called `anonymous' functions.
Its rather that defs are functions with names, ie a def bundles up two independent activities:
naming and function-making.

Do we call constants 'anonymous variables'?
One could of course but its misleading because constants come before variables

Most people know this in the form: "Arithmetic comes before algebra"
A CS buzz version: Functional programming is simpler than imperative programming.
However I find this unhelpful and misleading for the same reason that 'λ is 
an anonymous function' is: If functional programming were 'programming with functions' then
C would be a functional language <wink>

Here is our attempt at explaining this in more detail in 'modern' format
https://www.youtube.com/watch?v=FZoq-GlOdSs

The above is all with 'conceptual-fundamentals' hat firmly on.

>From the pragmatic pov, the need to mix naming with function-making is
so overwhelmingly what is needed, that rarely/never using lambdas is ok.

JFTR Miranda one of the seminal functional languages, had no lambdas, only
(the equivalent of) defs.
Put differently, Ive no issue with Guido wanting to remove lambda from python
[In any case in the unicode age I'd prefer it spelt as λ]

Ive an issue with people claiming to have a degree in CS not knowing (basics of)
λ-calculus



More information about the Python-list mailing list