Skip to content

Commit

Permalink
fix #331
Browse files Browse the repository at this point in the history
  • Loading branch information
sn6uv committed Apr 2, 2016
1 parent a89c1e3 commit a3ca6b7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 7 additions & 0 deletions mathics/builtin/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,14 @@ def apply(self, expr, evaluation):
items = expr.get_sequence()
result = Symbol('Null')
for expr in items:
prev_result = result
result = expr.evaluate(evaluation)

# `expr1; expr2;` returns `Null` but assigns `expr2` to `Out[n]`.
# even stranger `CompoundExpresion[expr1, Null, Null]` assigns `expr1` to `Out[n]`.
if result == Symbol('Null') and prev_result != Symbol('Null'):
evaluation.predetermined_out = prev_result

return result


Expand Down
9 changes: 8 additions & 1 deletion mathics/core/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ def __init__(self, definitions=None,
self.out_callback = out_callback
self.listeners = {}
self.options = None
self.predetermined_out = None

self.quiet_all = False
self.quiet_messages = set()
Expand Down Expand Up @@ -211,7 +212,13 @@ def evaluate():
Expression('In', line_no), query))
result = query.evaluate(self)
if history_length > 0:
stored_result = self.get_stored_result(result)
if self.predetermined_out is not None:
out_result = self.predetermined_out
self.predetermined_out = None
else:
out_result = result

stored_result = self.get_stored_result(out_result)
self.definitions.add_rule('Out', Rule(
Expression('Out', line_no), stored_result))
if result != Symbol('Null'):
Expand Down

0 comments on commit a3ca6b7

Please sign in to comment.