On Jun 15, 2009, at 7:57 AM, Jason Bandlow wrote: > Robert Bradshaw wrote: >> On Jun 9, 2009, at 9:47 AM, Jason Bandlow wrote: >> >>>> On Jun 9, 2009, at 8:29 AM, Jason Bandlow wrote: >>>> >>>>> Hi, >>>>> >>>>> I ran across the following behavior in sage-3.4.1 and sage-4.0 (I >>>>> don't >>>>> have 4.0.1 yet), and I find it fairly disturbing. >>>>> >>>>> sage: d = {'a': 1} # Create some object >>>>> sage: d >>>>> {'a': 1} >>>>> sage: type(d) = type({}) # Attempt to check the type but >>>>> # foolishly use = instead of == >>>>> >>>>> TypeError: cannot coerce type '<type 'type'>' into a >>>>> SymbolicExpression. # An error is expected >>>>> >>>>> sage: d # But now my data is gone! >>>>> d >>>>> sage: type(d) # Replaced by a symbolic variable >>>>> <class 'sage.calculus.calculus.SymbolicVariable'> >>> Robert Bradshaw wrote: >>>> This isn't a coercion issue, it's because of how functions are >>>> defined in Sage using the "f(x) = expr" notation using the >>>> preparser. >>>> I think that's too useful to get rid of. We could special case a >>>> warning for "type(x) = ..." but I'm not sure if that's the best >>>> idea. >>> Interesting! This means the problem is worse than I thought. >>> Anytime we >>> have data 'd' and 'e' and a function 'f', doing >>> >>> sage: f(d) = e # Instead of f(d) == e >>> >>> will raise a TypeError and replace 'd' with a symbolic variable. >>> Fortunately, though, >>> >>> sage: if f(d) = e: # The usual reason to check equality >>> >>> raises a SyntaxError first, so maybe this problem isn't so serious. >> >> Yes, I think it's fairly rare to want to do this. Probably should be >> added to an FAQ somewhere at least, as it's a surprising and subtle >> side effect. > > First of all, thanks very much for the explanations, Robert. Is > there a > particular FAQ where I could add a brief description of this?
Here's a good a place as any: http://wiki.sagemath.org/faq - 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 -~----------~----~----~----~------~----~------~--~---