From c35f84583e0e0a8e223815a19beebdf823775fa4 Mon Sep 17 00:00:00 2001 From: rocky Date: Mon, 6 Apr 2026 19:24:14 -0400 Subject: [PATCH 1/2] Adjust some comments --- mathics/builtin/patterns/restrictions.py | 6 +++++- mathics/core/convert/expression.py | 2 +- mathics/core/expression.py | 5 +++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/mathics/builtin/patterns/restrictions.py b/mathics/builtin/patterns/restrictions.py index a33ce94d9..4d3fa0b89 100644 --- a/mathics/builtin/patterns/restrictions.py +++ b/mathics/builtin/patterns/restrictions.py @@ -51,8 +51,12 @@ class Condition(InfixOperator, PatternObject): """ arg_counts = [2] - # Don't know why this has attribute HoldAll in Mathematica + + # We use HOLD_REST because the condition *pattern* evaluated, + # but not the *expr*. Evaluation of *expr* is controlled by + # whether *pattern* is true or not. attributes = A_HOLD_REST | A_PROTECTED + summary_text = "conditional definition" def init( diff --git a/mathics/core/convert/expression.py b/mathics/core/convert/expression.py index 60784bfea..f23e59c3a 100644 --- a/mathics/core/convert/expression.py +++ b/mathics/core/convert/expression.py @@ -24,7 +24,7 @@ def to_expression( elements_conversion_fn: Callable = from_python, ) -> Expression: """ - This is an expression constructor that can be used when the Head and elements are not Mathics + This is an expression constructor that can be used when the Head and elements are not Mathics3 objects. For example to_expression("Plus", 1, 2, 3) """ if isinstance(head, str): diff --git a/mathics/core/expression.py b/mathics/core/expression.py index 58f1f744a..d39de744b 100644 --- a/mathics/core/expression.py +++ b/mathics/core/expression.py @@ -621,8 +621,9 @@ def evaluate( def evaluate_elements(self, evaluation) -> "Expression": """ - return a new expression with the head and the - evaluable elements evaluated, according to the attributes. + Return a new expression with the head and the + evaluable elements evaluated, taking into account the + the expression's head attribute and its HOLD properties. """ head = self._head if isinstance(head, EvalMixin): From ee67f5953e4c1fd31ee708245919cec941062632 Mon Sep 17 00:00:00 2001 From: rocky Date: Mon, 6 Apr 2026 21:40:12 -0400 Subject: [PATCH 2/2] Condition needs HOLD_ALL, not HOLD_REST Thanks, mmatera! --- mathics/builtin/patterns/restrictions.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/mathics/builtin/patterns/restrictions.py b/mathics/builtin/patterns/restrictions.py index 4d3fa0b89..2483d24d2 100644 --- a/mathics/builtin/patterns/restrictions.py +++ b/mathics/builtin/patterns/restrictions.py @@ -7,7 +7,7 @@ from typing import Optional as OptionalType, Tuple from mathics.core.atoms import Integer, Number, Rational, Real, String -from mathics.core.attributes import A_HOLD_REST, A_PROTECTED +from mathics.core.attributes import A_HOLD_ALL, A_PROTECTED from mathics.core.builtin import InfixOperator, PatternObject, Test from mathics.core.evaluation import Evaluation from mathics.core.expression import Expression @@ -51,11 +51,7 @@ class Condition(InfixOperator, PatternObject): """ arg_counts = [2] - - # We use HOLD_REST because the condition *pattern* evaluated, - # but not the *expr*. Evaluation of *expr* is controlled by - # whether *pattern* is true or not. - attributes = A_HOLD_REST | A_PROTECTED + attributes = A_HOLD_ALL | A_PROTECTED summary_text = "conditional definition"