Skip to content

Commit c6e5d28

Browse files
authored
Rename element order values with _ELT_ORDER suffix (#1508)
My beef with the suffix `_SORT_KEY` is that it is vague (what is sorted, and why?). Also, we use the `_SORT_KEY` suffix for the pattern selection precedence this has nothing to do with element ordering. The `_ELT_ORDER` suffix aims to make things clearer and less ambiguous.
1 parent 33fac2b commit c6e5d28

File tree

6 files changed

+36
-35
lines changed

6 files changed

+36
-35
lines changed

mathics/builtin/compilation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from mathics.core.element import ImmutableValueMixin
2626
from mathics.core.evaluation import Evaluation
2727
from mathics.core.expression import Expression
28-
from mathics.core.keycomparable import LITERAL_EXPRESSION_SORT_KEY
28+
from mathics.core.keycomparable import LITERAL_EXPRESSION_ELT_ORDER
2929
from mathics.core.symbols import Atom, Symbol, SymbolFalse, SymbolTrue
3030
from mathics.core.systemsymbols import SymbolCompiledFunction
3131

@@ -146,7 +146,7 @@ def element_order(self) -> tuple:
146146
lexicographically.
147147
148148
"""
149-
return (LITERAL_EXPRESSION_SORT_KEY, hex(id(self)))
149+
return (LITERAL_EXPRESSION_ELT_ORDER, hex(id(self)))
150150

151151
@property
152152
def pattern_precedence(self) -> tuple:

mathics/builtin/image/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from mathics.core.builtin import AtomBuiltin, String
1313
from mathics.core.evaluation import Evaluation
1414
from mathics.core.expression import Expression
15-
from mathics.core.keycomparable import IMAGE_EXPRESSION_SORT_KEY
15+
from mathics.core.keycomparable import IMAGE_EXPRESSION_ELT_ORDER
1616
from mathics.core.list import ListExpression
1717
from mathics.core.systemsymbols import SymbolImage, SymbolRule
1818
from mathics.eval.image import image_pixels, pixels_as_float, pixels_as_ubyte
@@ -122,7 +122,7 @@ def element_order(self) -> tuple:
122122
# and adding two extra fields: the length in the 5th position,
123123
# and a hash in the 6th place.
124124
return (
125-
IMAGE_EXPRESSION_SORT_KEY,
125+
IMAGE_EXPRESSION_ELT_ORDER,
126126
SymbolImage,
127127
len(self.pixels),
128128
tuple(),

mathics/core/atoms.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
from mathics.core.element import BoxElementMixin, ImmutableValueMixin
1414
from mathics.core.keycomparable import (
15-
BASIC_ATOM_BYTEARRAY_SORT_KEY,
16-
BASIC_ATOM_NUMBER_SORT_KEY,
17-
BASIC_ATOM_STRING_SORT_KEY,
15+
BASIC_ATOM_BYTEARRAY_ELT_ORDER,
16+
BASIC_ATOM_NUMBER_ELT_ORDER,
17+
BASIC_ATOM_STRING_ELT_ORDER,
1818
)
1919
from mathics.core.number import (
2020
FP_MANTISA_BINARY_DIGITS,
@@ -91,7 +91,7 @@ def element_order(self) -> tuple:
9191
of an expression. The tuple is ultimately compared lexicographically.
9292
"""
9393
return (
94-
BASIC_ATOM_NUMBER_SORT_KEY,
94+
BASIC_ATOM_NUMBER_ELT_ORDER,
9595
self.value,
9696
0,
9797
1,
@@ -722,7 +722,7 @@ def element_order(self) -> tuple:
722722
of an expression. The tuple is ultimately compared lexicographically.
723723
"""
724724
return (
725-
BASIC_ATOM_BYTEARRAY_SORT_KEY,
725+
BASIC_ATOM_BYTEARRAY_ELT_ORDER,
726726
self.value,
727727
"utf-8",
728728
0,
@@ -887,7 +887,7 @@ def element_order(self) -> tuple:
887887
of an expression. The tuple is ultimately compared lexicographically.
888888
"""
889889
return (
890-
BASIC_ATOM_NUMBER_SORT_KEY,
890+
BASIC_ATOM_NUMBER_ELT_ORDER,
891891
self.real.element_order[1],
892892
self.imag.element_order[1],
893893
1,
@@ -1049,7 +1049,7 @@ def element_order(self) -> tuple:
10491049
"""
10501050
# HACK: otherwise "Bus error" when comparing 1==1.
10511051
return (
1052-
BASIC_ATOM_NUMBER_SORT_KEY,
1052+
BASIC_ATOM_NUMBER_ELT_ORDER,
10531053
sympy.Float(self.value),
10541054
0,
10551055
1,
@@ -1140,7 +1140,7 @@ def element_order(self) -> tuple:
11401140
of an expression. The tuple is ultimately compared lexicographically.
11411141
"""
11421142
return (
1143-
BASIC_ATOM_STRING_SORT_KEY,
1143+
BASIC_ATOM_STRING_ELT_ORDER,
11441144
self.value,
11451145
0,
11461146
1,

mathics/core/expression.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@
4040
from mathics.core.evaluation import Evaluation
4141
from mathics.core.interrupt import ReturnInterrupt
4242
from mathics.core.keycomparable import (
43-
BASIC_EXPRESSION_SORT_KEY,
44-
BASIC_NUMERIC_EXPRESSION_SORT_KEY,
45-
GENERAL_EXPRESSION_SORT_KEY,
46-
GENERAL_NUMERIC_EXPRESSION_SORT_KEY,
43+
BASIC_EXPRESSION_ELT_ORDER,
44+
BASIC_NUMERIC_EXPRESSION_ELT_ORDER,
45+
GENERAL_EXPRESSION_ELT_ORDER,
46+
GENERAL_NUMERIC_EXPRESSION_ELT_ORDER,
4747
Monomial,
4848
)
4949
from mathics.core.structure import LinkedStructure
@@ -897,7 +897,7 @@ def element_order(self) -> tuple:
897897
of an expression. The tuple is ultimately compared lexicographically.
898898
"""
899899
"""
900-
General sort key structure:
900+
General element order key structure:
901901
0: 1/2: Numeric / General Expression
902902
1: 2/3 Special arithmetic (Times / Power) / General Expression
903903
2: Element: Head
@@ -932,9 +932,9 @@ def element_order(self) -> tuple:
932932
if exps:
933933
return (
934934
(
935-
BASIC_NUMERIC_EXPRESSION_SORT_KEY
935+
BASIC_NUMERIC_EXPRESSION_ELT_ORDER
936936
if self.is_numeric()
937-
else BASIC_EXPRESSION_SORT_KEY
937+
else BASIC_EXPRESSION_ELT_ORDER
938938
),
939939
Monomial(exps),
940940
1,
@@ -945,9 +945,9 @@ def element_order(self) -> tuple:
945945
else:
946946
return (
947947
(
948-
GENERAL_NUMERIC_EXPRESSION_SORT_KEY
948+
GENERAL_NUMERIC_EXPRESSION_ELT_ORDER
949949
if self.is_numeric()
950-
else GENERAL_EXPRESSION_SORT_KEY
950+
else GENERAL_EXPRESSION_ELT_ORDER
951951
),
952952
head,
953953
len(self._elements),

mathics/core/keycomparable.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -272,16 +272,17 @@ def __ne__(self, other) -> bool:
272272
) # Used as the last element in the third field.
273273

274274

275-
### SORT_KEYS prefix for expression_order
275+
### _ELT_ORDER suffixes are used in element ordering and
276+
### Expression.element_order().
276277

277-
BASIC_ATOM_NUMBER_SORT_KEY = 0x00
278-
BASIC_ATOM_STRING_SORT_KEY = 0x01
279-
BASIC_ATOM_BYTEARRAY_SORT_KEY = 0x02
280-
LITERAL_EXPRESSION_SORT_KEY = 0x03
278+
BASIC_ATOM_NUMBER_ELT_ORDER = 0x00
279+
BASIC_ATOM_STRING_ELT_ORDER = 0x01
280+
BASIC_ATOM_BYTEARRAY_ELT_ORDER = 0x02
281+
LITERAL_EXPRESSION_ELT_ORDER = 0x03
281282

282-
BASIC_NUMERIC_EXPRESSION_SORT_KEY = 0x12
283-
GENERAL_NUMERIC_EXPRESSION_SORT_KEY = 0x13
284-
IMAGE_EXPRESSION_SORT_KEY = 0x13
283+
BASIC_NUMERIC_EXPRESSION_ELT_ORDER = 0x12
284+
GENERAL_NUMERIC_EXPRESSION_ELT_ORDER = 0x13
285+
IMAGE_EXPRESSION_ELT_ORDER = 0x13
285286

286-
BASIC_EXPRESSION_SORT_KEY = 0x22
287-
GENERAL_EXPRESSION_SORT_KEY = 0x23
287+
BASIC_EXPRESSION_ELT_ORDER = 0x22
288+
GENERAL_EXPRESSION_ELT_ORDER = 0x23

mathics/core/symbols.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
from mathics.core.keycomparable import (
1818
BASIC_ATOM_PATTERN_SORT_KEY,
19-
BASIC_EXPRESSION_SORT_KEY,
20-
BASIC_NUMERIC_EXPRESSION_SORT_KEY,
19+
BASIC_EXPRESSION_ELT_ORDER,
20+
BASIC_NUMERIC_EXPRESSION_ELT_ORDER,
2121
Monomial,
2222
)
2323
from mathics.eval.tracing import trace_evaluate
@@ -558,9 +558,9 @@ def element_order(self) -> tuple:
558558
"""
559559
return (
560560
(
561-
BASIC_NUMERIC_EXPRESSION_SORT_KEY
561+
BASIC_NUMERIC_EXPRESSION_ELT_ORDER
562562
if self.is_numeric()
563-
else BASIC_EXPRESSION_SORT_KEY
563+
else BASIC_EXPRESSION_ELT_ORDER
564564
),
565565
Monomial({self.name: 1}),
566566
0,

0 commit comments

Comments
 (0)