-
-
Notifications
You must be signed in to change notification settings - Fork 61
More suggestions and fixes #595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -167,6 +167,36 @@ def do_clear(self, definition): | |
| definition.defaultvalues = [] | ||
|
|
||
|
|
||
| class Remove(Builtin): | ||
| """ | ||
| <dl> | ||
| <dt>'Remove[$x$]' | ||
| <dd>removes the definition associated to $x$. | ||
| </dl> | ||
| >> a := 2 | ||
| >> Names["Global`a"] | ||
| = {a} | ||
| >> Remove[a] | ||
| >> Names["Global`a"] | ||
| = {} | ||
| """ | ||
|
|
||
| attributes = A_HOLD_ALL | A_LOCKED | A_PROTECTED | ||
| messages = {"ssym": "`1` is not a symbol."} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see "ssym" defined a number of places: I think if we just add it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's do it in the next round. |
||
| precedence = 670 | ||
| summary_text = "remove the definition of a symbol" | ||
|
|
||
| def eval(self, symb, evaluation): | ||
| """Remove[symb_]""" | ||
| if isinstance(symb, Symbol): | ||
| evaluation.definitions.reset_user_definition(symb.name) | ||
| elif isinstance(symb, String): | ||
| evaluation.definitions.reset_user_definition(symb.value) | ||
| else: | ||
| evaluation.message(self.get_name(), "ssym", symb) | ||
| return SymbolNull | ||
|
|
||
|
|
||
| class Unset(PostfixOperator): | ||
| """ | ||
| <dl> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -567,9 +567,12 @@ def process_assign_makeboxes(self, lhs, rhs, evaluation, tags, upset): | |
| # 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) | ||
|
|
||
| makeboxes_rule = Rule(lhs, rhs, system=False) | ||
| definitions = evaluation.definitions | ||
| definitions.add_rule("System`MakeBoxes", makeboxes_rule, "down") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the reason, "add_rule" takes a string here a historical artifact, or is there a reason why a string is better than a Symbol? Semantically, Symbol is the more precise entity, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Symbol would be more precise, but now, the key in |
||
| # makeboxes_defs = evaluation.definitions.builtin["System`MakeBoxes"] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. During a session, we should not touch the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. Thanks for the explanation and fix of what is wrong. Why is is there a definition inside the symbol at all? My gut feeling is that if this is removed, then Symbol is more like a Lisp Symbol (and we start to see more speed improvement ;-). But to start out with, let me narrow this question for just SymbolMakeBoxes symbols. The definitions we are adding are (or will be) the first ones added, so what is the value of having any rule associated with SymbolMakeBoxes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure to understand your question. A Then we have Definitions, that we can associate to Symbols. We could have more than one Definition for the same Symbol. A Definition stores the attributes of a Symbol, together with a set (or several sets) of replacement rules. Then, we have certain actions we can perform over these elements (Atoms and Expressions). Replacements are one of these the possible actions. In a replacement, we take an element, and we produce a new element following certain rules, and eventually, producing certain side actions on the system (like write a file, run a system command). Another kind of actions that we can perform over an Expression is to "evaluate" it. For doing it,
OK. I am not sure to understand the question. I will try again to provide a description of the elements, and probably you can reformulate them in more standard/generic/LISP-compliant terms. Symbols do not have a Definition "inside". A Then, we can associate a Over an To If we can think about a unique evaluation loop, certain symbols lead to specific evaluation patterns, involving following a different order in the application of the rules. One example are the expressions of the form
In the current implementation, the evaluation of In Master, all the MakeBoxes rules are stored as builtin rules. In Master, if we set a MakeBoxes rule in an autoload file, these other definitions are erased, and the evaluation gets broken. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Let me review how the code works now, used to work, look at WMA docs and so on. It may take a little time though. |
||
| # makeboxes_defs.add_rule(makeboxes_rule) | ||
| return True | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it a fair hypothesis that if Export and Import fail, it may be because the are looking inside the builtin rather than the user definitions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is... |
||
| for name in self.user: | ||
| self.builtin[name] = self.get_definition(name) | ||
|
|
||
| self.user = {} | ||
| self.clear_cache() | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this may be wordy, but how about
RadicalCubeRootBox?I made a mistake here in using the generic term "Radical" when what we are referring to is is a cube root radical.
"radical" box" by itself is too general because this is not a rule for a square root, and "cube box" is too general too because exponent 1/3 is a cube root as well, so what we want to convey is the radical form of a cube root.
Note that in the names here, we are referring somewhat to the visual form, e.g. "radical" boxing as opposed to "power" boxing even though many times there is a box that surrounds the argument.
The name though will influence formatting later on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point, wordy is OK.