Le 11/08/2021 à 08:09, Nils Bruin a écrit :
On Tuesday, 10 August 2021 at 21:10:43 UTC-7 [email protected] wrote:

Just to add to all the ideas, what about using a with statement, eg:

with Immutable():
     # the things Nils wishes were immutable are immutable by default here

That would basically move the "unless otherwise instructed, new elements
are constructed mutable/immutable" from a flag on the parent to global
state. On the plus side, we don't need to duplicate parents or (worse!)
have a toggle on parents that should be immutable. On the minus side, we
now have truly global state that governs this behaviour. The "with" context
manager hides it a little bit, but the implementation would control the
toggle (globally!) based on time, not scope (because there is no such thing
in python).
In fact for my scenario (an interactive session) I would not be able to
write in a "with Immutable" environment, but that's fine: you can just take
the context manager without the "with" and call the "__enter__" on it.

A big plus: since we'll have the option to flick between the two different
default behaviours, perhaps it gives a gentler route towards "default
immutable", where mutable vectors can be had, but need to be explicitly
requested. Which is probably the better place for the long-time future.

So while global state is generally to be avoided, perhaps in this situation
it is an instrument that can get us ahead eventually.

Very tempting to use environment. It could even be refined to

with Immutable(V):
    # elements of V are now immutable by default

But even then, some code elsewhere in sage might use the very same
parent (eg ZZ^2 is unique). This parent might want to deal with
mutable vectors. So toggling options on the parent does not look
like an option to me.

--
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/91c95713-d57b-f4fb-20a9-2c64148ee977%40gmail.com.

Reply via email to