-
-
Notifications
You must be signed in to change notification settings - Fork 64
Go over Optional doc #1636
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?
Go over Optional doc #1636
Conversation
| = Pattern[x, Blank[]] | ||
| >> _:d // FullForm | ||
| = Optional[Blank[], d] | ||
| >> x:_+y_:d // FullForm |
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.
This example does not seem motivated.
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.
I guess the motivation is to show the order of interpretation: the second colon is interpreted first, to build the inner Optional expression, and then the first one is interpreted as a named Pattern.
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.
Ok. I'll add this example back, adding this explanation.
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.
I guess the motivation is to show the order of interpretation: the second colon is interpreted first, to build the inner
Optionalexpression, and then the first one is interpreted as a named Pattern.
Hmm... It looks like we may have the wrong Precedence indicated for Pattern. We give Pattern value 670 while it is 150 in WMA. In both WMA and Mathics3, though, Optional is 140. So the behavior is natural.in WMA while in Mathics3, it goes contrary to what is specified.
Is this something we specifically hacked around? and would get wrong were we to follow the usual precedence rules?
Edit what we have would give the same behavior. But, I wonder if there is a reason not to use the same value 150.
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.
I looked at the precedence issue, and it is tagged with the right value in mathics_scanner, but Pattern is not tagged as an operator in mathics-core, and if that's changed, other things break. 670 is the magic number that's given when we can't find a precedence value tagged.
Sigh.
| = Optional[Pattern[s, Blank[]]] | ||
| 'InputForm' shows it in its 'Infix' or 'Postfix' form depending on the \ | ||
| number of parameters: |
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.
InputForm, by default, uses infix for equations. I do not understand from the example where the number of parameters is coming into play. And I do not see where postifx notation is selected.
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.
There is no Infix form with just one argument...
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.
Technically, this degenerate case is defined on Infix:
In[2]:= Infix[{1}, "+"]
Out[2]= 1
But the larger and more important point is: what does this Infix and Postfix stuff have to do with the examples?
Make it more clear the operator nature of Optional and Pattern. Make more explicit the precedence between Optional and Pattern.
|
@mmatera thoughts on this PR? |
No description provided.