-
-
Notifications
You must be signed in to change notification settings - Fork 61
improve OneIdentity builtin
#602
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
Changes from all commits
92e6b0c
cd74aa9
cb2ca92
afcf467
454bbaa
21a4080
d33ca93
318a2b8
de5bbbe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -460,15 +460,24 @@ class OneIdentity(Predefined): | |
|
|
||
| <dl> | ||
| <dt>'OneIdentity' | ||
| <dd>is an attribute specifying that '$f$[$x$]' should be treated \ | ||
| as equivalent to $x$ in pattern matching. | ||
| <dd>is an attribute assigned to a symbol, say $f$, indicating that '$f$[$x$]', $f$[$f$[$x$]], etc. are all \ | ||
| equivalent to $x$ in pattern matching. | ||
| </dl> | ||
|
|
||
| 'OneIdentity' affects pattern matching: | ||
| >> a /. f[x_:0, u_] -> {u} | ||
| = a | ||
|
|
||
| Here is how 'OneIdentity' changes the pattern matched above : | ||
|
|
||
| >> SetAttributes[f, OneIdentity] | ||
| >> a /. f[args___] -> {args} | ||
| >> a /. f[x_:0, u_] -> {u} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reading the documentation, I realize that this test was wrong... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! This bug goes back to the very first Mathics version. |
||
| = {a} | ||
| It does not affect evaluation: | ||
|
|
||
| However, without a default argument, the pattern does not match: | ||
| >> a /. f[u_] -> {u} | ||
| = a | ||
|
|
||
| 'OneIdentity' does not change evaluation: | ||
| >> f[a] | ||
| = f[a] | ||
| """ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -262,9 +262,6 @@ def __init__( | |
| # status of last evaluate | ||
| self.exc_result = self.SymbolNull | ||
| self.last_eval = None | ||
| # Necesary to handle OneIdentity on | ||
| # lhs in assignment | ||
| self.ignore_oneidentity = False | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bye bye... |
||
| # Used in ``mathics.builtin.numbers.constants.get_constant`` and | ||
| # ``mathics.builtin.numeric.N``. | ||
| self._preferred_n_method = [] | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.