Ask Your Question
0

flow control in sage notebooks?

asked 2019-04-14 21:00:24 +0100

stockh0lm gravatar image

I would love to insert a break or stop command into sage files, in order to absolutly stop further processing. The interpreter (?) should not die or exit, but rather pretent to be done with the notebook.

I looked through the sage reference and didnt find something similar. actually i didnt find anything on the whole flow control topic.

edit retag flag offensive close merge delete

Comments

You mentioned "sage files" so it's not clear: Do you mean like .sage scripts? Or a Jupyter notebook (that you're executing with "Run All Cells" or something)? In the latter case (which is nothing specific to Sage) there are several ways you could "pause" execution: Have a cell deliberate raise an exception. Put in a time.sleep() (if you just want a temporary delay), put in a call to input(), etc.

Iguananaut gravatar imageIguananaut ( 2019-04-15 15:42:59 +0100 )edit

i mean bla.sage scripts, that i execute like "sage bla.sage". Is that also called sage notebook? or is that something else?

stockh0lm gravatar imagestockh0lm ( 2019-04-15 15:48:39 +0100 )edit

A .sage script is just a script. Just code saved to a file line-by-line for convenience so that you don't have to manually re-enter it manually into an interactive prompt. A notebook is another beast entirely. Sage is just Python so anything you can do in Python you can do in a Sage script. What exactly are you trying to do and why? What does "Pretend to be done with the notebook" mean to you, if not exit?

Iguananaut gravatar imageIguananaut ( 2019-04-18 18:51:12 +0100 )edit

I use sage-shell-mode in emacs. I dont want to do an exit, because then i would need to reload the sage process every time. I currently use the "syntax error break method" which makes the sage interpreter stop when it encounters a syntax error I insert deliberately - that is somewhat ugly, because it gives me two lines of traceback in emacs and interesting stuff is pushed out of my window. for my rapid work flow i would like something that just stops processing of my buffer at a given point - and pretends it is done, without an error or traceback.

stockh0lm gravatar imagestockh0lm ( 2019-04-26 11:19:09 +0100 )edit

I don't know anything about emacs so that would probably be a sage-shell-mode issue if it exits the interpreter when you're not otherwise done using it.

Iguananaut gravatar imageIguananaut ( 2019-05-06 16:52:44 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-04-14 21:36:31 +0100

Emmanuel Charpentier gravatar image

As far as I can tell, there is no way to do this "cleanly" under program control : a notebook is not a way to program a system. However, there are a few things possible, at least in Jupyter notebooks (the old Sage notebook is unmaintained, unmaintainable and will die sooner or later : don't start new work with it, unless you need some specific feature such as multi-user access) :

* Go to a cell, and request evaluation of all cells above.

* Introduce a cell raising a runtime error (e.g. a syntax error, referencing an undefined variable, division by 0, und so weiter...)..

* Write a program. Notebook is a great way to jot down and test ideas quickly, not to polish up a paper.

For the latter, \LaTeX and Sagetex (or Pythontex (or org-babel)) are much more easy...

edit flag offensive delete link more

Comments

Apparently the actual question was something about using sage in emacs, and not the Jupyter Notebook. If any emacs users are out there they would likely need to be the ones to answer the question.

Iguananaut gravatar imageIguananaut ( 2019-05-06 16:54:09 +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

1 follower

Stats

Asked: 2019-04-14 21:00:24 +0100

Seen: 320 times

Last updated: Apr 14 '19