> 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. Still, it seems like it should be possible for the preparser to check whether f(d) evaluates to something (in which case, the assignment is going to fail anyway) before it makes the argument(s) symbolic variables. But maybe there are subtleties I'm not thinking of. -Jason --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---