-
-
Notifications
You must be signed in to change notification settings - Fork 66
removing n_evaluation #559
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
2dd8a5f
ae889a0
dedf6a7
3fdad82
3fc8e2d
6438ce7
382017f
dac7a92
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 |
|---|---|---|
|
|
@@ -1378,23 +1378,32 @@ def to_python(self, *args, **kwargs): | |
| String -> '"..."' | ||
| Function -> python function | ||
| numbers -> Python number | ||
| If kwarg n_evaluation is given, apply N first to the expression. | ||
| """ | ||
| from mathics.builtin.base import mathics_to_python | ||
|
|
||
| n_evaluation = kwargs.get("n_evaluation", None) | ||
| assert n_evaluation is None | ||
|
|
||
| head = self._head | ||
| if head is SymbolFunction: | ||
|
|
||
| from mathics.core.convert.function import expression_to_callable_and_args | ||
|
|
||
| vars, expr_fn = self.elements | ||
| return expression_to_callable_and_args(expr_fn, vars, n_evaluation) | ||
| evaluation = kwargs.get("evaluation", None) | ||
| if evaluation: | ||
| vars, expr_fn = self.elements | ||
| return expression_to_callable_and_args(expr_fn, vars, evaluation) | ||
|
|
||
| # Backward compatibility | ||
| n_evaluation = kwargs.get("n_evaluation", None) | ||
| if n_evaluation is not None: | ||
|
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. Line 1386 or thereabouts has an assert that
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. Indeed, this line should be removed. Regarding
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. BTW, if we want that Then, if at some point the expression becomes evaluable and produces a Python native object, then the result would be a Python object...
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.
I'd like to be very clear about this. In my view this was an intermediary step because there was myopic thinking about the code an a lack of a bigger picture about how interpreters normally work. The entire operation represented as a class is the kind of thing you find in toy interpreters but not performant interpreters. Performant interpreters do not use class methods to implement built-in operations. For a list of Python built-in operations see https://docs.python.org/3/library/dis.html#opcode-collections . For a list of GNU Emacs operations see https://github.com/rocky/elisp-bytecode . You can find the same thing for Ruby, Java, Javascript, and so on. It is a necessary prerequisite say if you want to have add JIT technology for example (which we are a very long way from being able to contemplate). I mention to be aware of this so as not do this as much in the future. There has been a rush to just plunge into into new areas where much is not known either in terms of the existing code or of conventional practice. And that sometimes leads to an equal effort to remove it later. Remind me why would we want to "support"
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.
This is a possibility but there would be a different method called. As I have said in the past there was this pervasive vaguess which assists a muddling of concepts. As I have alluded to before,
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.
OK. That was because I was much less aware than now about how to make a readable PR. This is something that I learn in the hard way during this time...
Yes, I agree with all that. But then, we can take two positions: leave the code as it is, diagram a master plan, then rework all the existing pieces, and then (let's say, in a couple of years) see if we can start improving the functionality. The other way (the one in which I think I could be useful now) is to fix peripherical parts with (maybe suboptimal) code, and to add tests to reinforce the compatibility with WMA. This is what I was trying to do during the last months.
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.
There has been a rough plan. I was making my way over the rewrite-apply-eval process. I had gotten to the top-level evaluation. That was blocking Formatting and Boxing work you wanted to do. So I stopped that process so that you would have free reign over Form, Boxing, and Format. While you are doing that I am looking to expand the use of ListExpression and customized kinds of expressions. Association is a natural for this as well. The Boxing and Formatting work quickly spilled into scanning and parsing - rightly or wrongly. I'll handle issues that spill over there.
In the places where we have no choice, okay. But in the areas where I have a clearer idea of what needs to be done, let's wait on that. With respect specifically to Forms, Boxing, and Format, this is a clear area where you know more about this than I can even hope to understand, so focus on that. The plan that you have put together seems good so far. So just continue with that. As for this PR, let's put back that
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. OK. The assert was removed, and I left the code for converting
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. Please no deprecation warning for something that should not have been added. This PR I thought (and actually the previous one) were supposed to remove uses, not deprecate them. The "assert" checks that. In a little while the assert can be removed as well. Thanks. In a little while the assert could be removed as well.
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. I commented out both the assert and the code that shows the deprecation. I am going to leave this as a draft, and eventually use this discussion (and the changes) when we want to go over this method. |
||
| value = Expression(SymbolN, self).evaluate(n_evaluation) | ||
| from mathics.core.evaluators import eval_N | ||
| import warnings | ||
|
|
||
| warnings.warn( | ||
| ( | ||
| "use of expr.to_python(n_evaluation) is deprecated." | ||
| "Use instead eval_N(expr, evaluation).to_python()" | ||
| ), | ||
| DeprecationWarning, | ||
| ) | ||
| value = eval_N(self, n_evaluation) | ||
| return value.to_python() | ||
|
|
||
| if head is SymbolDirectedInfinity and len(self._elements) == 1: | ||
|
|
||
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.
Also, I fixed a typo here, which was avoiding that this module gets loaded.
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.
Fixed also in #560.