On Jan 13, 2016, at 12:15 , 'Martin R' via sage-devel <sage-devel@googlegroups.com> wrote:
> Hi there! > > I'm trying to understand inheritance. In formal_sum I find the following > code: > > class FormalSums(UniqueRepresentation, Module): > > Element = FormalSum > > def _element_constructor_(self, x, check=True, reduce=True): > > if isinstance(x, FormalSum): > P = x.parent() > if P is self: > return x > elif P == self: > return self.element_class(x._data, check=False, reduce=False, > parent=self) > else: > x = x._data > > I do not understand this: > http://doc.sagemath.org/html/en/reference/structure/sage/structure/unique_representation.html#sage.structure.unique_representation.UniqueRepresentation > gives me the impression that "P is self" and "P == self" should be the same > thing. Is my impression wrong or is the code above misleading? To understand the difference between ‘is’ and ‘==‘ may require some background in programming. Specifically, “a==b” evaluates to “True” if the objects ‘a’ and ‘b’ “evaluate to the same *value*”, while “a is b” evaluates to “True” if the objects ‘a’ and ‘b’ *are the same” (i.e., are located at the same locations in RAM). If that is not clear (and it need not be; it’s a kind of complicated issue in programming language design and implementation), do an internet search for something like “is vs == in python”. To answer your questions, your impression is not correct (but you are not alone), and the code is not misleading (making the rash assumption that it is correct, which I have not verified). HTH Justin -- Justin C. Walker, Curmudgeon at Large Director Institute for the Enhancement of the Director's income ----------- -- They said it couldn't be done, but sometimes, it doesn't work out that way. - Casey Stengel -- -- 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 sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.