Skip to content

Commit 8713078

Browse files
mmaterarocky
authored andcommitted
my suggestions (#592)
1 parent 4dd1ca9 commit 8713078

2 files changed

Lines changed: 36 additions & 38 deletions

File tree

mathics/builtin/assignments/internals.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,21 @@ def process_assign_format(self, lhs, rhs, evaluation, tags, upset):
558558
return count > 0
559559

560560

561+
def process_assign_makeboxes(self, lhs, rhs, evaluation, tags, upset):
562+
# FIXME: the below is a big hack.
563+
# Currently MakeBoxes boxing is implemented as a bunch of rules.
564+
# See mathics.builtin.base contribute().
565+
# I think we want to change this so it works like normal SetDelayed
566+
# That is:
567+
# MakeBoxes[CubeRoot, StandardForm] := RadicalBox[3, StandardForm]
568+
# rather than:
569+
# MakeBoxes[CubeRoot, StandardForm] -> RadicalBox[3, StandardForm]
570+
makeboxes_rule = Rule(lhs, rhs, system=True)
571+
makeboxes_defs = evaluation.definitions.builtin["System`MakeBoxes"]
572+
makeboxes_defs.add_rule(makeboxes_rule)
573+
return True
574+
575+
561576
def process_assign_messagename(self, lhs, rhs, evaluation, tags, upset):
562577
lhs, condition = unroll_conditions(lhs)
563578
lhs, rhs = unroll_patterns(lhs, rhs, evaluation)
@@ -685,23 +700,24 @@ def process_tags_and_upset_allow_custom(tags, upset, self, lhs, evaluation):
685700

686701
class _SetOperator:
687702
special_cases = {
688-
"System`OwnValues": process_assign_definition_values,
689-
"System`DownValues": process_assign_definition_values,
690-
"System`SubValues": process_assign_definition_values,
691-
"System`UpValues": process_assign_definition_values,
692-
"System`NValues": process_assign_definition_values,
693-
"System`DefaultValues": process_assign_definition_values,
694-
"System`Messages": process_assign_definition_values,
695-
"System`Attributes": process_assign_attributes,
696-
"System`Options": process_assign_options,
697-
"System`$RandomState": process_assign_random_state,
698703
"System`$Context": process_assign_context,
699704
"System`$ContextPath": process_assign_context_path,
700-
"System`N": process_assign_n,
701-
"System`NumericQ": process_assign_numericq,
702-
"System`MessageName": process_assign_messagename,
705+
"System`$RandomState": process_assign_random_state,
706+
"System`Attributes": process_assign_attributes,
703707
"System`Default": process_assign_default,
708+
"System`DefaultValues": process_assign_definition_values,
709+
"System`DownValues": process_assign_definition_values,
704710
"System`Format": process_assign_format,
711+
"System`MakeBoxes": process_assign_makeboxes,
712+
"System`MessageName": process_assign_messagename,
713+
"System`Messages": process_assign_definition_values,
714+
"System`N": process_assign_n,
715+
"System`NValues": process_assign_definition_values,
716+
"System`NumericQ": process_assign_numericq,
717+
"System`Options": process_assign_options,
718+
"System`OwnValues": process_assign_definition_values,
719+
"System`SubValues": process_assign_definition_values,
720+
"System`UpValues": process_assign_definition_values,
705721
}
706722

707723
def assign_elementary(self, lhs, rhs, evaluation, tags=None, upset=False):
@@ -755,21 +771,5 @@ def assign(self, lhs, rhs, evaluation):
755771
return False
756772
indices = lhs.elements[1:]
757773
return walk_parts([rule.replace], indices, evaluation, rhs)
758-
759-
# FIXME: the below is a big hack.
760-
# Currently MakeBoxes boxing is implemented as a bunch of rules.
761-
# See mathics.builtin.base contribute().
762-
# I think we want to change this so it works like normal SetDelayed
763-
# That is:
764-
# MakeBoxes[CubeRoot, StandardForm] := RadicalBox[3, StandardForm]
765-
# rather than:
766-
# MakeBoxes[CubeRoot, StandardForm] -> RadicalBox[3, StandardForm]
767-
elif lhs.get_head_name() == "System`MakeBoxes":
768-
makeboxes_rule = Rule(lhs, rhs, system=True)
769-
makeboxes_defs = defs.builtin["System`MakeBoxes"]
770-
makeboxes_defs.add_rule(makeboxes_rule)
771-
# FIXME: what should be the result?
772-
return makeboxes_rule
773-
774774
else:
775775
return self.assign_elementary(lhs, rhs, evaluation)

mathics/builtin/base.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -283,15 +283,13 @@ def check_options(options_to_check, evaluation):
283283
rules.append(
284284
BuiltinRule(name, pattern, function, check_options, system=True)
285285
)
286-
for pattern, replace in self.rules.items():
287-
# FIXME: sometimes pattern is a string and sometimes a BaseElement?
288-
# This seems wrong.
289-
if not isinstance(pattern, BaseElement):
290-
pattern = pattern % {"name": name}
291-
pattern = parse_builtin_rule(pattern, definition_class)
292-
replace = replace % {"name": name}
293-
# FIXME: Should system=True be system=not is_pymodule ?
294-
rules.append(Rule(pattern, parse_builtin_rule(replace), system=True))
286+
for pattern_str, replace_str in self.rules.items():
287+
pattern_str = pattern_str % {"name": name}
288+
pattern = parse_builtin_rule(pattern_str, definition_class)
289+
replace_str = replace_str % {"name": name}
290+
rules.append(
291+
Rule(pattern, parse_builtin_rule(replace_str), system=not is_pymodule)
292+
)
295293

296294
box_rules = []
297295
# FIXME: Why a special case for System`MakeBoxes? Remove this

0 commit comments

Comments
 (0)