|
4 | 4 | """
|
5 | 5 |
|
6 | 6 |
|
7 |
| -from mathics.builtin.assignments.internals import _SetOperator |
8 | 7 | 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 | + |
9 | 15 | from mathics.core.attributes import (
|
10 | 16 | A_HOLD_ALL,
|
11 | 17 | A_HOLD_FIRST,
|
|
18 | 24 | from mathics.core.systemsymbols import SymbolFailed
|
19 | 25 |
|
20 | 26 |
|
| 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 | + |
21 | 60 | class Set(BinaryOperator, _SetOperator):
|
22 | 61 | """
|
23 | 62 | <dl>
|
|
0 commit comments