Skip to content

Commit 4286b32

Browse files
mmaterarocky
authored andcommitted
Singletonize Symbol System`List
1 parent 21eb3eb commit 4286b32

12 files changed

Lines changed: 202 additions & 190 deletions

File tree

mathics/builtin/calculus.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from mathics.version import __version__ # noqa used in loading to check consistency.
77

88
from mathics.builtin.base import Builtin, PostfixOperator, SympyFunction
9-
from mathics.core.expression import Expression, Integer, Number, SymbolTrue, SymbolFalse
9+
from mathics.core.expression import Expression, Integer, Number, SymbolTrue, SymbolFalse, SymbolList
1010
from mathics.core.convert import sympy_symbol_prefix, SympyExpression, from_sympy
1111
from mathics.core.rules import Pattern
1212
from mathics.core.numbers import dps
@@ -190,7 +190,7 @@ def summand(leaf, index):
190190
def apply_wrong(self, expr, x, other, evaluation):
191191
"D[expr_, {x_, other___}]"
192192

193-
arg = Expression("List", x, *other.get_sequence())
193+
arg = Expression(SymbolList, x, *other.get_sequence())
194194
evaluation.message("D", "dvar", arg)
195195
return Expression("D", expr, arg)
196196

@@ -743,7 +743,7 @@ def apply(self, eqs, vars, evaluation):
743743
if eq == SymbolTrue:
744744
pass
745745
elif eq == SymbolFalse:
746-
return Expression("List")
746+
return Expression(SymbolList)
747747
elif not eq.has_form("Equal", 2):
748748
return evaluation.message("Solve", "eqf", eqs_original)
749749
else:
@@ -816,9 +816,9 @@ def transform_solution(sol):
816816
if not isinstance(result, list):
817817
result = [result]
818818
if isinstance(result, list) and len(result) == 1 and result[0] is True:
819-
return Expression("List", Expression("List"))
819+
return Expression(SymbolList, Expression(SymbolList))
820820
if result == [None]:
821-
return Expression("List")
821+
return Expression(SymbolList)
822822
results = []
823823
for sol in result:
824824
results.extend(transform_solution(sol))
@@ -1141,4 +1141,4 @@ def sub(evaluation):
11411141
else:
11421142
evaluation.message("FindRoot", "maxiter")
11431143

1144-
return Expression("List", Expression("Rule", x, x0))
1144+
return Expression(SymbolList, Expression("Rule", x, x0))

mathics/builtin/files.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
SymbolFalse,
4343
SymbolNull,
4444
SymbolTrue,
45+
SymbolList,
4546
from_mpmath,
4647
from_python,
4748
valid_context_name,
@@ -396,7 +397,7 @@ class Path(Predefined):
396397
name = "$Path"
397398

398399
def evaluate(self, evaluation):
399-
return Expression("List", *[String(p) for p in PATH_VAR])
400+
return Expression(SymbolList, *[String(p) for p in PATH_VAR])
400401

401402

402403
class OperatingSystem(Predefined):

mathics/builtin/graphics.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
Real,
2727
String,
2828
Symbol,
29+
SymbolList,
2930
strip_context,
3031
system_symbols,
3132
system_symbols_dict,
@@ -475,7 +476,7 @@ def convert(content):
475476
head = content.get_head_name()
476477

477478
if head == "System`List":
478-
return Expression("List", *[convert(item) for item in content.leaves])
479+
return Expression(SymbolList, *[convert(item) for item in content.leaves])
479480
elif head == "System`Style":
480481
return Expression(
481482
"StyleBox", *[convert(item) for item in content.leaves]
@@ -986,9 +987,9 @@ def distance(a, b):
986987
*[distance(a, b) for a, b in zip(c1.leaves, c2.leaves)]
987988
)
988989
else:
989-
return Expression("List", *[distance(c, c2) for c in c1.leaves])
990+
return Expression(SymbolList, *[distance(c, c2) for c in c1.leaves])
990991
elif c2.get_head_name() == "System`List":
991-
return Expression("List", *[distance(c1, c) for c in c2.leaves])
992+
return Expression(SymbolList, *[distance(c1, c) for c in c2.leaves])
992993
else:
993994
return distance(c1, c2)
994995
except ColorError:
@@ -1436,7 +1437,7 @@ def do_init(self, graphics, points):
14361437
leaves = points.leaves
14371438
self.multi_parts = True
14381439
else:
1439-
leaves = [Expression("List", *points.leaves)]
1440+
leaves = [Expression(SymbolList, *points.leaves)]
14401441
self.multi_parts = False
14411442
lines = []
14421443
for leaf in leaves:
@@ -1492,7 +1493,7 @@ def init(self, graphics, style, item=None):
14921493
points = item.leaves[0]
14931494
if points.has_form("List", None) and len(points.leaves) != 0:
14941495
if all(not leaf.has_form("List", None) for leaf in points.leaves):
1495-
points = Expression("List", points)
1496+
points = Expression(SymbolList, points)
14961497
self.do_init(graphics, points)
14971498
else:
14981499
raise BoxConstructError
@@ -1890,7 +1891,7 @@ def process_option(self, name, value):
18901891
self.vertex_colors = [[black] * len(line) for line in self.lines]
18911892
colors = value.leaves
18921893
if not self.multi_parts:
1893-
colors = [Expression("List", *colors)]
1894+
colors = [Expression(SymbolList, *colors)]
18941895
for line_index, line in enumerate(self.lines):
18951896
if line_index >= len(colors):
18961897
break
@@ -2046,7 +2047,7 @@ def vertices():
20462047
)
20472048

20482049
new_item = Expression(
2049-
"RegularPolygonBox", Expression("List", *list(vertices()))
2050+
"RegularPolygonBox", Expression(SymbolList, *list(vertices()))
20502051
)
20512052
else:
20522053
raise BoxConstructError
@@ -3525,7 +3526,7 @@ def apply(self, colors, u, evaluation):
35253526
if not colors:
35263527
raise ColorError
35273528
except ColorError:
3528-
evaluation.message("Blend", "arg", Expression("List", colors_orig))
3529+
evaluation.message("Blend", "arg", Expression(SymbolList, colors_orig))
35293530
return
35303531

35313532
if u.has_form("List", None):
@@ -3546,7 +3547,7 @@ def apply(self, colors, u, evaluation):
35463547
use_list = False
35473548
if values is None:
35483549
return evaluation.message(
3549-
"Blend", "argl", u, Expression("List", colors_orig)
3550+
"Blend", "argl", u, Expression(SymbolList, colors_orig)
35503551
)
35513552

35523553
if use_list:

mathics/builtin/graphics3d.py

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import numbers
99
from mathics.version import __version__ # noqa used in loading to check consistency.
10-
from mathics.core.expression import Expression, from_python, system_symbols_dict
10+
from mathics.core.expression import Expression, from_python, system_symbols_dict, SymbolList
1111
from mathics.builtin.base import BoxConstructError, Builtin, InstanceableBuiltin
1212
from .graphics import (
1313
Graphics,
@@ -1026,81 +1026,81 @@ def apply_full(self, xmin, ymin, zmin, xmax, ymax, zmax, evaluation):
10261026
# X
10271027
Expression(
10281028
"List",
1029-
Expression("List", xmin, ymin, zmin),
1030-
Expression("List", xmin, ymax, zmin),
1031-
Expression("List", xmin, ymax, zmax),
1029+
Expression(SymbolList, xmin, ymin, zmin),
1030+
Expression(SymbolList, xmin, ymax, zmin),
1031+
Expression(SymbolList, xmin, ymax, zmax),
10321032
),
10331033
Expression(
10341034
"List",
1035-
Expression("List", xmin, ymin, zmin),
1036-
Expression("List", xmin, ymin, zmax),
1037-
Expression("List", xmin, ymax, zmax),
1035+
Expression(SymbolList, xmin, ymin, zmin),
1036+
Expression(SymbolList, xmin, ymin, zmax),
1037+
Expression(SymbolList, xmin, ymax, zmax),
10381038
),
10391039
Expression(
10401040
"List",
1041-
Expression("List", xmax, ymin, zmin),
1042-
Expression("List", xmax, ymax, zmin),
1043-
Expression("List", xmax, ymax, zmax),
1041+
Expression(SymbolList, xmax, ymin, zmin),
1042+
Expression(SymbolList, xmax, ymax, zmin),
1043+
Expression(SymbolList, xmax, ymax, zmax),
10441044
),
10451045
Expression(
10461046
"List",
1047-
Expression("List", xmax, ymin, zmin),
1048-
Expression("List", xmax, ymin, zmax),
1049-
Expression("List", xmax, ymax, zmax),
1047+
Expression(SymbolList, xmax, ymin, zmin),
1048+
Expression(SymbolList, xmax, ymin, zmax),
1049+
Expression(SymbolList, xmax, ymax, zmax),
10501050
),
10511051
# Y
10521052
Expression(
10531053
"List",
1054-
Expression("List", xmin, ymin, zmin),
1055-
Expression("List", xmax, ymin, zmin),
1056-
Expression("List", xmax, ymin, zmax),
1054+
Expression(SymbolList, xmin, ymin, zmin),
1055+
Expression(SymbolList, xmax, ymin, zmin),
1056+
Expression(SymbolList, xmax, ymin, zmax),
10571057
),
10581058
Expression(
10591059
"List",
1060-
Expression("List", xmin, ymin, zmin),
1061-
Expression("List", xmin, ymin, zmax),
1062-
Expression("List", xmax, ymin, zmax),
1060+
Expression(SymbolList, xmin, ymin, zmin),
1061+
Expression(SymbolList, xmin, ymin, zmax),
1062+
Expression(SymbolList, xmax, ymin, zmax),
10631063
),
10641064
Expression(
10651065
"List",
1066-
Expression("List", xmin, ymax, zmin),
1067-
Expression("List", xmax, ymax, zmin),
1068-
Expression("List", xmax, ymax, zmax),
1066+
Expression(SymbolList, xmin, ymax, zmin),
1067+
Expression(SymbolList, xmax, ymax, zmin),
1068+
Expression(SymbolList, xmax, ymax, zmax),
10691069
),
10701070
Expression(
10711071
"List",
1072-
Expression("List", xmin, ymax, zmin),
1073-
Expression("List", xmin, ymax, zmax),
1074-
Expression("List", xmax, ymax, zmax),
1072+
Expression(SymbolList, xmin, ymax, zmin),
1073+
Expression(SymbolList, xmin, ymax, zmax),
1074+
Expression(SymbolList, xmax, ymax, zmax),
10751075
),
10761076
# Z
10771077
Expression(
10781078
"List",
1079-
Expression("List", xmin, ymin, zmin),
1080-
Expression("List", xmin, ymax, zmin),
1081-
Expression("List", xmax, ymax, zmin),
1079+
Expression(SymbolList, xmin, ymin, zmin),
1080+
Expression(SymbolList, xmin, ymax, zmin),
1081+
Expression(SymbolList, xmax, ymax, zmin),
10821082
),
10831083
Expression(
10841084
"List",
1085-
Expression("List", xmin, ymin, zmin),
1086-
Expression("List", xmax, ymin, zmin),
1087-
Expression("List", xmax, ymax, zmin),
1085+
Expression(SymbolList, xmin, ymin, zmin),
1086+
Expression(SymbolList, xmax, ymin, zmin),
1087+
Expression(SymbolList, xmax, ymax, zmin),
10881088
),
10891089
Expression(
10901090
"List",
1091-
Expression("List", xmin, ymin, zmax),
1092-
Expression("List", xmin, ymax, zmax),
1093-
Expression("List", xmax, ymax, zmax),
1091+
Expression(SymbolList, xmin, ymin, zmax),
1092+
Expression(SymbolList, xmin, ymax, zmax),
1093+
Expression(SymbolList, xmax, ymax, zmax),
10941094
),
10951095
Expression(
10961096
"List",
1097-
Expression("List", xmin, ymin, zmax),
1098-
Expression("List", xmax, ymin, zmax),
1099-
Expression("List", xmax, ymax, zmax),
1097+
Expression(SymbolList, xmin, ymin, zmax),
1098+
Expression(SymbolList, xmax, ymin, zmax),
1099+
Expression(SymbolList, xmax, ymax, zmax),
11001100
),
11011101
]
11021102

1103-
return Expression("Polygon", Expression("List", *polygons))
1103+
return Expression("Polygon", Expression(SymbolList, *polygons))
11041104

11051105
def apply_min(self, xmin, ymin, zmin, evaluation):
11061106
"Cuboid[{xmin_, ymin_, zmin_}]"

0 commit comments

Comments
 (0)