Skip to content
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.. contents::
.. contents::

CHANGES
=======
Expand Down Expand Up @@ -41,6 +41,8 @@ Internals
#. Operator name to unicode or ASCII comes from Mathics scanner character tables.
#. ``eval*`` methods in `Builtin` classes are considerer as synonyms of ``apply*`` methods.
#. Modularize and improve the way in which `Builtin` classes are selected to have an associated `Definition`.
#. `_SetOperator.assign_elementary` was renamed as `_SetOperator.assign`. All the special cases are not handled by the `_SetOperator.special_cases` dict.



Bugs
Expand Down
26 changes: 24 additions & 2 deletions mathics/builtin/assignments/assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,30 @@ class SetDelayed(Set):
= 2 / 3
>> F[-3, 2]
= -2 / 3
We can use conditional delayed assignments to define \
symbols with values conditioned to the context. For example,
>> ClearAll[a,b]; a/; b>0:= 3
Set $a$ to have a value of $3$ if certain variable $b$ is positive.\
So, if this variable is not set, $a$ stays unevaluated:
>> a
= a
If now we assign a positive value to $b$, then $a$ is evaluated:
>> b=2; a
= 3
"""

# I WMA, if we assign a value without a condition on the LHS,
# conditional values are never reached. So,
#
# Notice however that if we assign an unconditional value to $a$, \
# this overrides the condition:
# >> a:=0; a/; b>1:= 3
# >> a
# = 0
#
# In Mathics, this last line would return 3
# """

operator = ":="
attributes = A_HOLD_ALL | A_PROTECTED | A_SEQUENCE_HOLD

Expand Down Expand Up @@ -203,7 +225,7 @@ def apply(self, f, lhs, rhs, evaluation):
return

rhs = rhs.evaluate(evaluation)
self.assign_elementary(lhs, rhs, evaluation, tags=[name])
self.assign(lhs, rhs, evaluation, tags=[name])
return rhs


Expand All @@ -228,7 +250,7 @@ def apply(self, f, lhs, rhs, evaluation):
evaluation.message(self.get_name(), "sym", f, 1)
return

if self.assign_elementary(lhs, rhs, evaluation, tags=[name]):
if self.assign(lhs, rhs, evaluation, tags=[name]):
return SymbolNull
else:
return SymbolFailed
Expand Down
Loading