diff --git a/mathics/builtin/assignment.py b/mathics/builtin/assignment.py index a74fdb4f1b..34a5ece0d4 100644 --- a/mathics/builtin/assignment.py +++ b/mathics/builtin/assignment.py @@ -1012,34 +1012,6 @@ def apply(self, expr, evaluation): return Symbol('Null') -class Quit(Builtin): - """ -
-
'Quit'[] -
removes all user-defined definitions. -
- - >> a = 3 - = 3 - >> Quit[] - >> a - = a - - 'Quit' even removes the definitions of protected and locked symbols: - >> x = 5; - >> Attributes[x] = {Locked, Protected}; - >> Quit[] - >> x - = x - """ - - def apply(self, evaluation): - 'Quit[]' - - evaluation.definitions.set_user_definitions({}) - return Symbol('Null') - - def get_symbol_values(symbol, func_name, position, evaluation): name = symbol.get_name() if not name: diff --git a/mathics/builtin/evaluation.py b/mathics/builtin/evaluation.py index b8cf8ec2a9..00c3db5d01 100644 --- a/mathics/builtin/evaluation.py +++ b/mathics/builtin/evaluation.py @@ -392,3 +392,42 @@ class Out(Builtin): ' f:StandardForm|TraditionalForm|InputForm|OutputForm]': r'"%%" <> ToString[k]', } + + +class Exit(Builtin): + ''' +
+
'Exit[]' +
terminates the Mathics session. +
'Exit[n]' +
terminates with exit code $n$. +
+ + Exit is an alias for Quit. + ''' + + def apply(self, evaluation): + 'Exit[]' + sys.exit() + + def apply_n(self, n, evaluation): + 'Exit[n_Integer]' + sys.exit(n.get_int_value()) + + +class Quit(Builtin): + ''' +
+
'Quit[]' +
terminates the Mathics session. +
'Quit[n]' +
terminates with exit code $n$. +
+ + Quit is an alias for Exit. + ''' + + rules = { + 'Quit[n_Integer]': 'Exit[n]', + 'Quit[]': 'Exit[]', + } diff --git a/mathics/main.py b/mathics/main.py index 18e5d5f862..61824a44e6 100644 --- a/mathics/main.py +++ b/mathics/main.py @@ -288,9 +288,13 @@ def main(): shell.print_result(result) except (KeyboardInterrupt): print('\nKeyboardInterrupt') - except (SystemExit, EOFError): + except EOFError: print("\n\nGoodbye!\n") break + except SystemExit: + print("\n\nGoodbye!\n") + # raise to pass the error code on, e.g. Quit[1] + raise finally: shell.reset_lineno()