On Dec 2, 12:12 pm, Nick Alexander <ncalexan...@gmail.com> wrote: > > In the Python environment, if someone detects an error in a Python > > function FF, then the function can be replaced in the run-time > > environment, e.g. at a command line by: > > This is technically true but in practice not useful. Most Python code > is not a top-level function; it is a class member function. It is > possible to update a member function (try it!), but not a Cython class > member function. And even when you do update a member function, there > is in general no way to update existing instances of the class, > meaning that your mis-behaving object is not fixed.
It is possible to change the class definition at Python, and have all instantiated objects updated: sage: G = SymmetricGroup(5); G Symmetric group of order 5! as a permutation group sage: G.is_finite() True sage: SymmetricGroup.is_finite = lambda x: False sage: G.is_finite() False I've not found this particularly useful myself, though replacing a member function on a particular instance can be handy (e.g. telling Sage that Z/nZ is a field without doing a primality test on n). This is not possible for compiled C extensions though, which is one disadvantage of using Cython. > Various modules > (reload, xreload) try to address this, but Python's design works > strongly against this. For example, even if you update top-level > function, any module that already imported the old version retains the > old version. Smalltalk and Lisp (including CLOS?) have supported this > feature since their inception. Ruby too. Depends on how the import was done. If I import math, then refer to math.sin, a lookup happens every time and this can be updated. If, however, I do "from math import sin" this is an assignment "import math; sin = math.sin" and updating the math module does not remove the handle to the original function. - Robert -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org