On 7/4/11 9:07 PM, kcrisman wrote:

f() # gives 4

f(3) # gives 9

The original function is left intact, so you can just call it.

Hmm, I didn't realize that would work so easily.  I must have been so
blown away by the interact return value that it didn't occur to me to
try this :)

You should pay better attention to the PREP tutorials ;). It's in the first few lines of the interact one.



Harder example:

@interact
def _(f=x^2, a=(3,[2..10]), c = (2,6)):
       g(x)=f+a
       show(plot(g,(x,-c,c)))

This is harder since when the interact is run, ``a`` is a single number
(by the autoguessing), but when the function itself is run, ``a`` is a
tuple.  Same problem for c.  Maybe we should actually change the
function that is returned to substitute in the default arguments,
instead of just returning the function.  That would be doable and
reasonable, I think.

That would be very nice, since then the function one gets is actually
more usable, if one needed that.

But is there any *current* way to get at this?  My guess is no,
because the code for the "autoguessing", if that was what I was
looking at, is fairly detailed to cover all the cases.   But it would
be really useful.

There's hacks that you could do (call the autoguessing function yourself, then call the default method on each control returned)...how desperate are you?

I looked at this for a bit. Does anyone know if it's all right to just replace g.func_defaults? Or are there problems with just outright setting that tuple?

Thanks,

Jason

--
To post to this group, send an email to [email protected]
To unsubscribe from this group, send an email to 
[email protected]
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to