On Sat, Dec 25, 2010 at 5:13 PM, Justin C. Walker <[email protected]> wrote:
> Hi, all,
>
> A couple of questions regarding mutabilty:
>
> First, I noticed a comment at the beginning of quadratic_forms/binary_qf.py 
> from Stein:  "make immutable".  Can anyone (William?) elaborate on what that 
> means?  They don't currently (e.g., sage-4.6.1-a3) seem to be very immutable:
> sage: q1=BinaryQF((-2,0,1))
> sage: q1._a=3
> sage: q1
>  3*x^2 + y^2

sage: q1.discriminant()
8

It's generally unsafe to set underscore attributes directly, as it's
unclear what may be cached or what invariants may need to be

> Second, on this note, is there anywhere written a discussion of what 
> immutability means in Python?  A quick check of the doc (for Python 2.[67]) 
> doesn't seem to lead anywhere.

Immutability is just a matter of convention.

> For example, can one declare a "class" immutable and have it stick, or is 
> there extra work involved to ride herd on all "instance variables" that one 
> would want to be unchangeable directly?

As mentioned, one can use __setattr__. It's easy from Cython to make a
class immutable from Python as well.

- Robert

-- 
To post to this group, send an email to [email protected]
To unsubscribe from this group, send an email to 
[email protected]
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to