next | previous | forward | backward | up | index | toc

# splice -- remove subsequences from a sequence or list

## Synopsis

• Usage:
splice X
• Inputs:
• X, ,
• Outputs:
• Y, , the new list resulting from replacing each element of X that is a sequence with its elements

## Description

Unlike the function deepSplice, which recursively flattens subsequences at all levels, splice removes the outermost nested level of subsequences only.

 i1 : X = {(), (0, (1, 2, (3, 4))), (5, (6, 7)), 8, 9}; i2 : splice X o2 = {0, (1, 2, (3, 4)), 5, (6, 7), 8, 9} o2 : List i3 : deepSplice X o3 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} o3 : List

splice does not alter elements that are lists, arrays, or anything other than sequences.

 i4 : Z = {(), {0, {1, 2, (3, 4)}}, [5, [6, 7]], 8, 9}; i5 : splice Z o5 = {{0, {1, 2, (3, 4)}}, [5, [6, 7]], 8, 9} o5 : List

splice works on sequences, too, and all other objects of class BasicList. The output matches the class of the input.

 i6 : splice ((), (0, (1, 2, (3, 4))), (5, (6, 7)), 8, 9) o6 = (0, (1, 2, (3, 4)), 5, (6, 7), 8, 9) o6 : Sequence i7 : splice [(), (0, (1, 2, (3, 4))), (5, (6, 7)), 8, 9] o7 = [0, (1, 2, (3, 4)), 5, (6, 7), 8, 9] o7 : Array

Even if X is a MutableList, splice returns a new list rather than altering the definition of X.

 i8 : M = new MutableList from X o8 = MutableList{...5...} o8 : MutableList i9 : splice M o9 = MutableList{...6...} o9 : MutableList i10 : M o10 = MutableList{...5...} o10 : MutableList