while i'm on the topic of sets, is the Set class intended to be immutable? 
this does seem to be the intent, since there is no method on the object 
itself which can be used to change its value. however,

In [58]: x=[1,2,3]

In [59]: s=Set(x)

In [60]: x[1]=5

In [61]: s
Out[61]: {1, 3, 5}


i propose that this is undesirable, and there is an easy fix, assuming 
any X for which X.is_finite() == True also has an iterator (and can 
therefore be converted to a python set). see patch below.
note: the second part of this patch assumes the patch in my previous email 
has been applied. if not, just use the first part of this patch.



# HG changeset patch
# User Kyle Schalm <[EMAIL PROTECTED]>>
# Date 1176453082 18000
# Node ID ce41e74d58b655aa854acba1e08a69fec9534cc6
# Parent  bca0cc86fd5e88dc21887c5d222c1fcfa71ae490
guard Set_object_enumerated against accidental change via underlying 
object

diff -r bca0cc86fd5e -r ce41e74d58b6 sage/sets/set.py
--- a/sage/sets/set.py  Fri Apr 13 03:07:17 2007 -0500
+++ b/sage/sets/set.py  Fri Apr 13 03:31:22 2007 -0500
@@ -55,8 +55,8 @@ def Set(X):
      if isinstance(X, Element):
          raise TypeError, "Element has no defined underlying set"
      try:
-        if isinstance(X, (list, tuple, set)) or X.is_finite():
-            return Set_object_enumerated(X)
+        if isinstance(X, (list, tuple, set, frozenset)) or X.is_finite():
+            return Set_object_enumerated(frozenset(X))
      except AttributeError:
          pass
      return Set_object(X)
@@ -527,11 +527,7 @@ class Set_object_enumerated(Set_object):
              sage: type(X)
              <class 'sage.sets.set.Set_object_enumerated'>
          """
-        try:
-            return self.__set
-        except AttributeError:
-            self.__set = frozenset(self.object())
-            return self.__set
+        return self.object()

      def __hash__(self):
          return hash(self.set())



--~--~---------~--~----~------------~-------~--~----~
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/
-~----------~----~----~----~------~----~------~--~---

Reply via email to