Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Splice expressions at certain positions
ResourceFunction["SpliceAt"][expr,{e1,e2,…},pos] splices expressions ei at position pos of expr. | |
ResourceFunction["SpliceAt"][expr,{p1→{e11,e12,…},p2→{e21,e22,…},…}] splices expressions eij at corresponding positions pi. | |
ResourceFunction["SpliceAt"][{e1,e2,…}, pos] represents an operator form that can be applied to an expression. | |
ResourceFunction["SpliceAt"][{p1→{e11,e12,…},p2→{e21,e22,…},…}] represents an operator form with rules. |
Splice a list of expressions inside another expression:
In[1]:= | ![]() |
Out[1]= | ![]() |
Splice at multiple positions:
In[2]:= | ![]() |
Out[2]= | ![]() |
Splice with rules:
In[3]:= | ![]() |
Out[3]= | ![]() |
Use Unevaluated to prevent premature evaluation:
In[4]:= | ![]() |
Out[4]= | ![]() |
Use RuleDelayed to delay evaluation for rules:
In[5]:= | ![]() |
Out[5]= | ![]() |
Use operator forms:
In[6]:= | ![]() |
Out[6]= | ![]() |
In[7]:= | ![]() |
Out[7]= | ![]() |
In most cases, SpliceAt is just equivalent to Insert with Sequence:
In[8]:= | ![]() |
Out[8]= | ![]() |
In[9]:= | ![]() |
Out[9]= | ![]() |
But Insert will not work at deeper than first level inside held arguments:
In[10]:= | ![]() |
Out[10]= | ![]() |
While SpliceAt works as expected:
In[11]:= | ![]() |
Out[11]= | ![]() |
Also Insert does not support multiple insertions, while SpliceAt does:
In[12]:= | ![]() |
Out[12]= | ![]() |
Root position is invalid:
In[13]:= | ![]() |
Out[13]= | ![]() |
Subhead position is invalid:
In[14]:= | ![]() |
Out[14]= | ![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License