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.
- Robert
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'>
>
> This is not 'dictionary' specific; the same problem of data loss
> occurs
> with any object at all.
>
> sage: type(Integer) = type(2) # Admittedly a silly thing to do...
> TypeError: ...
> sage: 1
> DeprecationWarning: Substitution using function-call syntax and
> unnamed arguments is deprecated and will be removed from a future
> release of Sage; you can use named arguments instead, like
> EXPR(x=..., y=...)
>
>
> My feeling is that coercion is being a little too aggressive here. I
> understand that coercion sees the '=' and tries its best to make sense
> out of the expression, but I would hope that when it fails, nothing in
> the expression would be changed.
>
> Best,
> Jason Bandlow
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---