Skip to content

Commit

Permalink
fix #956
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatera committed Jan 9, 2024
1 parent bfaf356 commit 826bedb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mathics/builtin/procedural.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ def eval(self, expr, rules, evaluation):
evaluation.message("Switch", "argct", "Switch", len(rules) + 1)
return
for pattern, value in zip(rules[::2], rules[1::2]):

This comment has been minimized.

Copy link
@rocky

rocky Jan 9, 2024

Member

It might be good to add a comment basically saying what you mentioned in the issue:

pattern.evaluate() is needed because Switch[] has a HoldRest attribute.

if match(expr, pattern, evaluation):
if match(expr, pattern.evaluate(evaluation), evaluation):
return value.evaluate(evaluation)
# return unevaluated Switch when no pattern matches

Expand Down
6 changes: 6 additions & 0 deletions test/builtin/test_procedural.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ def test_nestwhile(str_expr, str_expected):
("res", None, "Null", None),
("res=CompoundExpression[]", None, "Null", None),
("res", None, "Null", None),
(
"{MatchQ[Infinity,Infinity],Switch[Infinity,Infinity,True,_,False]}",
None,
"{True, True}",
"Issue #956",
),
(
"Clear[f];Clear[g];Clear[h];Clear[i];Clear[n];Clear[res];Clear[z]; ",
None,
Expand Down

1 comment on commit 826bedb

@rocky
Copy link
Member

@rocky rocky commented on 826bedb Jan 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - Thanks!

Please sign in to comment.