-
-
Notifications
You must be signed in to change notification settings - Fork 56
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
Condition[...] expressions as second element in RuleDelayed behaviour not compatible with WMA #1213
Comments
This is related with #1209 |
As a workaround, can one implement this by adding a rewriting rule? |
I think so |
Ok. Then this provides a simple solution. First, let's write this outside of Mathics3. Then we can add it as a Rule inside Mathics3 replacing whatever code we currently have. |
In any case, it would be a partial solution: the real issue becomes apparent in functions that do an introspection of the rules in DownValues. That is what is mentioned in #1209. |
Ok. If you are up for it, we can start with a partial solution if it is simple, and gets tests for the partial solution, which ensures more correct behavior. After the next release, we can discuss and expand as necessary. |
Description
In WMA, rules of the form
pat:>Condition[a,cond]
are treated asCondition[pat, cond]:>a
when applied to an expression. Mathics-core does not reproduce this behavior. Notice that this does not happen with->
.Now, when Mathics execute a (Delayed) assignment instruction
f[x_]:= g[x]
, the rulef[x_]:>g[x]
is stored into the definition off
. On the other hand, for conditional assignments likef[x_]:=x/;x==2
, in Mathics, we reformat the rule to obtain the right result. Now, if we fix the logic in handling these kind of rules, we can then replace the behavior of the assignment.How to Reproduce
For example WMA, if we apply the rule
f[x_]:>x/;x==2
to the expressionf[3]
, the interpreter understands the same as we apply the rulef[x_]/;x==2:>x
, i.e., check thatf[3]
matches with the patternf[x_]
, and then ifx
satisfies the condition. If it does, replaces the expression by the replacement (in this case,2
).In Mathics, the interpreter understands that
f[x_]:>x/;x==2
matches withf[3]
, and thenf[3]/. f[x_]/;x==2:>x
results in3/;3==2
.Your Environment
This is independent on the environment.
Workarounds
Put the
Condition
expression in the pattern instead of the replacement.Priority
Low?
Additional context
This also affects how expressions are stored in Assignements (Set, SetDelayed, etc...)
The text was updated successfully, but these errors were encountered: