Repository navigation
Conversation
…rst evaluation should be stored in In[1] and Out[1].
| >> Definition[In] | ||
| = Attributes[In] = {Listable, Protected} | ||
| . | ||
| . In[6] = Definition[In] |
There was a problem hiding this comment.
Here, the order was wrong because the rules were not properly built in mathics.core.evaluation. Adding the evaluation parameter when the rules are created, the rules can determine that that the patterns are literal patterns, and therefore the right precedence is used.
|
|
||
| name = "$Line" | ||
| summary_text = "current line number" | ||
| rules = {"$Line": "1"} |
There was a problem hiding this comment.
This automatically sets the initial value of $Line after we reset the Definitions object.
| line_number = self.get_line_no() | ||
| if line_number is not None: | ||
| self.set_config_value("$Line", +increment) | ||
| self.set_config_value("$Line", line_number + increment) |
There was a problem hiding this comment.
Seems we erase it by mistake at some point...
There was a problem hiding this comment.
Probably during Dialog[] addition. We should make sure that this isn't broken by these changes.
There was a problem hiding this comment.
I could use in Evaluation.evaluation, in the finally block. Right now, it is not used anywhere
| output_forms = self.definitions.outputforms | ||
|
|
||
| line_no = self.definitions.get_line_no() | ||
| line_no += 1 |
There was a problem hiding this comment.
This should happend at the end of the evaluation, not before.
| """ | ||
| try: | ||
| self.definitions = Definitions(add_builtin) | ||
| except KeyError: |
There was a problem hiding this comment.
This seems to have worked before I fixed the MakeBoxes rule. The proper way to decide if we need to load the built-ins is to check if they were already loaded...
| def test_session_evaluation_as_in_cli(): | ||
| # `evaluation_as_in_cli` returns a `Result` object | ||
| session.reset() | ||
| assert session.evaluate("$Line") is Symbol("$Line") |
There was a problem hiding this comment.
This change fits better with the WMA behaviour.
There was a problem hiding this comment.
Ok. Please enlighten. In what way is it better?
There was a problem hiding this comment.
As it is now in master,
In[1]:= $Line
Out[1]= 2
which is weird. Also, this is not compatible with the result using the MathicsSession object:
>>> from mathics.core.load_builtin import import_and_load_builtins
>>> from mathics.session import MathicsSession
>>> import_and_load_builtins()
>>> session=MathicsSession()
>>> session.evaluate("$Line")
<Symbol: System`$Line>
>>> session.evaluate_as_in_cli("$Line").result
'1'
which looks inconsistent: three ways to evaluate the same expression in the same condition, and three different results.
In WMA,
In[1]:= $Line
Out[1]= 1
|
When I added Dialog, I was sloppy and didn't add tests to ensure the Dialog numbering would work correctly. I also believe I didn't fully implement all the WMA Dialog features. (I think at that time I was more focused on diagnosing a Rubi problem we have/had). Also, we did not, and still don't, have sufficient line numbering tests. I think what we need to do here is write examples and then tests that show how we're currently broken and demonstrates how this fixes it. |
The tests were already there; it's just that they were not testing the right behavior... |
Fix behavior of $Line,
In[...]andOut[...]always start at 1, and the first evaluation should be stored in In[1] and Out[1].