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. -- 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/7962aca1-ecb5-4a6f-b128-435195622857n%40googlegroups.com.
