diff --git a/mathics/autoload/forms/StandardForm.m b/mathics/autoload/forms/StandardForm.m new file mode 100644 index 000000000..425a50422 --- /dev/null +++ b/mathics/autoload/forms/StandardForm.m @@ -0,0 +1,24 @@ +(* This implements StandardForm boxing rules in Mathics *) + + +Begin["System`"] + +(******************************************************************************************) +(* Common Boxing routines that are used by many forms. FIXME: place this in another file. *) +(******************************************************************************************) + +(* Change RadBox to RadicalBox. We use RadBox to make it clear that + the below code was a read-in from a file and not some pre-existing + code. *) +Attributes[CubeRootRadicalBox] = HoldAll; +Attributes[RadBox] = HoldAll; +CubeRootRadicalBox[expr_, form_]:= RadBox[MakeBoxes[expr, form], 3]; + +(******************************************************************************************) +(* StandardForm Boxing Rules *) +(******************************************************************************************) + +MakeBoxes[CubeRoot[expr_], StandardForm] := CubeRootRadicalBox[expr, StandardForm]; +(*All the other StandardForm boxing routines... *) + +End[] diff --git a/mathics/builtin/arithfns/basic.py b/mathics/builtin/arithfns/basic.py index a3c39c8b5..466ae53b3 100644 --- a/mathics/builtin/arithfns/basic.py +++ b/mathics/builtin/arithfns/basic.py @@ -112,9 +112,6 @@ class CubeRoot(Builtin): rules = { "CubeRoot[n_?NumberQ]": "If[n > 0, Power[n, Divide[1, 3]], Times[-1, Power[Times[-1, n], Divide[1, 3]]]]", "CubeRoot[n_]": "Power[n, Divide[1, 3]]", - "MakeBoxes[CubeRoot[x_], f:StandardForm|TraditionalForm]": ( - "RadicalBox[MakeBoxes[x, f], 3]" - ), } summary_text = "cubed root" diff --git a/mathics/builtin/assignments/clear.py b/mathics/builtin/assignments/clear.py index 471eb5692..44f00cc59 100644 --- a/mathics/builtin/assignments/clear.py +++ b/mathics/builtin/assignments/clear.py @@ -193,7 +193,6 @@ class Remove(Builtin): """ attributes = A_HOLD_ALL | A_LOCKED | A_PROTECTED - precedence = 670 summary_text = "remove the definition of a symbol" diff --git a/mathics/builtin/assignments/internals.py b/mathics/builtin/assignments/internals.py index 132d9e390..2d8804a63 100644 --- a/mathics/builtin/assignments/internals.py +++ b/mathics/builtin/assignments/internals.py @@ -558,6 +558,24 @@ 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=False) + definitions = evaluation.definitions + definitions.add_rule("System`MakeBoxes", makeboxes_rule, "down") + # 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) @@ -685,23 +703,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): diff --git a/mathics/builtin/base.py b/mathics/builtin/base.py index 57a8473eb..b6faf3aac 100644 --- a/mathics/builtin/base.py +++ b/mathics/builtin/base.py @@ -283,15 +283,16 @@ def check_options(options_to_check, evaluation): rules.append( BuiltinRule(name, pattern, function, check_options, system=True) ) - for pattern, replace in self.rules.items(): - 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 if name != "System`MakeBoxes": new_rules = [] for rule in rules: diff --git a/mathics/core/definitions.py b/mathics/core/definitions.py index def6b1a93..46aa0c31c 100644 --- a/mathics/core/definitions.py +++ b/mathics/core/definitions.py @@ -169,7 +169,14 @@ def __init__( if name.startswith("Global`"): raise ValueError("autoload defined %s." % name) - self.builtin.update(self.user) + # The idea here is that all the symbols loaded in + # autoload become converted in builtin. + # For some reason, if we do not do this here, + # `Export` and `Import` fails. + # TODO: investigate why. + for name in self.user: + self.builtin[name] = self.get_definition(name) + self.user = {} self.clear_cache()