Re: [sage-devel] Recursive function and local variable

2013-06-29 Thread Travis Scrimshaw
Hey Matthieu, The problem is you are returning the *original* *modified* object you passed in, not a new object like you seem to be expecting. Just make a copy of l before making any changes to it. Since the function is straight forward, I'd recommend just making it iterative using a while lo

Re: [sage-devel] Recursive function and local variable

2013-06-29 Thread Matthieu Deneufchâtel
I might have misunderstood your suggestion, but I don't think that it is the solution (I tried it and I get the same problem). My problem is that when I try the same expansion several times in a row, the list is not cleared after each call and thus the coefficients are false: sage: M=FreeMonoid(2

Re: [sage-devel] Recursive function and local variable

2013-06-29 Thread Mike Hansen
I'm guessing this is just due to you using dict() in the function definition. See http://effbot.org/zone/default-values.htm . If you replace it with None do something like if l is None: l = {} at the beginning of the function, then things should be okay. --Mike --Mike On Sat, Jun 29, 201

[sage-devel] Recursive function and local variable

2013-06-29 Thread Matthieu Deneufchâtel
In a recursive function, I use a dictionary (which contains the elements of the expansion of the argument on another basis). Since each call to the function needs the dictionary, I don't want the user to be forced to put the dictionary as an argument (i.e. I want him to call to_pbw(elem) instead