Alex,
I'm not (yet) an experienced sage user, but I have some experience in
what you are trying to do,
I also tried to write scripts which can be started from the normal
shell (with "#!/usr/bin/env sage-python" as a first line, note that
sage-python just refers to the python installation that comes with
sage) as well as from the sage prompt by
sage: load"script.sage"
Doing this bears some bitfalls, e.g. note that there are different
number types, even for integers, there are the sage 'Integer' and the
python 'int' and 'long' types, so if you write a script with a line
like
a = 3/5
print a
and run it from the shell by
$ ./script.sage
it prints out 0 because '3' and '5' are treated as python int's and
not as sage Integer's, so the operator / refers to the python int
division which is defined to be an int as well, of course this is not
appropriate in an CAS, if you run the same script from the sage prompt
sage: load "script.sage" it prints out
3/5
and this result is of type Rational (a sage type, you can prove this
by typing "type(_)" at the sage prompt), because sage first wraps this
line to
a = Integer(3)/Integer(5)
and stores it in script.py and the runs this script through python,
here / refers to sage division (i.e. division of objects of type
Integer).
This is a drawback of the genious approach to use python as is, it's
confusing for beginners, as a Java dev you should be familiar with
operator overloading, in this case 3/5 does not has to be the same as
3/5.
So if you want your script to behave the same in both cases you have
to write
a = Integer(3)/Integer(5)
which then wraps to
a = Integer(Integer(3))/Integer(Integer(5))
if you run it from the sage prompt, that's actually is no problem,
just looks stupid..(maybe a performance issue?)
you have the same issue with the operator "^" which normally should
refer to exponentiation, but in python means the bitwise operator
"xor", exponentiation in python is done by "**", e.g. 2**5, in sage
you can use both 2^5 as well as 2**5, so in scripts which you want to
run from both, the shell and sage, you have to write 2**5.
As far as I know these are the only to cases to consider, in the sage
tutorial in section 5 (programing) you can read something about this
topics ....
Another drawback is as far as I experienced that from a normal script
you can't load and compile files with a .spyx ending (tutorial section
5.2 "creating compiled code") by inserting the line
load "file.spyx"
into your script
I hope this helps a bit,...
Georg

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to