Skip to content

Commit 4241f5f

Browse files
committed
remove weird form of Infix with list of operators.
1 parent 26f7f51 commit 4241f5f

File tree

2 files changed

+12
-33
lines changed

2 files changed

+12
-33
lines changed

mathics/builtin/layout.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,6 @@ class Infix(Builtin):
175175
>> g[a, b] * c
176176
= c (a # b)
177177
178-
>> Infix[{a, b, c}, {"+", "-"}]
179-
= a + b - c
180-
181178
#> Format[r[items___]] := Infix[If[Length[{items}] > 1, {items}, {ab}], "~"]
182179
#> r[1, 2, 3]
183180
= 1 ~ 2 ~ 3

mathics/builtin/makeboxes.py

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,11 @@ def int_to_s_exp(expr, n):
3939
return s, exp, nonnegative
4040

4141

42-
# FIXME: op should be a string, so remove the Union.
43-
def make_boxes_infix(
44-
elements, op: Union[String, list], precedence: int, grouping, form: Symbol
45-
):
42+
def make_boxes_infix(elements, op: String, precedence: int, grouping, form: Symbol):
4643
result = []
4744
for index, element in enumerate(elements):
4845
if index > 0:
49-
if isinstance(op, list):
50-
result.append(op[index - 1])
51-
else:
52-
result.append(op)
46+
result.append(op)
5347
parenthesized = False
5448
if grouping == "System`NonAssociative":
5549
parenthesized = True
@@ -476,31 +470,19 @@ def format_operator(operator) -> Union[String, BaseElement]:
476470

477471
elements = expr.elements
478472
if len(elements) > 1:
479-
if operator.has_form("List", len(elements) - 1):
480-
operator = [format_operator(op) for op in operator.elements]
481-
return make_boxes_infix(
482-
elements, operator, py_precedence, grouping, form
473+
encoding_rule = evaluation.definitions.get_ownvalue("$CharacterEncoding")
474+
encoding = "UTF8" if encoding_rule is None else encoding_rule.replace.value
475+
op_str = (
476+
operator.value if isinstance(operator, String) else operator.short_name
477+
)
478+
if encoding == "ASCII":
479+
operator = format_operator(
480+
String(operator_to_ascii.get(op_str, op_str))
483481
)
484482
else:
485-
encoding_rule = evaluation.definitions.get_ownvalue(
486-
"$CharacterEncoding"
487-
)
488-
encoding = (
489-
"UTF8" if encoding_rule is None else encoding_rule.replace.value
490-
)
491-
op_str = (
492-
operator.value
493-
if isinstance(operator, String)
494-
else operator.short_name
483+
operator = format_operator(
484+
String(operator_to_unicode.get(op_str, op_str))
495485
)
496-
if encoding == "ASCII":
497-
operator = format_operator(
498-
String(operator_to_ascii.get(op_str, op_str))
499-
)
500-
else:
501-
operator = format_operator(
502-
String(operator_to_unicode.get(op_str, op_str))
503-
)
504486

505487
return make_boxes_infix(elements, operator, py_precedence, grouping, form)
506488

0 commit comments

Comments
 (0)