Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct LHS evaluation in SetDelayed assignment #603

Merged
merged 36 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8dbbe6e
improving clarity in Builtin.contribute
mmatera Nov 7, 2022
6dd03d5
adding comments. adding tests
mmatera Nov 8, 2022
ff86f72
fix test for SetDelayed. Move special case for Set with LHS a list aw…
mmatera Nov 8, 2022
a514882
more on modularize assignment. assign_elementary->assign
mmatera Nov 8, 2022
5c5d85d
fixing set_eval
mmatera Nov 8, 2022
11f29ba
adding tests for OneIdentity
mmatera Nov 8, 2022
88be642
fix OneIdentity
mmatera Nov 10, 2022
0c60ac5
remove comment
mmatera Nov 10, 2022
7a62c66
Merge branch 'fix_one_identity' into fix_set_eval
mmatera Nov 10, 2022
8cd763a
fix pytest
mmatera Nov 10, 2022
58f808e
fix a bug that makes that URLSave always fails
mmatera Nov 10, 2022
b0b52b5
fix WriteString standard output
mmatera Nov 10, 2022
71b082b
catch not known attributes in ClearAttributes and SetAttributes
mmatera Nov 11, 2022
8a86511
Merge pull request #608 from Mathics3/fix_Set_and_Clear_Attributes
rocky Nov 11, 2022
6fda837
Update 'attributes' for current standards
rocky Nov 11, 2022
3528e0d
Merge pull request #607 from Mathics3/update-attribute-for-current-st…
rocky Nov 11, 2022
513bfc5
adding comments. adding tests
mmatera Nov 8, 2022
e92da0f
fix test for SetDelayed. Move special case for Set with LHS a list aw…
mmatera Nov 8, 2022
a728701
more on modularize assignment. assign_elementary->assign
mmatera Nov 8, 2022
9f9c5b8
Merge pull request #606 from Mathics3/fix_URLSave
rocky Nov 12, 2022
d88ab76
Merge pull request #600 from Mathics3/fix_contribute
rocky Nov 13, 2022
ad6b87a
Merge pull request #601 from Mathics3/documenting_assignment
rocky Nov 13, 2022
92e6b0c
fix OneIdentity
mmatera Nov 10, 2022
cd74aa9
remove comment
mmatera Nov 10, 2022
cb2ca92
Handle optional with a first element that is not a Pattern[]
mmatera Nov 11, 2022
afcf467
Update examples in OneIdentity
rocky Nov 12, 2022
454bbaa
More pervasive use of Symbols
rocky Nov 12, 2022
21a4080
Pattern_create -> Pattern.create
rocky Nov 12, 2022
d33ca93
Add function signature; straighten import issue
rocky Nov 12, 2022
318a2b8
Put test_rules_patterns tests where they belong
rocky Nov 12, 2022
de5bbbe
Add note to add skipped example as a doctest ...
rocky Nov 13, 2022
cdd8e6a
Merge pull request #602 from Mathics3/fix_one_identity
rocky Nov 13, 2022
b829b09
merge
mmatera Nov 13, 2022
20799cf
Changes suggested in PR review
rocky Nov 15, 2022
ca35d60
Move ASSIGNMENT_FUNCTION_MAP into core
rocky Nov 15, 2022
73a369b
Merge pull request #622 from Mathics3/improve-SetDelayed-LHS-assignment
rocky Nov 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ clean: clean-cython clean-cache

#: Run py.test tests. Use environment variable "o" for pytest options
pytest:
py.test $(PYTEST_WORKERS) test $o
$(PYTHON) -m pytest $(PYTEST_WORKERS) test $o


#: Run a more extensive pattern-matching test
Expand Down
3 changes: 2 additions & 1 deletion mathics/builtin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
PatternObject,
)

from mathics.core.pattern import pattern_objects

from mathics.settings import ENABLE_FILES_MODULE
from mathics.version import __version__ # noqa used in loading to check consistency.

Expand Down Expand Up @@ -267,7 +269,6 @@ def sanity_check(cls, module):
mathics_to_python = {} # here we have: name -> string
sympy_to_mathics = {}

pattern_objects = {}
builtins_precedence = {}

new_builtins = _builtins
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
24 changes: 15 additions & 9 deletions mathics/builtin/assignments/clear.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,20 @@
Atom,
Symbol,
SymbolNull,
system_symbols,
symbol_set,
)

from mathics.core.systemsymbols import (
SymbolContext,
SymbolContextPath,
SymbolDownValues,
SymbolFailed,
SymbolMessages,
SymbolNValues,
SymbolOptions,
SymbolOwnValues,
SymbolSubValues,
SymbolUpValues,
)

from mathics.core.atoms import String
Expand Down Expand Up @@ -320,12 +326,12 @@ def apply(self, expr, evaluation):
return SymbolNull


SYSTEM_SYMBOL_VALUES = system_symbols(
"OwnValues",
"DownValues",
"SubValues",
"UpValues",
"NValues",
"Options",
"Messages",
SYSTEM_SYMBOL_VALUES = symbol_set(
SymbolDownValues,
SymbolMessages,
SymbolNValues,
SymbolOptions,
SymbolOwnValues,
SymbolSubValues,
SymbolUpValues,
)
Loading