On Mar 11, 2009, at 3:07 PM, Florent Hivert wrote: > Dear Carl, > >> The paragraph you quoted was part of a very rough proposal for a way >> that Sage's coercion might be changed in the future; it's definitely >> not how it works now. > > My apologies for missing this. > >> Also, the way coercion is implemented now, int(2) does have a parent; >> it's just not available at the .parent() method: >> >> sage: parent(int(2)) >> <type 'int'> > > Hum !!! Is there a place where we can find the specification and if > not a > description of this parent mechanism. I'm pretty sure that if one > grep into > the code on can find at least some code that use those three following > different ways to ask for the parent of an object: > 1) x.parent()
A method on elements, returning x._parent. > 2) x._parent The actual C attribute that stores the Parent object (much faster access from C code than calling a Python function). > 3) parent(x) If x is an Element, return x._parent, else punt and return type(x) which can at least be somewhat reasoned with. > In the end, there can be only one ;-) If x is an Element, they should all agree. The latter is useful when x is not an element, and one doesn't want to worry about attribute errors. It's also a convenient functional notation, the same way we allow sin(x), sqrt(x), etc. as well as x.sin(), x.sqrt(), etc. > I though the first one should be used and I realized it cannot be > used for > int, whence my e-mail. As far as a understood 2) is an > implementation details > and should not be called directly. I've never seen 3). Note that > I'm quite new > to Sage and I haven read the entire source right now :-) Hope this clears things up a bit. - Robert --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to sage-devel-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---