Skip to content

Append ​

The collection with value added as its last element.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguageAppend✓
Append(collection, value)the collection with value added as its last element.
Append(expr, value)value added as the last operand of any expression, not just a collection.
Typed signatures
TypePackageApplies
untypedcombinatoricsalways
(collection<any>, (missing | value)+) -> collectioncompute-enginealways

Domain: Collections

Details
  • Append(c,x)=Join(c,{x})Append(c, x) = Join(c, \{x\}). See Join.
  • Appending a list nests it as a single element rather than splicing its contents in — use Join to splice.
  • Works on a set as well as a list, and on the operands of any expression.

Examples

Basic #
live ↗
InAppend([1,2,3],4)\mathrm{Append}(\bigl\lbrack1, 2, 3\bigr\rbrack, 4)Out[1,2,3,4]\bigl\lbrack1, 2, 3, 4\bigr\rbrack
live ↗
InAppend([a,b,c,d],x)\mathrm{Append}(\bigl\lbrack a, b, c, d\bigr\rbrack, x)Out[a,b,c,d,x]\bigl\lbrack a, b, c, d, x\bigr\rbrack
Scope #

A set as well as a list

live ↗
InAppend({1,2,3},4)\mathrm{Append}(\lbrace1, 2, 3\rbrace, 4)Out{1,2,3,4}\lbrace1, 2, 3, 4\rbrace

Onto the empty list

live ↗
InAppend([],x)\mathrm{Append}(\bigl\lbrack\bigr\rbrack, x)Out[x]\bigl\lbrack x\bigr\rbrack

A lazy Range is materialised first

live ↗
InAppend(1..3,4)\mathrm{Append}(1..3, 4)Out[1,2,3,4]\bigl\lbrack1, 2, 3, 4\bigr\rbrack

Any head, not just a list

live ↗
InAppend(f(a,b),c)\mathrm{Append}(f(a, b), c)Outf(a,b,c)f(a, b, c)
Applications #

Adding a row to a matrix

live ↗
InAppend([[1,2],[3,4]],[5,6])\mathrm{Append}(\bigl\lbrack\bigl\lbrack1, 2\bigr\rbrack, \bigl\lbrack3, 4\bigr\rbrack\bigr\rbrack, \bigl\lbrack5, 6\bigr\rbrack)Out[[1,2],[3,4],[5,6]]\bigl\lbrack\bigl\lbrack1, 2\bigr\rbrack, \bigl\lbrack3, 4\bigr\rbrack, \bigl\lbrack5, 6\bigr\rbrack\bigr\rbrack
live ↗
InNestList(_1⁡↦Symbol(x),[a],5)\mathrm{NestList}(\operatorname{\_1}↦\mathrm{Symbol}(x), \bigl\lbrack a\bigr\rbrack, 5)Out[[a],Symbol(x),Symbol(x),Symbol(x),Symbol(x),Symbol(x)]\bigl\lbrack\bigl\lbrack a\bigr\rbrack, \mathrm{Symbol}(x), \mathrm{Symbol}(x), \mathrm{Symbol}(x), \mathrm{Symbol}(x), \mathrm{Symbol}(x)\bigr\rbrack
Properties #

Append(c,x)=Join(c,{x})Append(c, x) = Join(c, \{x\}). See Join

live ↗
InAppend([1,2,3],4)=Join([1,2,3],[4])\mathrm{Append}(\bigl\lbrack1, 2, 3\bigr\rbrack, 4)=\mathrm{Join}(\bigl\lbrack1, 2, 3\bigr\rbrack, \bigl\lbrack4\bigr\rbrack)OutTrue\mathrm{True}

Appending adds exactly one element. See Length

live ↗
InLength(Append([1,2,3],4))=Length([1,2,3])+1\mathrm{Length}(\mathrm{Append}(\bigl\lbrack1, 2, 3\bigr\rbrack, 4))=\mathrm{Length}(\bigl\lbrack1, 2, 3\bigr\rbrack)+1OutTrue\mathrm{True}
Possible issues #

Appending a list nests it as a single element rather than splicing its contents in

live ↗
InAppend([1,2,3],[9])\mathrm{Append}(\bigl\lbrack1, 2, 3\bigr\rbrack, \bigl\lbrack9\bigr\rbrack)Out[1,2,3,[9]]\bigl\lbrack1, 2, 3, \bigl\lbrack9\bigr\rbrack\bigr\rbrack
About
Examples11
Checked againstWolfram Language 11 agreemathlib4 6 agree1 error
CrosswalkWolfram Language

Implementation

mappedmathlib4packages/oracle/src/mappings.ts

The value as a new last element; a list value onto a list of scalars fails to elaborate (ours nests it as one element), as does a set.

See also: Join, Prepend