Skip to content

Conversation

@rocky
Copy link
Member

@rocky rocky commented Jan 20, 2026

No description provided.

= Pattern[x, Blank[]]
>> _:d // FullForm
= Optional[Blank[], d]
>> x:_+y_:d // FullForm
Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Member Author

@rocky rocky Jan 20, 2026

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.

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.

Copy link
Member Author

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:
Copy link
Member Author

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.

Copy link
Contributor

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...

Copy link
Member Author

@rocky rocky Jan 20, 2026

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?

@rocky rocky requested a review from mmatera January 20, 2026 01:13
rocky added 2 commits January 19, 2026 21:01
Make it more clear the operator nature of Optional and Pattern.
Make more explicit the precedence between Optional and Pattern.
@rocky
Copy link
Member Author

rocky commented Jan 25, 2026

@mmatera thoughts on this PR?

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.

3 participants