On 4/13/07, Kyle Schalm <[EMAIL PROTECTED]> wrote: > > >> you mean something like > >> > >> s = Set([1,2,3],immutable=True) > >> > >> ? that would work for me. > > > > Yes, exactly. Also, > > s = Set([1,2,3]) > > then > > s.set_immutable() > > when would someone want to change a set from mutable to immutable?
You create a set by doing lots of operations on it, so it has to be mutable. Then you record the set as an attribute of a class. Then you have a method to return that set -- you don't want the code that calls the method to be able to change the set. E.g., maybe your set is the primes of bad reduction for an elliptic curve, which you compute as you go. Then you do self.__bad_primes = that set. If you return self.__bad_primes, and don't make it immutable, then users could mess with that set. This is a very common sort of situation in mathematical algorithms. > i don't have a problem with it, just wondering. this only goes one way, i > hope -- that is, it won't be allowed to change back from immutable to > mutable, right? (that would be bad IMHO.) Yes. There is no way to make something immutable back to being mutable, beyond sneaky __ methods. > > I agree. Removing setitem, as I think you did, is a good > > idea. The python builtin set doesn't have it. > > i didn't -- it was already gone (or never there). > however, something like > > s.replace(a,b) > > which is equivalent to > > s.remove(a) > s.add(b) > > might make sense -- i don't want to add features no one needs; what do > you think? Don't add features nobody needs or request. > while i'm at it, what about these additional methods, which exist in > python sets? they look useful: > > s.issubset(t) s <= t test whether every element in s is in > t > s.issuperset(t) s >= t test whether every element in t is in > s > > s.update(t) s |= t update set s, adding elements > from t > s.intersection_update(t) s &= t update set s, keeping only > elements found in both s and t > s.difference_update(t) s -= t update set s, removing > elements found in t > s.symmetric_difference_update(t) s ^= t update set s, keeping only > elements found in either s or t but not in both > > although my preference would be change the name of update to union_update. Sure, add them. You're right -- union_update is a good choice of name. > also, what about: > > * making + and += synonyms for | and |= ? > * a "powerset" method? Sounds good if the precedence is correct. William --~--~---------~--~----~------------~-------~--~----~ 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/sage-devel URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/ -~----------~----~----~----~------~----~------~--~---