On Tue, Nov 4, 2008 at 3:02 AM, Brian Granger <[EMAIL PROTECTED]> wrote:
>
>> All Basic classes are immutable. It shows up in a way that once you
>> create an instance of any Basic subclass, it represents what you put
>> there a the creation time. If it changes later, it's a bug.
>>
>> Example: x+x calls Add.__new__(x, x), which does canonicalization and
>> creates an instance of Mul(2, x).  Once Mul(2, x) is created, it never
>> changes.
>>
>> It is however useful to have mutable Matrices. That's why they don't
>> inherit from Basic, because if they did, we get in trouble once you
>> start using Matrices in expressions.
>>
>> If something is still not clear, let's discuss it.
>
> This makes sense.  But, clearly, there are some aspects of Basic that
> are not tied to Basic being mutable:
>
> * the is_Function, is_Add, etc. attributes.
> * I am sure many methods are as well.
>
> One problem that I am running into is when I get a Sympy related
> object, I can't automatically assume that it has the methods and
> attributes.  Thus I have to write code like:
>
> if isinstance(o, Basic):
>  if o.is_Function
> ....
>
> having to call isinstance makes the speed advantage of the is_* method
> irrelevant.  The speed advantage is only there if _all_ objects
> related to Sympy have them.
>
> Thus, I think that the _parts_ of Basic that don't make assumptions
> about mutability should be separated out into a different class like
> ImmutableBasic.  Then classes like Matrix will have all those extra
> methods.

That makes sense to me. But where did you encounter this problem? E.g.
which of your code needs to accept both matrices and Basic objects?
I'd like to see a broader context for this. We can also take the
approach of Matrices (or any Basic subclass) of being mutable only to
the point when the __hash__ method is called (or the object is printed
or stored in other classes), then it will freeze and become immutable.

Ondrej

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

Reply via email to