next up previous contents index
Next: Other Sequence Functions Up: Sequence Functions Previous: Simple Sequence Manipulation

Nesting Sequences

The two functions partition and flatten are the primitives for moving between levels of nesting. All other functions for moving between levels of nesting can be built out of these. The functions split and bottop are often useful for divide-and-conquer routines.

partition(v, counts) {([a], [int]) tex2html_wrap_inline10379 [[a]] :: (a in any)}
  Given a sequence of values and another sequence of counts, partition returns a nested sequence with each subsequence being of a length specified by the counts. The sum of the counts must equal the length of the sequence of values. For example:

4pt

tabular7915

flatten(v) {[[a]] tex2html_wrap_inline10413 [a] :: (a in any)}
  Given a nested sequence of values, flatten flattens the sequence. For example:

4pt

tabular7929

split(v, flags) {([a], [bool]) tex2html_wrap_inline10447 [[a]] :: (a in any)}
  Given a sequence of values v and a boolean sequence of flags, split creates a nested sequence of length 2 with all the elements with an f in their flag in the first element and elements with a t in their flag in the second element. For example:

4pt

tabular7941

bottop(v) {[a] tex2html_wrap_inline10481 [[a]] :: (a in any)}
  Given a sequence of values values, bottop creates a nested sequence of length 2 with all the elements from the bottom half of the sequence in the first element and elements from the top half of the sequence in the second element. For example:

4pt

tabular7955

head_rest(values) {[a] tex2html_wrap_inline10511 (a, [a]) :: (a in any)}
  Given a sequence of values values of length > 0, head_rest returns a pair containing the first element of the sequence, and the remaining elements of the sequence.

rest_tail(values) {[a] tex2html_wrap_inline10515 ([a], a) :: (a in any)}
  Given a sequence of values values of length > 0, rest_tail returns a pair containing all but the last element of the sequence, and the last element of the sequence.



next up previous contents index
Next: Other Sequence Functions Up: Sequence Functions Previous: Simple Sequence Manipulation



Jonathan Hardwick
Tue Nov 28 13:57:00 EST 1995