-
-
Notifications
You must be signed in to change notification settings - Fork 67
Fix evaluation of InterpretationBox with options #1607
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 2 commits
ae5533f
30b1e71
40a0865
c65a874
a02dec4
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 |
|---|---|---|
|
|
@@ -6,6 +6,10 @@ | |
| symbolic "boxes". | ||
|
|
||
| The routines here assist in boxing at the bottom of the hierarchy, typically found when using in a notebook. | ||
|
|
||
| `Expression` objects having symbols in this module as head, are evaluated to | ||
| `BoxElementMixin` objects. These objects are literal objects, so do not have the method `evaluate`. Text render functions (in `mathics.format`) process `BoxElementMixin` to produce their output. | ||
|
|
||
| """ | ||
| from typing import Tuple | ||
|
|
||
|
|
@@ -14,7 +18,7 @@ | |
| from mathics.core.atoms import String | ||
| from mathics.core.attributes import A_HOLD_ALL_COMPLETE, A_PROTECTED, A_READ_PROTECTED | ||
| from mathics.core.builtin import Builtin | ||
| from mathics.core.element import BaseElement, BoxElementMixin | ||
| from mathics.core.element import BaseElement, BoxElementMixin, EvalMixin | ||
| from mathics.core.evaluation import Evaluation | ||
| from mathics.core.exceptions import BoxConstructError | ||
| from mathics.core.expression import Expression | ||
|
|
@@ -208,6 +212,10 @@ class InterpretationBox(BoxExpression): | |
| """ | ||
|
|
||
| attributes = A_HOLD_ALL_COMPLETE | A_PROTECTED | A_READ_PROTECTED | ||
| options = { | ||
| "Editable": "Automatic", | ||
| "AutoDelete": "Automatic", | ||
| } | ||
| summary_text = "box associated to an input expression" | ||
|
|
||
| def __repr__(self): | ||
|
|
@@ -233,17 +241,26 @@ def elements(self): | |
| ) | ||
| return self._elements | ||
|
|
||
| def eval_create(self, reprs, expr, evaluation): | ||
| """InterpretationBox[reprs_, expr_]""" | ||
| return InterpretationBox(reprs, expr) | ||
| def eval_create(self, reprs, expr, evaluation, options): | ||
| """InterpretationBox[reprs_, expr_, OptionsPattern[]]""" | ||
| # If the first element is not a litera, this | ||
|
rocky marked this conversation as resolved.
Outdated
|
||
| # function evaluates it (because the symbol has | ||
| # the attribute HoldAllComplete, this does not happend | ||
| # in the evaluation loop). Then, if the result is a | ||
| # BoxElementMixin, creates and return instance of `InterpretationBox`. | ||
| if isinstance(reprs, EvalMixin): | ||
| reprs = reprs.evaluate(evaluation) | ||
|
Member
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. What are examples of this code getting used?
Contributor
Author
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. the exampe is in
Member
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. That's generic test code. Where in the YAML though?
Contributor
Author
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, the YAML file contains the examples
Member
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. Yes, I figured that, but anything specific.
Contributor
Author
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. When the evaluation is successful, the final expression shows the options in lexicographical order.
Member
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. Thanks for the information. This is sufficiently complicated and subtle that a comment should be added. I've been trying to think of one, but I am not sure I fully understand. Is the idea that reprs is either some sort of evaluatable expression (or is it just some of StyleBox)? If it is in this former category, then we need to evaluate it to turn it into a box which will process and remove the options?
Contributor
Author
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. This rule converts an
Member
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. Let's add this as a comment. I can do that tomorrow, along with the other small doc changes. There is a lot of code in this PR that feels mysterious and bottom-up, as opposed to there beings some higher-level principle that can be used to derive the details coded. Maybe later we will have a simpler model for expressing InputForm and how that relates
Contributor
Author
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. This mechanism of conversions has been around for a while, but probably requires better documentation. The main idea is that |
||
| if not isinstance(reprs, BoxElementMixin): | ||
| return | ||
| return InterpretationBox(reprs, expr, **options) | ||
|
|
||
| def eval_to_expression1(self, boxexpr, evaluation): | ||
| """ToExpression[boxexpr_InterpretationBox]""" | ||
| return boxexpr.elements[1] | ||
| return boxexpr.expr | ||
|
|
||
| def eval_to_expression2(self, boxexpr, form, evaluation): | ||
| """ToExpression[boxexpr_InterpretationBox, form_]""" | ||
| return boxexpr.elements[1] | ||
| return boxexpr.expr | ||
|
|
||
| def eval_display(self, boxexpr, evaluation): | ||
| """DisplayForm[boxexpr_InterpretationBox]""" | ||
|
|
||
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.
litera -> literal
(I am not seeing the +/- commit button, or I'd suggest a commit.)
Thanks for the additional comments and clarification. This helps a lot.