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

mathics.eval #630

Merged
merged 6 commits into from
Nov 21, 2022
Merged

mathics.eval #630

merged 6 commits into from
Nov 21, 2022

Conversation

mmatera
Copy link
Contributor

@mmatera mmatera commented Nov 20, 2022

Moving evaluators to mathics.eval module

  • adding the module mathics.eval
  • mathics.core.evaluators-> mathics.eval.nevaluator
  • formatter.format_element and related routines -> mathics.eval.makeboxes
  • mathics.builtin.patterns.item_is_free -> mathics.eval.test

If the number of files is quite large, almost all of the changes are just renaming the import modules.
One advantage of this organization is that makes it easier to avoid circular dependencies.

   * adding the module mathics.eval

   * mathics.core.evaluators-> mathics.eval.nevaluator

   * formatter.format_element and related routines -> mathics.eval.makeboxes
@@ -571,7 +571,7 @@ class Power(BinaryOperator, _MPMathFunction):
'Infix[{HoldForm[x], HoldForm[y]}, "^", 590, Right]'
),
("", "x_ ^ y_"): (
"PrecedenceForm[Superscript[OuterPrecedenceForm[HoldForm[x], 590],"
"PrecedenceForm[Superscript[PrecedenceForm[HoldForm[x], 590],"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is something that I guess I have corrected several times...

Copy link
Member

Choose a reason for hiding this comment

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

@mmatera - sorry. .Then let us make sure this gets in!

Copy link
Member

Choose a reason for hiding this comment

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

PS. Another way to make sure this gets in is to create a PR with just this change and it will go through faster.

@mmatera mmatera force-pushed the mathics_eval_module branch from 081f603 to a1bb326 Compare November 20, 2022 21:18
@mmatera mmatera marked this pull request as ready for review November 20, 2022 21:28
@@ -107,7 +107,7 @@ def __init__(
"Global`",
)

from mathics.builtin.pymathics import (
from mathics.eval.pymathics import (
Copy link
Member

Choose a reason for hiding this comment

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

It was my understanding that the idea behind eval was to transition to a model where we could run a sequence of instructions where each instruction corresponds to an eval function right now.

I am not opposed to moving around the functions that load modules or separating pymathics things, but I don't get why the natural place for this is in mathics.eval

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 put it here because is what if follows from evaluating an expression like LoadModule[module]. In any case, this was in mathics.builtin.pymathics and it does not belong there. Maybe it belongs to mathics.core.pymathics.

Copy link
Member

Choose a reason for hiding this comment

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

I put it here because is what if follows from evaluating an expression like LoadModule[module]. In any case, this was in mathics.builtin.pymathics and it does not belong there. Maybe it belongs to mathics.core.pymathics.

Ok. Sure mathics.core or somewhere else is fine. Probably some of the things in as yet not finished mathics.builtin.system_init belong in core as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 5caa0c3

@@ -0,0 +1,106 @@
# -*- coding: utf-8 -*-
Copy link
Member

Choose a reason for hiding this comment

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

I had a comment about this in the other PR that I guess comes after this. Please see that.

@mmatera mmatera force-pushed the mathics_eval_module branch from 7454458 to 5caa0c3 Compare November 21, 2022 01:22
@rocky
Copy link
Member

rocky commented Nov 21, 2022

LGTM. (I assume this will continue pass CI)

@mmatera mmatera merged commit 44a8eaf into master Nov 21, 2022
@mmatera mmatera deleted the mathics_eval_module branch November 21, 2022 01:39
# do_format_*


def do_format(
Copy link
Member

@rocky rocky Nov 21, 2022

Choose a reason for hiding this comment

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

The do_format... names were poorly selected and now that they have moved here moreso.

Better would be just to drop the do_ which doesn't add or do anything for clarity. Things in the eval module are automatic "do-ers". "eval" is a active verb and "format" is also an active verb.

Copy link
Member

@rocky rocky Nov 21, 2022

Choose a reason for hiding this comment

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

Let me explain the do_ convention as I understand it. When mixed with a number of other methods, a method marked do_ is the top-level function to call which presumably calls the other methods in the class that don't have do_. Similarly sometimes it is used as a function outside the class to kick off methods inside the class.

Neither of these situations now applies here.

In general though, if one is using this a lot, it is an indication that the code organization may need to be reworked as was done in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Regarding this, the plan is that this module is going to be reformulated soon. I didn't change the names just to make this PR a little bit shorter and easier to review.

Copy link
Member

Choose a reason for hiding this comment

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

Regarding this, the plan is that this module is going to be reformulated soon. I didn't change the names just to make this PR a little bit shorter and easier to review.

Ok - good to hear we are on the same page here.

I looked again to see if I understand the "plan" and I see this:

formatter.format_element and related routines -> mathics.eval.makeboxes

This doesn't seem right. eval methods should be thought of as instructions.

Boxing is something that could be written purely in Mathics. It is not on the same level as an interpreter instruction. If you want to put boxing routines in a different place, okay But it is not an "eval" thing.

Boxing "evaluation" which I think we call "formatting" and M-Expression evaluation are very different things.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I do not have a complete picture of this right now, and I think that its future form would require some discussion. However, what is clear is that this code does not belong to mathics.core.formatter and now, this behaves like a different kind of evaluation (just because it uses a different set of rules).

I will try to reimplement most of this code as a WL package, and then we can see what part belongs here, or if mathics.eval.makeboxes should be removed at the end.

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