Skip to content
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

using a private symbol to store the state inside DisplayForm. #617

Open
wants to merge 3 commits into
base: DisplayForm
Choose a base branch
from

Conversation

mmatera
Copy link
Contributor

@mmatera mmatera commented Nov 13, 2022

This is the alternative version. This makes the control variable "hackable" from inside the mathics session (we can read it) but avoids that the user overwrite the value (because it is protected and locked).

previous_df, evaluation.in_display_form = evaluation.in_display_form, True

old_value_in_display_form = SYMBOL_FORMATBOXES.evaluate(evaluation)
evaluation.definitions.set_ownvalue(SYMBOL_FORMATBOXES.name, SymbolTrue)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice that here we can not use the higher level way

Expression(SymbolSet, SYMBOL_NO_FORMATBOXES, SymbolTrue).evaluate(evaluation)

because the attributes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The drawbacks of this approach are that the access to the attribute is slower, and the code to set the context is larger and weirder than just setting an attribute.

@mmatera mmatera changed the title using a private symbol to store the state. using a private symbol to store the state inside DisplayForm. Nov 13, 2022
class PrivateSymbolThatControlsTheStateOfDisplayForm(Builtin):
"""
<dl>
<dt>'PrivateSymbolThatControlsTheStateOfDisplayForm'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small thing - please indent nested <dt>.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rocky, the question is, do you think that this is a better approach?

Copy link
Member

@rocky rocky Nov 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mmatera good question. I have to think about it. What I'd be looking for is clues in the WMA code.

Think of this like the way a physicist would. We have two hypotheses for how this might have been coded in WMA. Is there a test that distinguishes these? Suppose we hypothesize that WMA follows the WMA way to do this, what test could we come up with that would distinguish the implementations? (Likewise for the other way to code)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ja, it is a curious request! Because it is exactly as this physicist is trying to distinguish what is the implementation in WMA :)

Look at this, for example,

imagen

If I believe in this output, I have to assume that there is not a private hidden symbol but an internal variable inside the kernel.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok - I trust your conclusion, but I don't follow it. The output above doesn't indicate anything to me one way or another. Please break it down for a novice.

If it were implemented as a private hidden symbol what then would you expect to see?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably implement TracePrint so that we can check correspondence easier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect an evaluation for the corresponding hidden symbol. This is an example in which internal variables are used:

imagen

(I just cut the first lines)

Notice the use of symbols in hidden contexts (BoxFormls, IntegrateDumpTestLimits, BoxFormopt). Tracing MakeBoxes[DisplayForm[...]]` I do not see such kind of symbols in hidden contexts.

@@ -396,7 +403,7 @@ def apply_general(self, expr, f, evaluation):
if isinstance(expr, BoxElementMixin):
# If we are inside a DisplayForm block,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really just DisplayForm that could do this? There are no other forms that are like this. Or this isn't something Form creator might want to do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By now, this is the only case. This could also be a way to implement InputForm/OutputForm and the other non-standard print forms but setting a different control symbol. In any case, I am not sure that this way is better than the one I proposed before.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and the other non-standard print forms

What makes a print form "non-standard"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MakeBoxes accepts StandardForm|TraditionalForm as the second parameter. In some way, when you evaluate

MakeBoxes[OutputForm[expr], StandardForm]

Makeboxes first applies the format rules associated with OutputForm to expr and its subexpressions. Then, the reference to OutputForm are lost in the expression, but in some way, MakeBoxes knows that has to apply the OutputForm makeboxes rules to the inner expressions. One way to simulate this behavior would be to set a state variable that remembers that we are using OutputForm rules. This is not the way in which I think we should implement this, but it is a possibility.

Copy link
Member

@rocky rocky Nov 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but in some way, MakeBoxes knows that has to apply the OutputForm makeboxes rules to the inner expressions.

https://reference.wolfram.com/language/ref/TraditionalForm.html says:

TraditionalForm inserts invisible TagBox and InterpretationBox constructs into the box form of output it generates, to allow unique interpretation.tionalForm

Does this provide a mechanism for how to do this? If so, possibly the same is could done for StandardForm (and is done but just not mentioned). Sometimes it happens that only in implementing the second thing of a kind the general mechanism, and the first is done in a more hacky way is not retrofitted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants