Splice

Splice[{e1,e2,}]

represents an expression that will automatically be spliced into any list in which it appears as the sequence of elements ei.

Splice[{e1,e2,},hpatt]

represents an expression that will automatically be spliced into any expression whose head matches the pattern hpatt.

Details

Examples

open allclose all

Basic Examples  (3)

Give a list of elements to be spliced into a surrounding list:

Splice expressions do not automatically flatten inside other heads:

Flatten a list of lists inside another list:

Splice a list of elements inside an expression of a specific head:

Scope  (3)

Splice a list of elements into another list:

The same object does not splice into expressions with other heads:

Splice a list of elements into an expression with a given head:

The same object does not splice into expressions with other heads:

Splice a list of elements into an expression whose head matches a given pattern:

Applications  (1)

Splice a list into another list:

Properties & Relations  (5)

Splice[{e1,e2,}] behaves like Sequence[e1,e2,] inside a list:

Sequence objects also splice inside other heads, but not one-argument Splice objects:

Splice[{e1,e2,},_] behaves like Sequence[e1,e2,] under evaluation:

Splice[{}] is equivalent to Nothing:

FlattenAt[list,pos] is equivalent to MapAt[Splice,list,pos]:

Splice may be resolved inside functions with the HoldAll, HoldFirst, and HoldRest attributes:

It is not resolved inside functions with the HoldAllComplete attribute, as this attribute blocks upvalues:

Splice is also not resolved when nested deeply inside a held expression:

Possible Issues  (1)

Unlike Sequence, the action of Splice cannot be blocked using Unevaluated:

Compare with:

Instead, use Block if it is necessary to temporarily deactivate Splice:

Wolfram Research (2020), Splice, Wolfram Language function, https://reference.wolfram.com/language/ref/Splice.html (updated 2022).

Text

Wolfram Research (2020), Splice, Wolfram Language function, https://reference.wolfram.com/language/ref/Splice.html (updated 2022).

CMS

Wolfram Language. 2020. "Splice." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2022. https://reference.wolfram.com/language/ref/Splice.html.

APA

Wolfram Language. (2020). Splice. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Splice.html

BibTeX

@misc{reference.wolfram_2024_splice, author="Wolfram Research", title="{Splice}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/Splice.html}", note=[Accessed: 01-December-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_splice, organization={Wolfram Research}, title={Splice}, year={2022}, url={https://reference.wolfram.com/language/ref/Splice.html}, note=[Accessed: 01-December-2024 ]}