Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

sage script multiline parameter parsed error #77

Closed
ghost opened this issue Jun 19, 2017 · 2 comments
Closed

sage script multiline parameter parsed error #77

ghost opened this issue Jun 19, 2017 · 2 comments

Comments

@ghost
Copy link

ghost commented Jun 19, 2017

SageMath version 7.6

for example, I have this in file x.sage:

#!/usr/bin/sage
fx(x)=piecewise([[(-1,2),2*x+4], \
        [(2,4), 2*x^2-4*x]])

but sage x.sage send error like this

  File "x.sage.py", line 7
    __tmp__=var("x"); fx = symbolic_expression(piecewise([[(-_sage_const_1 ,_sage_const_2 ),_sage_const_2 *x+_sage_const_4 ],  * BackslashOperator() * ).function(x)
                                                                                                                               ^
SyntaxError: invalid syntax

while I can just copy the code and paste in the sage shell, it works of course.
but for the script, I have no way to make it work, the preparser only deal with a single line and don't know the line continue mark.
And I'm extremely wondering why the script doesn't work like just paste the content line by line to the sage shell, it's called sage script but it doesn't works like a script.
This can be done just by parsing the original line to the sage shell, which also makes it for sure that the script works really like a script.

@jdemeyer
Copy link
Contributor

This is indeed a known issue with the Sage preparser. I guess it's better to write everything on 1 line.

Alternatively, you can first create an expression and then turn it into a function:

var('x')
a = piecewise([[(-1,2),2*x+4], \
        [(2,4), 2*x^2-4*x]])
fx(x) = a

@ghost
Copy link
Author

ghost commented Jun 24, 2017

thanks a lot! that's an acceptable solution, indeed

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants