[Python-ideas] Syntactic sugar to declare partial functions

Abe Dillon abedillon at gmail.com
Mon Aug 13 15:08:39 EDT 2018


[Bruce Leban]

> Lambda calculus IS computer science.

It's a foundation of computer science. That doesn't mean it "IS" computer
science. Set theory is a foundation of computer science. It's still it's
own discipline.

 [Bruce Leban]

> Rejecting lambda as CS is as bad as rejecting the + operator because
> that's mathematics.

This is a complete misunderstanding of my argument.

Not all programmers are computer scientists. In fact, not all programmers
are professional. Many, including myself, came from engineering. Many came
from other scientific fields. Many came from finance and all sorts of
fields. Many are teenagers who just want to build a cool website or a video
game or scrape song lyrics for their favorite bands.

The whole point of a programming language is to bridge the gap between
machine code and natural language (in Python's case English, as with most
other languages). It's to make reading and writing code easier through
abstraction, not to create ivory towers through the use of esoteric jargon.
It's not supposed to make a cool kids club for people privileged enough to
study CS in college. At least that's not my goal.

[Bruce Leban]

> Lambda calculus is a model of computation. It was invented about 30 years
> before the name "computer science" but is nonetheless foundational computer
> science.


Yes. I know.

[Bruce Leban]

> If using lambda as a keyword leads people to go and learn about lambda
> calculus that is a good thing.


I don't think the point of Python is to force people to eat their
vegetables. You might think it's a good thing if everyone learns about
Turing machines and the Halting problem and Kolmogorov Complexity and X86
machine code, etc. but that's not what Python is for. I may think that
everyone should learn what I learned in college about electromagnetics and
semiconductor physics, etc. But I'm not arrogant enough to force that on
people who just want to use abstract tools to get some job done.

I didn't realize that my distaste for 'lambda' was such an unheard-of
opinion. I could have sworn that the likes of Guido Van Rossum and Raymond
Hetinger also found the term at least a little troublesome.

As someone who has taught Python professionally, I can say that there is a
strange mental block regarding lambda expressions. Pretty much every
student I've had has struggled with lambda expressions, even those who
grasp similarly complex constructs like decorators with ease. This includes
students who learned english as a second language. I can only attribute
that to the word 'lambda' being confusing as hell.

[Bruce Leban]

> And as to saying a lambda function is an "anonymous function": the
> anonymity is not a property of the function.


Yes, It is:

>>> def func(x): return x*x
>>> func.__name__
'func'
>>> func = lambda x: x*x
>>> func.__name__
'<lambda>'

[Bruce Leban]

> If I assign it to a name, it's no longer anonymous.


That's not how variable assignment works in Python. The name of the
variable doesn't become an attribute of the object assigned to the variable.

[Bruce Leban]

> I can legitimately argue that + in Python is not the + in mathematics
> because the Python mathematical operators operate on integers and floats,
> not real numbers. Therefore we should use a different word like "floatadd".
> Of course not.


My whole point was to be less pedantic, not more pedantic. Pragmatism
should prevail over pedantry. This is why, as I've stated earlier, I know
that lambda expressions aren't going to change any time soon and I'm fine
with that. I consider it a bit of a wart, but whatever. I'm getting really
tired of having to defend this opinion.

Also, this argument makes no sense. Just because there isn't a way to
represent all real numbers in a computer, doesn't mean that integer,
floating point, and fractional addition become different kinds of addition.

On Mon, Aug 13, 2018 at 1:09 PM, Chris Angelico <rosuav at gmail.com> wrote:

> On Tue, Aug 14, 2018 at 4:00 AM, Bruce Leban <bruce at leban.us> wrote:
> > And as to saying a lambda function is an "anonymous function": the
> anonymity
> > is not a property of the function. If I assign it to a name, it's no
> longer
> > anonymous. Really a "lambda" or "lambda function" is just a function, but
> > "lambda" is a synecdoche for "function created with a lambda expression".
>
> True, but at that point, you get into hairy points of definitions.
> Which of these functions is anonymous?
>
> def do_stuff(callback): ...
>
> do_stuff(do_stuff)
> do_stuff(lambda: 42)
> do_stuff(callback=lambda: 42)
>
> Obviously do_stuff itself has a name. When you pass it a parameter, it
> can access that as "callback", which means the function has been
> assigned to a name. Does it cease to be anonymous? What if you use a
> keyword argument?
>
> Within Python, there's a fairly clear definition: if there is
> something in the source code which sets the function's __name__
> attribute, it's not an anonymous function. So anonymous functions come
> from:
>
> * Lambda expressions, always called "<lambda>"
> * Comprehensions/genexps, always called "<listcomp>" etc
> * Callable objects that aren't functions (or classes, since those have
> names)
> * Maybe something else that I've forgotten.
>
> You're absolutely right that a "lambda function" isn't really a thing,
> in the same way that Python doesn't have "raw strings" (only "raw
> string literals", which are literals which result in perfectly
> ordinary strings). But the anonymity of them is a somewhat measurable
> feature, even if it isn't very important. The distinction between
> "lambda functions" and "def functions" is important to style guides,
> but otherwise shouldn't matter.
>
> ChrisA
> _______________________________________________
> 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/20180813/345b512f/attachment-0001.html>


More information about the Python-ideas mailing list