from functools import partial
def add(x: int, y: int) -> int:
return x + y
add_2 = partial(add, 2)
def add(x: int, y: int) -> int:
return x + y
add_2 = add{2}sort_by_x = sort{key=lambda element: element.x}
# prepare the function
get_sorted_users: Callable[[], Iterator[User]] = sort{users, key=lambda user: user.creation_date}
# continue with job at hand
...
# some where else, maybe another process
sorted_users = list(get_sorted_users())
@dataclass
class Product:
name: str
category: Category
price: Decimal
smartphone_factory = Product{category=smartphone_category}
_______________________________________________
Python-ideas mailing list
Python...@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/
@partiallymultidef stuff(x,y,z):return x - y + 2*z
If we were to push partial application as a mainstream technique, and
I'm not saying we should, but if we did, my vote would be to give
function (and method) objects a partial method:
add1 = add.partial(1)
although possibly a less jargon name would be nicer:
add1 = add.given(1)
--
---
You received this message because you are subscribed to a topic in the Google Groups "python-ideas" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python-ideas/jOMinivFCcQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python-ideas...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and all its topics, send an email to python-ideas+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and all its topics, send an email to python-ideas...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I prefer partial since many programmers studied computer science
It makes the concepts easier to google.
It's a clear, *generic* meaning that doesn't have any association with
partial application.
We'd be trying to create that association from scratch.
> Words like 'partial', 'curry', 'lambda', and 'closure' are fine
> for text books, published papers, and technical discussion,
And programmers.
Programming is a technical skill with its own jargon. Classes,
inheritence, exceptions, trampolining, processes, threads, protocols,
imports, decorator, builders... we are happy with all those, why should
we fear partial and lambda?
> but I think
> they would (or do in the case of 'lambda') harm Python.
That's an extreme overreaction.
Do you mean to imply that there are people who looked at Python, loved
the language, but decided to use something else because they didn't like
the choice of the keyword "lambda"?
If not, in what way is Python harmed? Would it be faster if the keyword
was "function", or use less memory, or more expressive?
Remember that to millions of programmers in the world, "function" is
just as much an obscure foreign piece of jargon they have to memorise as
"lambda" is to English-speakers.
although possibly a less jargon name would be nicer:
add1 = add.given(1)
[Neil Girdhar]I prefer partial since many programmers studied computer science
Many did not. I studied electrical engineering and wouldn't have been able to tell you what the word 'partial' meant four years ago even though I've been programming in one form or another since the late nineties. Many programmers are scientists, engineers, financial analysts, etc. I'm pretty sure I know what a closure is or what currying is, but if you put me on the spot, I'd probably turn to Wikipedia to make sure I don't screw up the definition.
[Neil Girdhar]It makes the concepts easier to google.
That can be an important criteria, but it can also be a red-herring. If an implementation is clear enough, few people would have to google it. If, however, you use obscure enough words like "lambda", people will google it every day and still find it confusing. The ternary expression is difficult to google if you don't know the jargon "ternary", but there's less of a need to google it because it's pretty obvious how it works based simply on its implementation.
[Steven D'Aprano]It's a clear, *generic* meaning that doesn't have any association with
partial application.
We'd be trying to create that association from scratch.
Sure, that's a good point. I don't think that sounds like such a big problem, but I also don't hate 'partial'. I just prefer 'given'.
At any rate, I don't find the google-ablilty argument super strong because there are many constructs that are difficult to google, but still pretty great (e.g. comprehensions).
--
---
You received this message because you are subscribed to a topic in the Google Groups "python-ideas" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python-ideas/jOMinivFCcQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python-ideas...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
_______________________________________________
Python-ideas mailing list
Python...@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/
--
---
You received this message because you are subscribed to a topic in the Google Groups "python-ideas" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python-ideas/jOMinivFCcQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python-ideas...@googlegroups.com.
> ... I don't find the google-ablilty argument super strong because there are many constructs that are difficult to google, but still pretty great (e.g. comprehensions).
Not that it matters, but comprehension is a standard term in mathematics and computer science apparently:
I disagree with you though when it comes to avoiding the technical terms. It's easier for people new to a field to learn the jargon of that field than it is to try to make it easier for them and by essentially creating a whole lot more technical jargon.
To unsubscribe from this group and all its topics, send an email to python-ideas+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
_______________________________________________
Python-ideas mailing list
Python...@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/
--
---
You received this message because you are subscribed to a topic in the Google Groups "python-ideas" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python-ideas/jOMinivFCcQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python-ideas+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hello,Adding a new method to function object can break existing projects, but it is without impact with buit-in functions because they are immutables.
Currently the user defined functions are mutables, there can be existed python codes like this:
>>> def foo():
... pass
...
>>> if not hasattr(foo, 'partial'):
... foo.partial = {}
...
Just because I challenge your statements doesn't mean I'm attacking you.
You've said that the choice of keyword, "lambda", has caused harm. Given
the chance to clarify what you meant, you stood by your comment that the
choice of keyword "lambda" has done real, significant, non-trivial harm
to Python (the language, or the community).
I think there are better ways that anonymous functions could have been implemented. I've already said in past discussions, I think the expression should come before the signature because the signature is often obvious from context so placing it before the logic is kinda noisy. I don't know what the best syntax would have been, but I refuse to believe that an esoteric word from an esoteric branch of calculus with an arbitrary etymology was the absolute best choice available. I think the harm that choice caused is relatively minor, but I don't think it was a great choice.
This is a genuine question. I'm trying to understand your comments, not just dismiss them.
Presumably you fear the same thing will happen again if we choose "partial" (otherwise, why raise the issue?).
Python does have a long-standing tradition of sticking to mostly English words, a tradition for which I personally am grateful.
But we ought to "check our privilege", as they say. I think that if we
as a community automatically reject any word because it isn't "plain
English", that would be a sign of unexamined privilege and quite rude to
boot.
How can we insist that 3/4 of the world learn English words to use Python
...if we aren't even willing to move out of our own comfort zone to
the extent of learning accurate jargon terms from our own profession?
If we go down this path... and choose "given" over "partial", we ought to be
clear about the reasons why.
He is questioning the concept that the lambda keyword has caused any harm. You assert that it caused minor harm. Minor harm can still be real, significant, and non-trivial.
You will find no evidence to support your argument.
If your reaction was extreme, saying so isn't attacking you.
Explain, please, what the HARM is that comes from the use of the word
"lambda".
Also, the signature is most decidedly NOT obvious from context
nor is it insignificant.
Putting it first gives context to the body of the
function. Python made the correct choice here.
Ryan (ライアン)
Yoko Shimomura, ryo (supercell/EGOIST), Hiroyuki Sawano >> everyone else
https://refi64.com/
lst.onselect = anonfunc(print(target_item))
What's target_item? If you can't see the signature and see that it's a
parameter, you should look externally for it.
Now that the discussion has officially devolved into something that has absolutely nothing to do with the original topic, I'd like to point out something: (Note that I have no affiliation with the managers of this mailing list at all and am just posting this as an outsider.)In Steven D'Aprano's original message, I didn't see anything there as being a personal attack or as having an angry tone, at least based on his normal posting style. Maybe a bit critical and stern, but not really personal. You may have interpreted it as that, but I seriously doubt it was the intention.
--
---
You received this message because you are subscribed to a topic in the Google Groups "python-ideas" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python-ideas/jOMinivFCcQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python-ideas...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
_______________________________________________
Python-ideas mailing list
Python...@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/
--
---
You received this message because you are subscribed to a topic in the Google Groups "python-ideas" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python-ideas/jOMinivFCcQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python-ideas...@googlegroups.com.
Maybe we need to revive that discussion? Overall, I don’t think we have a people problem on this list as much as we have an administration tooling problem.
How often are straw polls actually needed? The popular vote is almost
entirely meaningless.
ChrisA
On Tue, Aug 14, 2018 at 3:06 AM, Michael Selik <mi...@selik.org> wrote:
>
>
> On Mon, Aug 13, 2018, 5:59 AM Nicholas Chammas <nicholas...@gmail.com>
> wrote:
>>
>> Maybe we need to revive that discussion? Overall, I don’t think we have a
>> people problem on this list as much as we have an administration tooling
>> problem.
>
>
> +1
>
> Even the fact that "straw poll" votes aren't counted automatically shows
> that better tools could help.
>
How often are straw polls actually needed? The popular vote is almost
entirely meaningless.
_______________________________________________
[Steven D'Aprano]...if we aren't even willing to move out of our own comfort zone to
the extent of learning accurate jargon terms from our own profession?
Very few of us are computer scientists by profession. That's not even where 'lambda' comes from. In computer science, it's called an "anonymous function". "lambda" comes from lambda calculus.
Lambda calculus IS computer science.
Rejecting lambda as CS is as bad as rejecting the + operator because that's mathematics.
Lambda calculus is a model of computation. It was invented about 30 years before the name "computer science" but is nonetheless foundational computer science.
If using lambda as a keyword leads people to go and learn about lambda calculus that is a good thing.
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.
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.
Nicholas Chammas writes:
> From what I’ve seen on this list in my relatively brief time here,
> this forum is mostly fine and the participants generally behave
> like adults. I don’t read every thread, so maybe I don’t have an
> accurate picture. From what I’ve seen, there is the occasional
> spat, where people just need to step away from the keyboard for a
> bit and cool off, but I wouldn’t consider the environment
> toxic. That seems like too strong a word.
I would go further, and say that use of the word says more about those
who used it than about the list.
> What I feel we lack are better tools for checking bad behavior and
> nudging people in the right direction, apart from having
> discussions like this.
I disagree. I think this is a scale problem: we have too many people
posting, some of them new or infrequent, to prevent (1) people getting
triggered by one word in an otherwise excellent post and going off in
their replies, (2) intemperate rebuttals to the replies in (1), or (3)
interminably long threads sustained by people who don't yet know when
not to post.
If (1) and (2) can be solved by moderation, then you pretty much have
a toxic channel.
The best solution to (3) is not channel-wide moderation, but killing/
muting the thread or specific posters in your MUA. If you're going to
participate in channels as high-traffic as the Python lists, and still
try to hold down a day job, this is one of the very few features where
I'm willing to say "bite the damn bullet and get a REAL MUA!" It
really improves life. If most people have muted the thread, there's
little to no harm in letting those who still care continue. This also
has the advantage that you don't have to wait for a thread to be of
use to nobody to kill it. You can do that now!
> These things would have been pretty handy in several recent and
> heated discussions, including the PEP 505 one I participated in a
> couple of weeks ago.
PEP 505 was an example of none of the above as far as I can see,
though. I think it's tough to find places where you could invoke a
thread freeze or a poster ban and not get a storm of pushback. And
it's kinda hard to see how killing a thread on an open PEP is useful.
> How much of this is possible on a mailing list?
Poster bans, whether temporary or indefinite, are possible.
Thread freezing or closing are in principle possible, but they'd be
really annoying to posters due to the nature of email, I suspect
(posts would bounce and clutter up your inbox later, rather than
having the "post reply" function disabled in the UI). Nor are they
implemented in GNU Mailman, although spam-checking could probably be
coerced to serve (ban messages where In-Reply-To or References
contains recent IDs in the frozen/closed thread). This would require
some additional scripts for efficient admin, and MUA tooling to
extract References would be nice, but all that doable in an afternoon
or two.
> But I remember a year or two ago there was a proposal to move
> python-ideas to a different format, perhaps a Discourse forum or
> similar, which would provide some handy administration tools and
> other UX improvements.
Going back to that discussion now that Guido is less involved might
get you a different answer. (He was not a fan of Discourse, and while
he told me he likes Zulip at PyCon Cleveland, he also said he sees it
as independent of the function of mailing lists. He also said Mailman
3's HyperKitty forum-like functionality sounds like it will be good
enough for him soon enough, so he'd probably be opposed to moving to
forum software on the "don't break what don't need fixing" principle.
All that is almost moot now.)
> Overall, I don’t think we have a people problem on this list as
> much as we have an administration tooling problem.
That's what @jack says, too. :-/ Sorry, that's a bit too snarky, but
the fundamental problem is that *people* post too much. That's a
*people* problem even though there are no problem people, and the
people that are deciding what to post aren't the admins (unless you'll
accept out-and-out censorship, or an editorial board if you prefer a
euphemism). So I don't see an admin tooling solution here.
Steve
--
Associate Professor Division of Policy and Planning Science
http://turnbull.sk.tsukuba.ac.jp/ Faculty of Systems and Information
Email: turn...@sk.tsukuba.ac.jp University of Tsukuba
Tel: 029-853-5175 Tennodai 1-1-1, Tsukuba 305-8573 JAPAN
> 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.
The whole point of a car is to make driving easier through abstracting
away the internal details of petrochemical propulsion, but if someone
says "I don't want to know about 'gears' or 'brakes' or any of these
technical terms", you wouldn't want them driving on the roads you're
on. There is a certain level of comprehension that you can't avoid.
(If you don't know anything about how to use a car, you can still ride
in one, but you can't drive it; and you don't need to understand about
anonymous functions in order to operate a computer, but you'll need
them to program effectively.)
- I accept that there've been a few cases where I could have
chosen my words better, and consequently I've rubbed Abe
the wrong way; sorry about that Abe, as I said earlier (and
I meant it) I have no grudge against you.
- The most important technical issue I wanted to get from my
discussion with Abe has been solved, I now believe that I
understand what harm he feels was caused by chosing the name
"lambda" over some alternative.
- Namely (if I have understood Abe correctly) its the lost
opportunity to have a better name.
- Which seems to me to be so slight a harm that I don't think
it gives us any guidance at all as to whether "partial" or
"given" would make a better name for this proposed feature.
It certainly has not been helped by people fanning the flames of
argument by calling this a "toxic forum".
We should assume good faith. Before flying off the handle and taking
offense, we should assume misunderstanding (on either or both party),
accidental poor choice of wording, or merely robust debate rather than
malice. We ought to be careful about making assumptions about people's
motives from their responses. Email is a notoriously bad medium for
judging people's motivation.
The rest that follows is detail, responding to a few specific points
which I deem relevant but not essential.
> I explained my position on lambda as fully as I care to in my response to
> Niel if you care to read it.
I did read it. Just because I didn't respond to it directly doesn't mean
I didn't read it.
You say you object to the name, but then suggest a change that is
idependent of that name.
> [Steven D'Aprano]
>
> > How can we insist that 3/4 of the world learn English words to use Python
>
> Do you really think that 3/4 of the world learns English just to write
> Python?
That's not what I wrote. There's a difference between these two
positions:
- needing to learn to read English words to use Python;
- using Python is the only reason to learn English.
I said the first, not the second.
Chris Angelico wrote:
> No, lambda calculus isn't on par with brakes - but anonymous functions
> are, and if they're called "lambda", you just learn that.
It's like saying that people would find it easier to learn to
drive if "brakes" were called "stoppers" or something. I don't
think that's true.
For my part, I don’t think I’ve ever used partial in production code.
It just seems easier to simply fo it by hand with a closure ( Am I
using that term right? I still don’t quite get the terminology)
And if I had a callable class instance I wanted to “customize”, I’d
likely use an OO approach — parameterize the instance, or subclass.
So yeah, partial is probably used primarily with “regular” functions.
But then, I don’t know that we need any easier syntax anyway — maybe
I’d be more likely to use it, but it kind of feels like a feature
that’s there so we can write more functional code for the sake of
writing more functional code.
If someone’s really interested in this, a search on gitHub or
something to see how it’s used in the wild could be enlightening.
-CHB
OTx2, and no offence, but … this is supported by research as well. People
tend to search just long enough to find the link that backs their …
observations. :)
Stefan
Michael Selik schrieb am 14.08.2018 um 21:42:
> This is supported by education research. Some light Googling found a
> study on the topic [0] that is consistent with my own observations.
OTx2, and no offence, but … this is supported by research as well. People
tend to search just long enough to find the link that backs their …
observations. :)
In my own experience teaching, I find that many concepts are easier to introduce if I avoid the Python jargon until after I've explained what it does. [...]
[...] It's tempting to use terms based on the origin of the concept, historical odds and ends, or even jokes. [...]
The conversation about syntactic sugar for ``functools.partial`` led to a question about whether jargon like "lambda" makes the concept of an anonymous function more difficult to learn.
While NOT wanting to start another fight I feel that I must put my
pedant hat on & point out that the above highlights why domain specific
words are used and their specificity actually highlights important
concepts, i.e.:
* Brakes are used to apply breaking, (i.e. to slow the vehicle,
possibly to a stop), while stoppers STOP something.
* postprandial = after Lunch (not after eating any meal or after a snack).
In all of these cases there is a specificity to the word used that is
missing from the alternative offered that will, hopefully, be raised by
the use of that word. Unfortunately many people, when trying to explain
what the word means fail to highlight where it is different (the number
of times that I have heard people "explain" port and starboard as left
and right without mentioning the word bow or forward is countless).
Using a slightly unfamiliar word can cause people to ask, or think
about, why this is different & what the difference is while also drawing
a parallel that can help the user/student to understand & remember the
concept.
Also, picking a label for something, and using it consistently, can
vastly simplify things like manual searches (or on-line searches).
Whether you spell it "function(arg) {...}" or "lambda arg: ...", it's
the semantics that are hardest to learn.
> For instance: when the iPhone was introduced, a lot of people praised
> it's subjectively "slick" user interface. I believe that perception of
> slickness is partly because the iPhone emulated physical interfaces
> very well so it leveraged people's intuition about the physical world.
> It was delightfully intuitive.
One of the things Apple have always been very good at is thinking hard about user interfaces. What made the iPhone so good was that they emulated the right physical interfaces, so flipping a page when you're reading rather than pressing a button.
Jargon becomes jargon because it's useful to enough people, for occasionally rather odd definitions of "useful". In the case of lambda, it's shorter than "inline function definition"
and lambda calculus at least shows up on most CompSci courses.
Once it settles into a group, you use it because other members of the group will understand what you mean and might not understand if you rephrase it.
While I don't entirely disagree with you, if I had been responsible for inventing that bit of Python I would probably have gone with "lambda" too. It had been part of my vocabulary as a computer scientist long before I met it in a programming language. Whether it's a *good* choice or not... possibly reusing "def" would fit people's expectations better, or perhaps it would have caused more confusion. Who can tell?
I was an economist then, and I'm an economist still, but I met lambda
in 1977. Surely lambda has had that role in computer languages since
shortly before I was born.
I would guess anybody above a certain age
would reach for "lambda" first for a keyword to denote or define an
anonymous function. Not because of the lambda calculus, but because
of Lisp.
Maybe there's a better word than "regret". After all, It's
hard to see how you could prototype range better than "range([START,]
END, [STRIDE])", and the same might be true for "def [NAME] ([ARG0,]
...):".
Secure in the knowledge that Guido probably isn't reading this and won't
contradict me *wink* I'm going to try channelling him.
I think he would regret "def expressions", but not because of the range reason.
I think its because he likes the relatively strict demarcation between statements and expressions.
We have 4 statements that have a expression form:
if...else versus ternary if expressions;
for loops versus comprehensions;
(soon) = assignment versus := assignment expressions; and
def versus lambda.
Okay, let's read that.
hand = # we're assigning this to the name 'hand'
sorted( # calling the function named 'sorted'
cards, # positional argument, whatever's in the 'cards' variable
by= # keyword argument, what comes next is the 'by' argument
value[card.suit] # subscript 'value' with 'card.suit'
if card is not wild # yep
else max_value # so we have an alternative
with card # WAIT WAIT WAIT
Once you get to 'with card', you have to go back and completely
reinterpret everything prior to that as a function.
> Oh wait... Did I accidentally replace "key" with "by"? Huh... It seems to
> make more sense even though the jargon is a "key function"... Oops! ;)
I'm sure it would make even more sense if you wrote it this way:
hand = sorted(cards, by="suit")
That's how SQL works - you just name the column that you want to order
the results by. But if you think "by" is a better keyword here, start
explaining why your ordering is done with an anonymous function, not
with an attribute name.
JFTR, I wouldn't implement a deck of cards this way.
It implies that there is exactly one wild card, where many
decks of cards have at least two.
In English, "card is not wild" can
be interpreted as a membership check, but in Python, it is only an
identity check; you're capitalizing on false readability by using this
notation.
That right there is unacceptable. You should not have to know the
destination to understand what something fundamentally is.
You can't redefine language syntax based on the function being called.
I use decks of cards primarily for non-game
usage (for instance, teaching data structures and algorithms - cards
laid out on a table can represent a tree, heap, array, etc)
A deck containing four suits of thirteen
cards plus one joker would have 53 cards, which is a prime number;
printing 54 cards lets you lay them out as 9 by 6 on a sheet, so it's
easy to add a second joker. Some decks (I have an Alice in Wonderland
themed deck) have *four* jokers.
As such, the most logical way to do this would be as an attribute of
the card.
I have reservations about the name lambda. But there's a lot of
code out there that uses lambda, and I'd like that code to continue to
run.
My understanding is that you prefer
>>> EXPRESSION with IDEN
to
>>> lambda IDEN: EXPRESSION
How do you feel about this, as a means of defining an anonymous function?
>>> with IDEN: EXPRESSION
Now for a trick question. Consider
>>> fn = (lambda : EXPRESSION)
This produces a function that has zero parameters.
How would you write this, using 'with'. Would it be:
>>> fn = (EXPRESSION with)
I think this looks rather odd.
Python's parser is *deliberately* incapable of backtracking this far
in its definition of syntax.
You then said that it was the parameter "key" that told you that
this would be a function, which is also unacceptable in Python syntax.
So how do you intend to do this?
And you still haven't done anything to show that this is actually
better than "lambda card:"
I'm done.