Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Use rules to make assignments
ResourceFunction["SetByRules"][rules] sets left sides of rules to their right sides. | |
ResourceFunction["SetByRules"][rules,f] assigns using functionf to resolve conflicts in case of identical left hand sides. |
Perform assignments according to given rules:
In[1]:= | ![]() |
Out[1]= | ![]() |
In[2]:= | ![]() |
Out[2]= | ![]() |
Apply the first rule in case of conflict:
In[3]:= | ![]() |
Out[3]= | ![]() |
In[4]:= | ![]() |
Out[4]= | ![]() |
Specify how to resolve a conflict:
In[5]:= | ![]() |
Out[5]= | ![]() |
In[6]:= | ![]() |
Out[6]= | ![]() |
Rules are not distinguished by pattern parameters:
In[7]:= | ![]() |
Out[7]= | ![]() |
In[8]:= | ![]() |
Out[8]= | ![]() |
Assignment immediately after solving the equation:
In[9]:= | ![]() |
Out[9]= | ![]() |
In[10]:= | ![]() |
Out[10]= | ![]() |
If the conflict is not resolved effectively, then a warning will be generated and the conflict will be automatically resolved:
In[11]:= | ![]() |
Out[11]= | ![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License