Skip to content

Commit

Permalink
adding Exit as an alias of Quit (#998)
Browse files Browse the repository at this point in the history
This fixes #996. It seems that the rule for `Exit` was not loaded
together with `Quit`.

---------

Co-authored-by: R. Bernstein <[email protected]>
  • Loading branch information
mmatera and rocky authored Feb 10, 2024
1 parent 7bdb5a7 commit 207ad32
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 93 deletions.
47 changes: 7 additions & 40 deletions mathics/builtin/evaluation.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# -*- coding: utf-8 -*-
"""Evaluation Control
Mathics3 takes an expression that it is given, and evaluates it. Built \
into the evaluation are primitives that allow finer control over the \
process of evaluation in cases where it is needed.
"""

from mathics.core.atoms import Integer
from mathics.core.attributes import A_HOLD_ALL, A_HOLD_ALL_COMPLETE, A_PROTECTED
from mathics.core.builtin import Builtin, Predefined
from mathics.core.evaluation import (
MAX_RECURSION_DEPTH,
Evaluation,
set_python_recursion_limit,
)
from mathics.core.evaluation import MAX_RECURSION_DEPTH, set_python_recursion_limit


class RecursionLimit(Predefined):
Expand Down Expand Up @@ -303,38 +305,3 @@ class Sequence(Builtin):
summary_text = (
"a sequence of arguments that will automatically be spliced into any function"
)


class Quit(Builtin):
"""
<url>:WMA link:https://reference.wolfram.com/language/ref/Quit.html</url>
<dl>
<dt>'Quit'[]
<dd> Terminates the Mathics session.
<dt>'Quit[$n$]'
<dd> Terminates the mathics session with exit code $n$.
</dl>
<dl>
<dt>'Exit'[]
<dd> Terminates the Mathics session.
<dt>'Exit[$n$]'
<dd> Terminates the mathics session with exit code $n$.
</dl>
"""

rules = {
"Exit[n___]": "Quit[n]",
}
summary_text = "terminate the session"

def eval(self, evaluation: Evaluation, n):
"%(name)s[n___]"
exitcode = 0
if isinstance(n, Integer):
exitcode = n.get_int_value()
raise SystemExit(exitcode)
101 changes: 101 additions & 0 deletions mathics/builtin/kernel_sessions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# -*- coding: utf-8 -*-
"Kernel Sessions"

from mathics.core.atoms import Integer
from mathics.core.attributes import A_LISTABLE, A_PROTECTED
from mathics.core.builtin import Builtin
from mathics.core.evaluation import Evaluation


class Out(Builtin):
"""
<url>:WMA: https://reference.wolfram.com/language/ref/$Out</url>
<dl>
<dt>'%$k$' or 'Out[$k$]'
<dd>gives the result of the $k$th input line.
<dt>'%'
<dd>gives the last result.
<dt>''%%'
<dd>gives the result before the previous input line.
</dl>
>> 42
= 42
>> %
= 42
>> 43;
>> %
= 43
>> 44
= 44
>> %1
= 42
>> %%
= 44
>> Hold[Out[-1]]
= Hold[%]
>> Hold[%4]
= Hold[%4]
>> Out[0]
= Out[0]
#> 10
= 10
#> Out[-1] + 1
= 11
#> Out[] + 1
= 12
"""

attributes = A_LISTABLE | A_PROTECTED

rules = {
"Out[k_Integer?Negative]": "Out[$Line + k]",
"Out[]": "Out[$Line - 1]",
"MakeBoxes[Out[k_Integer?((-10 <= # < 0)&)],"
" f:StandardForm|TraditionalForm|InputForm|OutputForm]": r'StringJoin[ConstantArray["%%", -k]]',
"MakeBoxes[Out[k_Integer?Positive],"
" f:StandardForm|TraditionalForm|InputForm|OutputForm]": r'"%%" <> ToString[k]',
}
summary_text = "result of the Kth input line"


class Quit(Builtin):
"""
<url>:WMA link:https://reference.wolfram.com/language/ref/Quit.html</url>
<dl>
<dt>'Quit'[]
<dd> Terminates the Mathics session.
<dt>'Quit[$n$]'
<dd> Terminates the mathics session with exit code $n$.
</dl>
'Quit' is the same thing as 'Exit'.
"""

summary_text = "terminate the session"

def eval(self, evaluation: Evaluation, n):
"%(name)s[n___]"
exitcode = 0
if isinstance(n, Integer):
exitcode = n.get_int_value()
raise SystemExit(exitcode)


class Exit(Quit):
"""
<url>:WMA link:https://reference.wolfram.com/language/ref/Exit.html</url>
<dl>
<dt>'Exit'[]
<dd> Terminates the Mathics session.
<dt>'Exit[$n$]'
<dd> Terminates the mathics session with exit code $n$.
'Exit' is the same thing as 'Quit'.
</dl>
"""
53 changes: 0 additions & 53 deletions mathics/builtin/mainloop.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,56 +222,3 @@ class Line(Builtin):

name = "$Line"
summary_text = "current line number"


class Out(Builtin):
"""
<url>:WMA: https://reference.wolfram.com/language/ref/$Out</url>
<dl>
<dt>'Out[$k$]'
<dt>'%$k$'
<dd>gives the result of the $k$th input line.
<dt>'%', '%%', etc.
<dd>gives the result of the previous input line, of the line before the previous input line, etc.
</dl>
>> 42
= 42
>> %
= 42
>> 43;
>> %
= 43
>> 44
= 44
>> %1
= 42
>> %%
= 44
>> Hold[Out[-1]]
= Hold[%]
>> Hold[%4]
= Hold[%4]
>> Out[0]
= Out[0]
#> 10
= 10
#> Out[-1] + 1
= 11
#> Out[] + 1
= 12
"""

attributes = A_LISTABLE | A_PROTECTED

rules = {
"Out[k_Integer?Negative]": "Out[$Line + k]",
"Out[]": "Out[$Line - 1]",
"MakeBoxes[Out[k_Integer?((-10 <= # < 0)&)],"
" f:StandardForm|TraditionalForm|InputForm|OutputForm]": r'StringJoin[ConstantArray["%%", -k]]',
"MakeBoxes[Out[k_Integer?Positive],"
" f:StandardForm|TraditionalForm|InputForm|OutputForm]": r'"%%" <> ToString[k]',
}
summary_text = "result of the Kth input line"

0 comments on commit 207ad32

Please sign in to comment.