Ask Your Question
0

How do I get output from sage -c ?

asked 2010-09-03 12:02:17 +0100

kcrisman gravatar image

Please compare:

$ Downloads/sage-4.5.3.rc0/sage -c 'is_prime(991)'

$ Downloads/sage-4.5.3.rc0/sage -c 'print is_prime(991)'

True

Should sage -c also print to the standard output the result of the command? That would seem a lot more useful. Right now Sage has to get all fired up just to act as a once-off calculator. But maybe this is actually a feature, consistent with other programs that one can call in once-off fashion?

edit retag flag offensive close merge delete

Comments

What do you suggest as an alternative? Perhaps a "-p" flag? Perl has a flag to loop over stdin and do similar things. Please state constructive input, thanks. :)

ccanonc gravatar imageccanonc ( 2010-09-03 13:26:33 +0100 )edit

I'm not sure what you mean. I want to be able to just send a Sage command to Sage and get a result, without having a whole Sage session open up, and don't want to have to use the print argument (because I will always forget to do so). Why isn't printing the output the default behavior?

kcrisman gravatar imagekcrisman ( 2010-09-03 13:34:20 +0100 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2010-09-03 14:23:55 +0100

niles gravatar image

The most compelling reason for this behavior (if there is any) is probably that python does the same thing. There doesn't seem to be a way to get python to print its results either: see here.

So maybe you're suggesting adding a "calculator" option to sage, so that it will print its results, but is that actually faster than just starting sage? (That is, does sage get all fired up, but just in the background?). And, even better, maybe you're suggesting a "quickstart" option for sage, so that it just loads some very basic functionality and can do calculator-like tasks, but nothing fancy. But I bet that's a hard problem :)

edit flag offensive delete link more

Comments

No, I just don't want the Sage hanging around in the background. What is the point of `python -c`? Also, does `python - c command` need to have the command as a string, as seems to be the case for Sage? Not looking for calculator - I want fancy, but without the `sage:` prompt hanging out.

kcrisman gravatar imagekcrisman ( 2010-09-03 15:02:21 +0100 )edit

oh, well, I guess I don't really know what the point of `python -c` is; presumably execute some piece of code that's so simple it's not worth the trouble to put it in a separate file . . . maybe this could be useful to call from a shell script? Anyway, it does seem to require string argument too.

niles gravatar imageniles ( 2010-09-03 15:09:38 +0100 )edit

It's not the same as the "quickstart" option that Niles suggests, but with 'sage.misc.lazy_import' and ticket #8456, we'll be able to reduce Sage's overall startup time (cf. #8254).

Mitesh Patel gravatar imageMitesh Patel ( 2010-09-03 17:13:16 +0100 )edit

I think that a well-documented 'calculator' option would be good for this.

kcrisman gravatar imagekcrisman ( 2010-09-03 23:14:26 +0100 )edit

oh, it just occurred to me that you could write a shell function `psage` which takes a string as input, adds "print " to the front, and passes it to `sage -c`. This wouldn't work for every situation, but would be fine for 1-liners (which I guess is what you're looking for).

niles gravatar imageniles ( 2010-09-04 08:44:07 +0100 )edit
0

answered 2010-09-03 14:34:50 +0100

ccanonc gravatar image

This sounds to me like a duplicate of the following question:

http://ask.sagemath.org/question/72/c...

The question there is how to connect to a running server with a terminal interface, over ssh, or locally.

edit flag offensive delete link more

Comments

No, I'm not asking about that. I want to just start it, answer a question, and close it, all in one command.

kcrisman gravatar imagekcrisman ( 2010-09-03 14:59:36 +0100 )edit

kcrisman: That's fine, but then the startup-time is a separate question/complaint. Why not write a short program, then make the -c command run it (so it loops over all the numbers)?

ccanonc gravatar imageccanonc ( 2010-09-03 16:01:49 +0100 )edit

It's not the startup time I'm concerned with. The problem is that I don't know how to get the output of my short program (such as the very short program `factorial(20)` other than using `print`!

kcrisman gravatar imagekcrisman ( 2010-09-03 16:52:37 +0100 )edit

kcrisman: What's wrong with using print? It works...so this is a user-preference issue IMHO.

ccanonc gravatar imageccanonc ( 2010-09-03 16:55:16 +0100 )edit

But it's not obvious. I'm thinking of a new user (or an old one who forgets); if it says it's executing a command, you'd think you would get to see the output as well. At the very least `sage -help` should be more informative about this.

kcrisman gravatar imagekcrisman ( 2010-09-03 23:13:44 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2010-09-03 12:02:17 +0100

Seen: 888 times

Last updated: Sep 03 '10