The lambda has it's own local namespace. It searches in the global namespace only if it does not find the variable in the local namespace. As the dummy variable is introduced it creates the key 'i' in the local dictionary, so you can be sure that it won't touch upon any 'i's in the global.
On 1 May 2012 11:53, smichr <[email protected]> wrote: > I'm trying to wrap an expression into a lambda and notice that the dummy > variable of the lambda doesn't match with the variable of the expression. Am > I doing this right? > > Here, the lambda's i is not the same as the i in the expression I send: >>>> def f(fi): > ... return lambda i: fi > ... >>>> f(i+1)(1) > i + 1 > > Here I remap the expression's i to the lambda's i >>>> def f(fi): > ... return lambda i: fi.subs(fi.free_symbols.pop(), i) > ... >>>> f(i+1)(1) > 2 > > /c > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/sympy/-/GdT_8xFkBDUJ. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/sympy?hl=en. -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
