"Pekka Karjalainen" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Python doesn't do any kind of tail recursion optimization by default
> because Guido has decided it shouldn't (at least so far). I'm sure it has
> been discussed in detail in Python development forums & lists, but
In article <[EMAIL PROTECTED]>,
Matteo wrote:
>This last approach could, at least theoretically, create an arbitrarily
>long list of polys, without overflowing any kind of stack. In practice,
>python does not seem to perform tail recursion optimizations, and conks
>out after makepolys(997) on my m
Josiah Manson wrote:
> In the following program I am trying to learn how to use functional
> programming aspects of python, but the following program will crash,
> claiming that the recursion depth is too great. I am attempting to make
> a list of polynomial functions such that poly[0](3) = 1, poly
In <[EMAIL PROTECTED]>, Tim Chase
wrote:
> My understanding is that the lambda-defined functions are not
> called until the actual application thereof, with the
>
> mypolys = make_polys(8)
> mypolys[5](2) #the lambda call happens here, no?
Yes, that's right.
> 's original statement
> I'm curious why the very first attempt to call p(3) doesn't bomb
> out with the NameError that "polys" wasn't defined before it even
> got to the point of attempting to call it.
In the first call, the 0th lambda function is evaluated, and it was
defined as the constant function 1. The functions
> Just to be a bit more explicit:
> In code like:
> def make_polys(n):
> """Make a list of polynomial functions up to order n."""
> p = lambda x: 1
> polys = [p]
> for i in range(n):
> polys.append(lambda x: polys[i](x)*x)
> i=3
>
> Th
> The `i` is the problem. It's not evaluated when the lambda *definition*
> is executed but when the lambda function is called. And then `i` is
> always == `n`. You have to explicitly bind it as default value in the
> lambda definition:
>
> polys.append(lambda x, i=i: polys[i](x)*x
Fredrik Lundh wrote:
> Tim Chase wrote:
>>> The `i` is the problem. It's not evaluated when the lambda
>>> *definition* is executed but when the lambda function is
>>> called. And then `i` is always == `n`. You have to
>>> explicitly bind it as default value in the lambda definition:
>>>
>>>
Tim Chase wrote:
>> The `i` is the problem. It's not evaluated when the lambda
>> *definition* is executed but when the lambda function is
>> called. And then `i` is always == `n`. You have to
>> explicitly bind it as default value in the lambda definition:
>>
>> polys.append(lambda x, i=i
> The `i` is the problem. It's not evaluated when the lambda
> *definition* is executed but when the lambda function is
> called. And then `i` is always == `n`. You have to
> explicitly bind it as default value in the lambda definition:
>
> polys.append(lambda x, i=i: polys[i](x)*x)
>
>
In <[EMAIL PROTECTED]>, Josiah Manson
wrote:
> def make_polys(n):
> """Make a list of polynomial functions up to order n.
> """
> p = lambda x: 1
> polys = [p]
>
> for i in range(n):
> polys.append(lambda x: polys[i](x)*x)
The `i` is the problem. It's
11 matches
Mail list logo