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, 2013 at 11:29 AM, Matthieu Deneufchâtel
<matthieudeneu...@yahoo.fr> wrote:
> 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 of
> to_pbw(elem,{})). But I get a little confused between local and global
> variables with the code below since the dictionary is not emptied when
> needed (my function as the expected behavior only when I call
> to_pbw(elem,{})).
>
> Could anyone help me (provided my question is not unclear)?
> Matthieu
>
> def to_pbw(f,l=dict()):
>     from sage.combinat.words.finite_word import to_monoid_element
>     if f!= 0 * f.parent().one():
>         support = [to_word(i[1]) for i in list(f)]
>         min=support[0]
>         if len(support) > 1:
>             for word in support[1:len(support)-1]:
>                 if min.lex_less(word):
>                     min = word
>         coeff = list(f)[support.index(min)][0]
>         if min not in l.keys():
>             l[min]=coeff
>         else:
>             l[min] += coeff
>         remainder = f - coeff * pbw_element(to_monoid_element(min))
>         return to_pbw(remainder,l)
>     return l
>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-devel+unsubscr...@googlegroups.com.
> To post to this group, send email to sage-devel@googlegroups.com.
> Visit this group at http://groups.google.com/group/sage-devel.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to