On 5/8/14, 11:01, William Stein wrote:
@interact
def foo(functions=[sin(x)], f=sin(x)):
show(plot(foo.functions))
del foo.functions
foo.functions = [f(x=x), f(x=x^2), f(x=x^3)]
Here's a corresponding one working in the cell server:
http://sagecell.sagemath.org/?q=ribyjg
@interact
def foo(self, functions=[sin(x)], f=sin(x)):
show(plot(functions))
del self.functions
self.functions = [f(x=x), f(x=x^2), f(x=x^3)]
Here are a few differences I noticed:
1. Instead of making foo available in the namespace of the function
(thereby possibly masking out a global variable foo), we follow the
python object method convention of passing a self argument in as the
first argument of the function. If the first argument of an interact
function does not have a default value, it is considered a 'self'
argument and is assigned a object that represents the interact itself.
This has its own problems, and I'd be interested in people weighing in
on each approach.
2. William has show(plot(foo.functions)). For the cell server,
self.functions is the *index* into the list of functions, rather than
the actual function. Of course, the actual function is available via
the normal interact way of just using the parameter name, functions.
This makes it less ambiguous to set the value of the selector---you just
set an index, rather than setting a value and then having sage try to
guess from the value what the index is.
3. This doesn't affect the above example, but it seems that when you
have functions=[single value], the cell server interacts creates a
single button, rather than a selector. This has implications for what
self.functions returns. I'm not sure if this is a backwards
compatibility thing or a bug in our implementation. It's in the code
that automagically creates controls based on default values.
4. When you click on a selector button that is already selected, the
cell server ignores the click (since it's already selected), while the
cloud processes the click as a new selection.
Thanks,
Jason
--
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 http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.