New assignmens ...

Avi Gross avigross at verizon.net
Mon Oct 25 19:16:30 EDT 2021


Stefan,

Yes, I often pass even fairly trivial functions like "add" or "+" or
whatever the language makes me say, to other functions in various forms of
functional programing. My point is that my example may seem trivial and not
necessary as an EXAMPLE of the greater point that may be easier to
understand than something complex. A sum() is often a generalization  of
adding two things by allowing a second addition to the sub-sum and so on.
But in a straightforward program where I am asking to add exactly two
things, few would use sum(a,b) versus just a+b. On the other hand, in
agreement with you, if I have two vectors or matrices or some other such
data holder and I want to add each position to a corresponding position,
then some kind of call to a function where I pass the two objects and the
name of a function that adds two things, is a decent way to go. But it need
not be a souped-up generalized_sum() function when a simple one will do and
be faster when invoked so many times.

And note often what is used is a temporary lambda anonymous function that
may look like \(x,y) x+y ... or whatever syntax your language uses.


-----Original Message-----
From: Python-list <python-list-bounces+avigross=verizon.net at python.org> On
Behalf Of Stefan Ram
Sent: Monday, October 25, 2021 12:57 PM
To: python-list at python.org
Subject: Re: New assignmens ...

"Avi Gross" <avigross at verizon.net> writes:
>Now, yes, nobody needs a function to just add two numbers.

  If one uses a framework like "functools.reduce", the only
  way to reduce an iterable to its sum, is to do just that:
  Write a function to add two numbers.

  Of course, one can circumvent "functools.reduce" (or use
  "operator.add"), but in other cases there are frameworks
  that need to be used and where one sometimes does need to
  write functions (callbacks) as simple as "lambda: None".


-- 
https://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list