Improve get functions for patterns #1292
Merged
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.
This is one tiny change I wanted to implement for a while. Im WMA, if you want to implement a rule that returns the same expression if certain test fails, the way to do it is
i.e. use a
Pattern[patname, pat]
expression to pass the whole original unevaluated expression (Half[a]
in the example) to the replace expression. However, we could not do this in the patterns especified in docstrings, because we "overloaded" the meaning ofpatname: pattern
in the function that loadseval_*
andformat_*
methods: we use them to indicate in the case offormat_
methods to whichFormat
corresponds the rule.As in some methods we need the full original expression, then we added a "hack" to interpret a parameter
expression
in aneval_
function to contain the whole expression.This PR removes the need of all this hackiness by changing the convention in
format_
methods docstrings: if you want to especify an specific Format, you can do it with a docstring of the form(form1, form2,...,): exprpattern
which is not a valid WL expression.We can also use this form to avoid the use of
Optional
in theeval_
methods, so eacheval_
method could return always aBaseExpression
. But this will come later.