Skip to content

Commit

Permalink
my suggestions (#592)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatera authored and rocky committed Nov 6, 2022
1 parent 4dd1ca9 commit 8713078
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 38 deletions.
58 changes: 29 additions & 29 deletions mathics/builtin/assignments/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,21 @@ def process_assign_format(self, lhs, rhs, evaluation, tags, upset):
return count > 0


def process_assign_makeboxes(self, lhs, rhs, evaluation, tags, upset):
# FIXME: the below is a big hack.
# Currently MakeBoxes boxing is implemented as a bunch of rules.
# See mathics.builtin.base contribute().
# I think we want to change this so it works like normal SetDelayed
# That is:
# MakeBoxes[CubeRoot, StandardForm] := RadicalBox[3, StandardForm]
# rather than:
# MakeBoxes[CubeRoot, StandardForm] -> RadicalBox[3, StandardForm]
makeboxes_rule = Rule(lhs, rhs, system=True)
makeboxes_defs = evaluation.definitions.builtin["System`MakeBoxes"]
makeboxes_defs.add_rule(makeboxes_rule)
return True


def process_assign_messagename(self, lhs, rhs, evaluation, tags, upset):
lhs, condition = unroll_conditions(lhs)
lhs, rhs = unroll_patterns(lhs, rhs, evaluation)
Expand Down Expand Up @@ -685,23 +700,24 @@ def process_tags_and_upset_allow_custom(tags, upset, self, lhs, evaluation):

class _SetOperator:
special_cases = {
"System`OwnValues": process_assign_definition_values,
"System`DownValues": process_assign_definition_values,
"System`SubValues": process_assign_definition_values,
"System`UpValues": process_assign_definition_values,
"System`NValues": process_assign_definition_values,
"System`DefaultValues": process_assign_definition_values,
"System`Messages": process_assign_definition_values,
"System`Attributes": process_assign_attributes,
"System`Options": process_assign_options,
"System`$RandomState": process_assign_random_state,
"System`$Context": process_assign_context,
"System`$ContextPath": process_assign_context_path,
"System`N": process_assign_n,
"System`NumericQ": process_assign_numericq,
"System`MessageName": process_assign_messagename,
"System`$RandomState": process_assign_random_state,
"System`Attributes": process_assign_attributes,
"System`Default": process_assign_default,
"System`DefaultValues": process_assign_definition_values,
"System`DownValues": process_assign_definition_values,
"System`Format": process_assign_format,
"System`MakeBoxes": process_assign_makeboxes,
"System`MessageName": process_assign_messagename,
"System`Messages": process_assign_definition_values,
"System`N": process_assign_n,
"System`NValues": process_assign_definition_values,
"System`NumericQ": process_assign_numericq,
"System`Options": process_assign_options,
"System`OwnValues": process_assign_definition_values,
"System`SubValues": process_assign_definition_values,
"System`UpValues": process_assign_definition_values,
}

def assign_elementary(self, lhs, rhs, evaluation, tags=None, upset=False):
Expand Down Expand Up @@ -755,21 +771,5 @@ def assign(self, lhs, rhs, evaluation):
return False
indices = lhs.elements[1:]
return walk_parts([rule.replace], indices, evaluation, rhs)

# FIXME: the below is a big hack.
# Currently MakeBoxes boxing is implemented as a bunch of rules.
# See mathics.builtin.base contribute().
# I think we want to change this so it works like normal SetDelayed
# That is:
# MakeBoxes[CubeRoot, StandardForm] := RadicalBox[3, StandardForm]
# rather than:
# MakeBoxes[CubeRoot, StandardForm] -> RadicalBox[3, StandardForm]
elif lhs.get_head_name() == "System`MakeBoxes":
makeboxes_rule = Rule(lhs, rhs, system=True)
makeboxes_defs = defs.builtin["System`MakeBoxes"]
makeboxes_defs.add_rule(makeboxes_rule)
# FIXME: what should be the result?
return makeboxes_rule

else:
return self.assign_elementary(lhs, rhs, evaluation)
16 changes: 7 additions & 9 deletions mathics/builtin/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,13 @@ def check_options(options_to_check, evaluation):
rules.append(
BuiltinRule(name, pattern, function, check_options, system=True)
)
for pattern, replace in self.rules.items():
# FIXME: sometimes pattern is a string and sometimes a BaseElement?
# This seems wrong.
if not isinstance(pattern, BaseElement):
pattern = pattern % {"name": name}
pattern = parse_builtin_rule(pattern, definition_class)
replace = replace % {"name": name}
# FIXME: Should system=True be system=not is_pymodule ?
rules.append(Rule(pattern, parse_builtin_rule(replace), system=True))
for pattern_str, replace_str in self.rules.items():
pattern_str = pattern_str % {"name": name}
pattern = parse_builtin_rule(pattern_str, definition_class)
replace_str = replace_str % {"name": name}
rules.append(
Rule(pattern, parse_builtin_rule(replace_str), system=not is_pymodule)
)

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

0 comments on commit 8713078

Please sign in to comment.