|
5 | 5 |
|
6 | 6 |
|
7 | 7 | from mathics.builtin.base import BinaryOperator, Builtin |
8 | | -from mathics.core.assignment import ( |
9 | | - ASSIGNMENT_FUNCTION_MAP, |
| 8 | +from mathics.core.eval.set import ( |
| 9 | + SET_EVAL_FUNCTION_MAP, |
10 | 10 | AssignmentException, |
11 | 11 | assign_store_rules_by_tag, |
12 | 12 | normalize_lhs, |
@@ -47,7 +47,7 @@ def assign(self, lhs, rhs, evaluation, tags=None, upset=False): |
47 | 47 | try: |
48 | 48 | # Using a builtin name, find which assignment procedure to perform, |
49 | 49 | # and then call that function. |
50 | | - assignment_func = ASSIGNMENT_FUNCTION_MAP.get(lookup_name, None) |
| 50 | + assignment_func = SET_EVAL_FUNCTION_MAP.get(lookup_name, None) |
51 | 51 | if assignment_func: |
52 | 52 | return assignment_func(self, lhs, rhs, evaluation, tags, upset) |
53 | 53 |
|
@@ -170,11 +170,21 @@ class SetDelayed(Set): |
170 | 170 | 'Condition' ('/;') can be used with 'SetDelayed' to make an |
171 | 171 | assignment that only holds if a condition is satisfied: |
172 | 172 | >> f[x_] := p[x] /; x>0 |
| 173 | + >> f[x_] := p[-x]/; x<-2 |
173 | 174 | >> f[3] |
174 | 175 | = p[3] |
175 | 176 | >> f[-3] |
176 | | - = f[-3] |
177 | | - It also works if the condition is set in the LHS: |
| 177 | + = p[3] |
| 178 | + >> f[-1] |
| 179 | + = f[-1] |
| 180 | + Notice that the LHS is the same in both definitions, but the second |
| 181 | + does not overwrite the first one. |
| 182 | +
|
| 183 | + To overwrite one of these definitions, we have to assign using the same condition: |
| 184 | + >> f[x_] := Sin[x] /; x>0 |
| 185 | + >> f[3] |
| 186 | + = Sin[3] |
| 187 | + In a similar way, the condition can be set in the LHS: |
178 | 188 | >> F[x_, y_] /; x < y /; x>0 := x / y; |
179 | 189 | >> F[x_, y_] := y / x; |
180 | 190 | >> F[2, 3] |
|
0 commit comments