On 3/25/2014 8:12 PM, Steven D'Aprano wrote:
On Tue, 25 Mar 2014 19:55:39 -0400, Terry Reedy wrote:
On 3/25/2014 11:18 AM, Steven D'Aprano wrote:
The thing is, we can't just create a ∑ function, because it doesn't
work the way the summation operator works. The problem is that we would
want syntactic support, so we could write something like this:
p = 2
∑(n, 1, 10, n**p)
Of course we can. If we do not insist on separating the dummy name from
the expression that contains it. this works.
def sigma(low, high, func):
sum = 0
for i in range(low, high+1):
sum += func(i)
return sum
There is no expression there. There is a function.
You cannot pass an expression to a function in Python,
One passes an unquoted expression in code by quoting it with either
lambda, paired quote marks (Lisp used a single '), or using it in a form
that implicitly quotes it (that includes def statements). Unquoted
expressions in statements ultimately get passed to an internal functions.
> not in the sense I am talking about,
well, if you eliminate all the possibilities ...
> because expressions are not first-class objects.
The concept is not a class, and the Python stdlib does not have an
expression class. But people have written classes to represent the
concept. I used existing classes instead.
Expressions are not (normally) mathematical objects either.
(An exception is rewriting theory, or other theories, where strings
representing expressions or WFFs (well-formed formulas) are the only
objects.) Mathematicians quote expression strings by context or
positiion. The sigma form is one of many examples.
--
Terry Jan Reedy
--
https://mail.python.org/mailman/listinfo/python-list