diff --git a/mathics/eval/assignment.py b/mathics/eval/assignment.py index 5e230f039..6c88ae0b2 100644 --- a/mathics/eval/assignment.py +++ b/mathics/eval/assignment.py @@ -50,6 +50,33 @@ def __init__(self, lhs, rhs) -> None: self.rhs = rhs +def assign_store_rules_by_tag(self, lhs, rhs, evaluation, tags, upset=False) -> bool: + """ + This is the default assignment. Stores a rule of the form lhs->rhs + as a value associated to each symbol listed in tags. + For special cases, such like conditions or patterns in the lhs, + lhs and rhs are rewritten in a normal form, where + conditions are associated to the lhs. + """ + lhs, condition = unroll_conditions(lhs) + lhs, rhs = unroll_patterns(lhs, rhs, evaluation) + defs = evaluation.definitions + ignore_protection, tags = eval_assign_other(self, lhs, rhs, evaluation, tags, upset) + # In WMA, this does not happens. However, if we remove this, + # some combinatorica tests fail. + # Also, should not be at the beginning? + lhs, rhs = process_rhs_conditions(lhs, rhs, condition, evaluation) + count = 0 + rule = Rule(lhs, rhs) + position = "up" if upset else None + for tag in tags: + if rejected_because_protected(self, lhs, tag, evaluation, ignore_protection): + continue + count += 1 + defs.add_rule(tag, rule, position=position) + return count > 0 + + def eval_assign( self, lhs: BaseElement, @@ -94,33 +121,6 @@ def eval_assign( return False -def assign_store_rules_by_tag(self, lhs, rhs, evaluation, tags, upset=False) -> bool: - """ - This is the default assignment. Stores a rule of the form lhs->rhs - as a value associated to each symbol listed in tags. - For special cases, such like conditions or patterns in the lhs, - lhs and rhs are rewritten in a normal form, where - conditions are associated to the lhs. - """ - lhs, condition = unroll_conditions(lhs) - lhs, rhs = unroll_patterns(lhs, rhs, evaluation) - defs = evaluation.definitions - ignore_protection, tags = eval_assign_other(self, lhs, rhs, evaluation, tags, upset) - # In WMA, this does not happens. However, if we remove this, - # some combinatorica tests fail. - # Also, should not be at the beginning? - lhs, rhs = process_rhs_conditions(lhs, rhs, condition, evaluation) - count = 0 - rule = Rule(lhs, rhs) - position = "up" if upset else None - for tag in tags: - if rejected_because_protected(self, lhs, tag, evaluation, ignore_protection): - continue - count += 1 - defs.add_rule(tag, rule, position=position) - return count > 0 - - def eval_assign_attributes( self: Builtin, lhs: BaseElement,