Hi! When demonstrating stuff in class, I often want the variable to be an argument to a function:
def test_subs(f, a, x=x): print f(a) This works if f is a function. If f is not a function, Sage issues a DeprecationWarning (rightly, IMHO). So we could try this: def test_subs(f, a, x=x): print f(x=a) ...which sort of works, but not with a different variable: sage: f = t^2 + 2 sage: test_subs(f, 1, t) t^2 + 2 Another way to make it work with expressions is by dictionary substitution: def test_subs(f, a, x=x): print f({x:a}) ...and that now works with expressions, but not with functions: sage: f(t) = t^2 + 2 sage: test_subs(f, 1, t) ... TypeError: no canonical coercion from <type 'dict'> to Callable function ring with argument t I can fix this with a try/except block, but when discussing it with a much wiser colleague he pointed out that it made the learning curve rather steep for kids who can barely do calculus. Is there a smarter way to do substitution, so that a function doesn't have to worry about whether the input is an expression or an honest-to-goodness function? -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at https://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.