Referring to previous results

24 views
Skip to first unread message

Ingo Dahn

unread,
Apr 11, 2017, 4:13:28 PM4/11/17
to sage-cell
From the net I got that the result of the previous computation can be referred to as _. But if I try to use it in SageCell like in
1+2
_+5
I get an error. What is the correct way to refer to previous results?

Andrey Novoseltsev

unread,
Apr 11, 2017, 6:44:07 PM4/11/17
to sage-cell

I never used or saw _ used in SageMathCell. There is a question of what "previous computation" is. Since I am used to SageNB, for me previous computation is the result of the previous cell, which does not make much sense when there is only one cell ;-)

I don't think that SageMathCell has any special treatment for _ on its own, so if it does or does not work, it is due to Sage/IPython/Jupyter/etc handing actual code and output. So - if things worked before and got broken I'll try to fix them, but if they never worked I claim that it is by design and should not be impemented.

Rob Beezer

unread,
Apr 11, 2017, 6:53:48 PM4/11/17
to sage...@googlegroups.com
Maybe it is a *convention* that "_" is the previous result.

"_" is a legitimate variable name in Python, so it is sometimes used for results
you don't really intend to keep.

The following produces 8 in the Sage Cell:

_ = 1 + 2
_ + 5

Rob
> --
> You received this message because you are subscribed to the Google Groups
> "sage-cell" group.
> To unsubscribe from this group and stop receiving emails from it, send an email
> to sage-cell+...@googlegroups.com
> <mailto:sage-cell+...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sage-cell/3f6cebdb-073f-4ec6-ac5c-b73d637bf8c7%40googlegroups.com
> <https://groups.google.com/d/msgid/sage-cell/3f6cebdb-073f-4ec6-ac5c-b73d637bf8c7%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Andrey Novoseltsev

unread,
Apr 11, 2017, 7:00:20 PM4/11/17
to sage-cell, bee...@ups.edu
On Tuesday, 11 April 2017 16:53:48 UTC-6, Robert Beezer wrote:
Maybe it is a *convention* that "_" is the previous result.

"_" is a legitimate variable name in Python, so it is sometimes used for results
you don't really intend to keep.

The following produces 8 in the Sage Cell:

_ = 1 + 2
_ + 5

Rob

Well, it is a convention that _ is automatically assigned the last result and on Sage command line you can do

sage: 1 + 2
3
sage: _ + 5
8

My point was that there are two separate computations here, but when entered in a single cell these two lines make "one computation", so _ does not get any value (also 3 is not displayed since only the last result is shown).
Reply all
Reply to author
Forward
0 new messages