-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Miscellaneous lint for expanding and correcting `MapAt[]` * add eval_MapAt (move out of builtin class), and start to address error messages more correctly * walk_parts -> eval_Part which is what it is. And move to `mathics.eval.list.eol` since that is where it belongs * DRY use of "psl" message * Drop "_" at the beginning of routines which weren't really internal.
- Loading branch information
Showing
15 changed files
with
425 additions
and
395 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
""" | ||
Evaluation routines for mathics.builtin.functional.appy_fns_to_lists | ||
""" | ||
from mathics.core.atoms import Integer | ||
from mathics.core.evaluation import Evaluation | ||
from mathics.core.exceptions import PartRangeError | ||
from mathics.core.expression import Expression | ||
from mathics.core.list import ListExpression | ||
from mathics.core.symbols import Symbol | ||
from mathics.core.systemsymbols import SymbolMapAt, SymbolRule | ||
|
||
|
||
def eval_MapAt(f, expr, args, evaluation: Evaluation): | ||
m = len(expr.elements) | ||
new_elements = list(expr.elements) | ||
|
||
def map_at_replace_one(i: int): | ||
if 1 <= i <= m: | ||
j = i - 1 | ||
elif -m <= i <= -1: | ||
j = m + i | ||
else: | ||
evaluation.message("MapAt", "partw", ListExpression(Integer(i)), expr) | ||
raise PartRangeError | ||
replace_element = new_elements[j] | ||
if hasattr(replace_element, "head") and replace_element.head is Symbol( | ||
"System`Rule" | ||
): | ||
new_elements[j] = Expression( | ||
SymbolRule, | ||
replace_element.elements[0], | ||
Expression(f, replace_element.elements[1]), | ||
) | ||
else: | ||
new_elements[j] = Expression(f, replace_element) | ||
|
||
try: | ||
if isinstance(args, Integer): | ||
map_at_replace_one(args.value) | ||
return ListExpression(*new_elements) | ||
elif isinstance(args, Expression): | ||
for item in args.elements: | ||
# Get value for arg in expr.elemnts | ||
# Replace value | ||
if ( | ||
isinstance(item, Expression) | ||
and len(item.elements) == 1 | ||
and isinstance(item.elements[0], Integer) | ||
): | ||
map_at_replace_one(item.elements[0].value) | ||
return ListExpression(*new_elements) | ||
else: | ||
evaluation.message( | ||
"MapAt", "psl", args, Expression(SymbolMapAt, f, expr, args) | ||
) | ||
except PartRangeError: | ||
return |
Empty file.
Oops, something went wrong.