<div dir="ltr"><br><div class="gmail_quote">On Sun, Oct 5, 2008 at 10:16 PM, Carl Johnson <span dir="ltr"><<a href="mailto:carl@carlsensei.com" target="_blank">carl@carlsensei.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>On 2008/10/05, at 6:47 pm, Bruce Leban wrote:<br>
<br>
</div><div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
i = 0<br>
def f():<br>
i += 1<br>
return lambda: i<br>
<br>
</blockquote>
<br></div>
I'm not sure I see what you're getting at. In Python 2.6 and 3.0rc1 this raises "UnboundLocalError: local variable 'i' referenced before assignment." If you want to do what it looks like you want to do, you have to use "nonlocal i" or "global i".<div>
<br>
</div></blockquote><div><br>Yup. I wrote that a bit too quickly. <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div>
<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
i = 0<br>
def f():<br>
i += 1<br>
return lambda: immanentize i<br>
<br>
This will return lambda: 1, then lambda: 2, etc. right? No. It returns lambda: 0, lambda: 0, etc.<br>
</blockquote>
<br></div><div>
To me, it is transparently clear that this will return lambda: 0 every time. That's what immanentization does. If you want lambda: 1, etc., use "nonlocal i".<br>
<br></div></blockquote></div><br>Consider this:<br><br>i = 0<br>def f():<br> global i<br> i += 1<br> return lambda: immanentize 1<br><br>when does immanentize get evaluated? when f is defined or when the lambda is evaluated? From what you wrote, it sounds like you think it's evaluated when f is defined. OK, so how do I get the equivalent of:<br>
<br>def f():<br> global i<br> i += 1<br> lambda i=i: i<br><br>using immanentize?<br>
</div>