-
-
Notifications
You must be signed in to change notification settings - Fork 6
Tag Optional as an operator... #141
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not sure if this symbol can be understood as an operator. In the first place, it can only accept a very special kind of elements as operands. I do not see clear how precedence an associativity must be assigned, and it would be a Postfix or Infix operator depending on the context.
Uh oh!
There was an error while loading. Please reload this page.
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.
All of the features below that concern you can be found in other WMA operators.
That's true of most of the other operators as well. And it is true of most Builtin functions; an operator is just a shorthand for a built-in function. In fact its the other way around: most operators and functions place limits on their parameters or operands.
For example,
Integraltakes two parameters: an expression and a partial. Even the most common operators,TimesandPlus, have limitations on their operands: they must be numeric.Actually, we just came across an example of this.
PatternandOptional, which both use the character ":" as their operator symbol, bindOptionalbeforePattern. SoPatternhas precedence 150 whileOptionalhas precedence 140.If two patterns can be juxtaposed next to one another, then there definitely is an associativity. If they can't ever be juxtaposed, then the associativity is "null" or "unkown" (used in the case of Box operators). See, for example, the
Informationoperator.This kind of thing also happens in other operator symbols;
--and++are both operator symbols that can appear before or after an expression. And even the common+and-operators can be used in both unary and binary forms depending on the context.Note that in the YAML table, though, these appear with different names. So we have
Predecrementas the operator name when--appears before an expression andPostDecrementas the operator name when it appears afterwards. Same with disambiguating+:UnaryPlusversusPlus.In sum, WMA defines a lot of operators. More than most people might expect. But that's not surprising. WMA pushes language concepts to extreme limits. Just as there are a lot more operators than found in any other common programming language I know, there are a lot more built-in functions in the language as well. While this kind of thing is a bit unusual, it is not illogical.
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.
The particularity of this
Optionaloperator is that it has different notations for one and two operators.Other operators have other particularities:
Integrateinvolves two operator characters (\[Integral]and\[DifferentialD]),Timesuses different operators inStandardFormandOutputForm, and--can be interpreted different as Prefix and Postfix operators. Also WMA reports forPrecedence[Optional]a value140, which is not the default value (670). The same happens withBlank, which has a precedence of730, but I am not sure if we treat it as an operator.In any case, my goal now is to complete the implementation of a framework for
MakeBoxesevaluation, with a behavior closer to WMA. It would be nice if it is possible to DRY the implementation ofOptionaland other symbols using the existing interface, but I do not think it is central.Regarding the user documentation, the question is whether it is clear enough for the user be able to use and understand it. I added some examples of formatting to include some doctests, but these doctests could be included in the
format_test.yamlfile.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.
Said this, I think the change in the entry does not cause any harm, and makes the table more accurate, so LGTM.
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.
Don't confuse operator characters like
\[Integral]with the operators likeIntegrate. (In some cases, likeDoubleContourIntegralthere is both a character name as well as an operator with the same name. So, it can lead to confusion)This is not just about reducing the size of the code. More important is the understanding of the principles of how things are organized, which by its very nature leads to a more compact implementation. In WMA, right or wrong, there is a lot that is pushed or framed in terms of operators and operator precedence. This generally dictates how things work.
As an analogy, one could write some code saying that when I see 612 + 300, it has the same value as 912. And I might notice a pattern for what happens when I see + 300. And I might call that DRYing or reducing the size of code. But what this misses is that the concept of how addition works, which is driving the implementation.
Understanding and following the concept is more likely to predict and produce more correct results, assuming that's what WMA is doing. (And I think it works this way.)
When I read the description that was in the master branch, the two problems I had were spending a lot of mental effort trying to understand the example, as well as what idea was being conveyed. Part of this is was a lack of description of intent. Part of it was adding extraneous aspects, and part of the difficulty was in using examples involving something other than what was being conveyed.
And then in the rewrite, I realized that there were some fundamental concepts like the notion that Pattern and Optional are operators, and they happen to use the same operator symbol, ":".
So instead of describing how to disambiguate a particular expression as an isolated fact, it becomes showing how to apply the standard rules when two operators (which happen to use the same operator symbol) are juxtaposed.