Skip to content

Commit 66de818

Browse files
committed
Merge remote-tracking branch 'origin/master' into fix_issue_in_rules_with_conditional_replacement
2 parents 1d61b85 + 2ffdf02 commit 66de818

File tree

12 files changed

+403
-306
lines changed

12 files changed

+403
-306
lines changed

mathics/builtin/assignments/assignment.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@
44
"""
55

66

7-
from mathics.builtin.assignments.internals import _SetOperator
87
from mathics.builtin.base import BinaryOperator, Builtin
8+
from mathics.core.assignment import (
9+
ASSIGNMENT_FUNCTION_MAP,
10+
AssignmentException,
11+
assign_store_rules_by_tag,
12+
normalize_lhs,
13+
)
14+
915
from mathics.core.attributes import (
1016
A_HOLD_ALL,
1117
A_HOLD_FIRST,
@@ -18,6 +24,39 @@
1824
from mathics.core.systemsymbols import SymbolFailed
1925

2026

27+
class _SetOperator:
28+
"""
29+
This is the base class for assignment Builtin operators.
30+
31+
Special cases are determined by the head of the expression. Then
32+
they are processed by specific routines, which are poke from
33+
the ``ASSIGNMENT_FUNCTION_MAP`` dict.
34+
"""
35+
36+
# FIXME:
37+
# Assigment is determined by the LHS.
38+
# Are there a larger patterns or natural groupings that we are missing?
39+
# For example, it might be that it
40+
# we can key off of some attributes or other properties of the
41+
# LHS of a builtin, instead of listing all of the builtins in that class
42+
# (which may miss some).
43+
# Below, we key on a string, but Symbol is more correct.
44+
45+
def assign(self, lhs, rhs, evaluation, tags=None, upset=False):
46+
lhs, lookup_name = normalize_lhs(lhs, evaluation)
47+
try:
48+
# Using a builtin name, find which assignment procedure to perform,
49+
# and then call that function.
50+
assignment_func = ASSIGNMENT_FUNCTION_MAP.get(lookup_name, None)
51+
if assignment_func:
52+
return assignment_func(self, lhs, rhs, evaluation, tags, upset)
53+
54+
return assign_store_rules_by_tag(self, lhs, rhs, evaluation, tags, upset)
55+
except AssignmentException:
56+
57+
return False
58+
59+
2160
class Set(BinaryOperator, _SetOperator):
2261
"""
2362
<dl>

mathics/builtin/assignments/clear.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@
3838
SymbolUpValues,
3939
)
4040

41+
from mathics.core.assignment import is_protected
4142
from mathics.core.atoms import String
4243

43-
from mathics.builtin.assignments.internals import is_protected
44-
4544

4645
class Clear(Builtin):
4746
"""

mathics/builtin/assignments/types.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88

99
from mathics.builtin.base import Builtin
1010

11-
from mathics.builtin.assignments.internals import get_symbol_values
12-
11+
from mathics.core.assignment import get_symbol_values
1312
from mathics.core.attributes import A_HOLD_ALL, A_PROTECTED
1413

1514

mathics/builtin/assignments/upvalues.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22

33

4-
from mathics.builtin.assignments.internals import _SetOperator
4+
from mathics.builtin.assignments.assignment import _SetOperator
55
from mathics.builtin.base import BinaryOperator
66
from mathics.core.attributes import (
77
A_HOLD_ALL,

mathics/builtin/atomic/symbols.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import re
99

10-
from mathics.builtin.assignments.internals import get_symbol_values
1110
from mathics.builtin.base import (
1211
Builtin,
1312
PrefixOperator,
@@ -16,6 +15,7 @@
1615

1716
from mathics.builtin.atomic.strings import to_regex
1817

18+
from mathics.core.assignment import get_symbol_values
1919
from mathics.core.atoms import String
2020

2121
from mathics.core.attributes import (

mathics/builtin/attributes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616

1717
from mathics.builtin.base import Predefined, Builtin
18-
from mathics.builtin.assignments.internals import get_symbol_list
18+
from mathics.core.assignment import get_symbol_list
1919
from mathics.core.atoms import String
2020
from mathics.core.attributes import (
2121
attributes_bitset_to_list,

mathics/builtin/scoping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"""
55

66

7-
from mathics.builtin.assignments.internals import get_symbol_list
87
from mathics.core.attributes import (
98
A_HOLD_ALL,
109
A_PROTECTED,
1110
attribute_string_to_number,
1211
)
1312
from mathics.builtin.base import Builtin, Predefined
13+
from mathics.core.assignment import get_symbol_list
1414
from mathics.core.atoms import (
1515
String,
1616
Integer,

0 commit comments

Comments
 (0)