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

  • Splice[{}] is equivalent to Nothing.
  • Splice[{e1,e2,}] is equivalent to Sequence[e1,e2,] when the outer wrapping head is List.
  • Splice[{e1,e2,},_] is equivalent to Sequence[e1,e2,].
  • Splice is resolved as part of the standard evaluation process. It is not resolved in expressions that are held or inactive.

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  (4)

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]:

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_2022_splice, author="Wolfram Research", title="{Splice}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/Splice.html}", note=[Accessed: 13-August-2022 ]}

BibLaTeX

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