John Cremona
2008/10/30 kcrisman <kcri...@gmail.com>:
I think the problem in the above is the question mark, not the
apostrophe. Removing the question mark makes the error go away for me.
Jason
Coming in late, but if this is literally what your example is, I think
the problem is the "f(x)=x^3". Can you do that?
If I try this
def foo(x):
f(x) = x^3
return f(x)
on 3.2.alpha0, without any doctstring, it blows up with
TypeError: Must construct a function with a tuple (or list) of
SymbolicVariables.
when I try to run it. If I add a docstring with """, it blows up the
same way. If I add a docstring with ''', it blows up with the syntax
error. Likewise, if I try this with "sage -python", I get the syntax
error.
Also, I tried this:
def foo(x):
x = x^2
return x
If I put in a docstring with """, foo(3) returns 9; with ''', foo(3)
returns 1 !
It seems that the ''' docstring causes the definition to bypass Sage,
while with the """ docstring, the definition is handled by Sage.
Is that possible?
Justin
--
Justin C. Walker, Curmudgeon at Large
Institute for the Absorption of Federal Funds
-----------
Like the ski resort full of girls hunting for husbands
and husbands hunting for girls, the situation is not
as symmetrical as it might seem.
- Alan MacKay
--
I meant to say in the discussion below that if your docstring is like
'''
That's all folks
...
you see the "bypass Sage" behavior, while the same string with """
gives you expected behavior.
So perhaps two problems:
- parser gets confused with too many single quotes (Sage parser
problem)
- can't assign to a function (language definition problem)
Does Sage permit "f(x) = x^3"? Python doesn't, I think.
Justin
If it weren't for carbon-14, I wouldn't date at all.
-----------
For the record, sagenb.org is nearly back. I configured a virtual
machine, put all the sagenb.org worksheets in it, got it a static
ip address on the network, etc. Everything worked locally, but
there was some nontrivial problem probably with the university's
local firewall or other networking configuration, which I still have
to resolve. So with luck sagenb.org will be back very soon.
Also, having it run in its own dedicated isolated virtual machine is
very nice, since I can tell exactly how much resources it is using
at any given time, which will be very helpful for debugging.
> However, I did try it on our
> departmental server (which is 3.0.4, I think) and it also blew up.
>
> Sample function which causes problems:
>
> sage: def plot_or_not():
> ....: '''
> ....: What's up with this? x^3
> ....: '''
> ....: f(x)=x^3
> ------------------------------------------------------------
> File "<ipython console>", line 5
> SyntaxError: can't assign to function call (<ipython console>, line 5)
>
> Experimentation reveals that the apostrophe is causing the trouble.
> As you can see, I now have had time to try this in the console, as
> well as the other problems on the linked worksheet, so I'm baffled.
>
> I hope it's not my architecture - PPC OSX.4.
>
> - kcrisman
> >
>
--
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org
>
>
>
>> Coming in late, but if this is literally what your example is, I
>> think
>> the problem is the "f(x)=x^3". Can you do that?
>>
>> If I try this
>>
>> def foo(x):
>> f(x) = x^3
>> return f(x)
>>
>> on 3.2.alpha0, without any doctstring, it blows up with
>
>
> Thanks for your thoughts. Interesting, because I don't have any
> problems with that! In fact, I think your problem there is that you
> have x as both the input and the variable in your definition. E.g.,
> your example blows up for me too, but I have no problems with the
> following:
[snip]
> It sounds like there are several interesting things developing out of
> this thread!
Yup. I was a bit too focused on the quote mark issues :-}
Removing the quotes, as well as the reuse of formal variables :-},
from the picture makes things a bit clearer.
It does look like there's a confusion arising in the parser when too
many quotes intrude...FWIW, if I use two 's in the doc string, things
work correctly (or, at least, as expected) :-}
Justin
--
Justin C. Walker, Curmudgeon-At-Large
Institute for the Absorption of Federal Funds
--------
Men are from Earth.
Women are from Earth.
Deal with it.
--------
Can you make a trac ticket with the above info? It should be enough to
make it "easy" for somebody to fix the problem, which is surely a bug
in the Sage preparser (and is surely my fault).
-- William