Next: , Previous: , Up: Top   [Contents][Index]


8 Purely functional sequences

Sequences are a general–purpose, variable–length collections, similar to lists, however they support efficient addition and removal from both ends, and random–access. Like other Scheme collections, sequences are zero–indexed.

Function: make-sequence

Return a new empty sequence.

Function: sequence item

Return a new sequence containing all of the argument items, in the given order.

Function: sequence? OBJ

Return #t if the argument is a sequence, #f otherwise.

Function: sequence-empty? sequence

Return #t if sequence contains no items, #f otherwise.

Function: sequence-size sequence

Return a non–negative integer representing the number of items in sequence.

Function: sequence-cons item sequence

Return a new sequence created by adding item to the front of sequence.

Function: sequence-uncons sequence

Return 2 values: the first item of sequence, and a new sequence containing all but the first items. If the sequence is empty: raise a condition with kind pfds-sequence-empty-condition.

Function: sequence-snoc sequence item

Return a new sequence created by adding item to the end of sequence.

Function: sequence-unsnoc sequence

Return 2 values: a new sequence containing all but the last item of sequence, and the last item itself. If sequence is empty: raise a condition with kind pfds-sequence-empty-condition.

Function: sequence-empty-condition? OBJ

Return #t if OBJ is a condition with kind pfds-sequence-empty-condition; otherwise return #f.

Function: sequence-append sequence1 sequence2

Return a new sequence containing all the items of sequence1, followed by all the items of sequence2.

Function: list->sequence list-of-items

Return a new sequence containing all the items from the given list, in the same order.

Function: sequence->list sequence

Return a new list containing all the items of sequence, in the same order.

Function: sequence-split-at sequence N

Return 2 new sequences: the first containing the first N items of sequence, the second containing the remaining items. If N is negative: return the empty sequence as the first value, and the original sequence as the second value. Similarly, if N is greater than the size of sequence: return the original sequence as the first value, and the empty sequence as the second value.

Consequently:

(let-values (((a b) (sequence-split-at SEQ N)))
  (sequence-append a b))

is equivalent to SEQ for all sequences SEQ, and integers N.

Function: sequence-take sequence N

Return a new sequence containing the first N items of sequence. If N is negative: the empty sequence is returned. If N is larger than the size of sequence: the whole sequence is returned.

Function: sequence-drop sequence N

Return a new sequence containing all but the first N items of sequence. If N is negative: the whole sequence is returned. If N is larger than the size of sequence: the empty sequence is returned.

Function: sequence-ref sequence INDEX

Return the item at the specified INDEX in the sequence; INDEX must be a non–negative exact integer. If INDEX is outside the range:

0 <= INDEX < (sequence-size sequence)

an assertion violation is raised.

Function: sequence-set sequence INDEX item

Return the new sequence obtained by replacing the item at the specified INDEX in sequence with the given item. If INDEX is outside the range:

0 <= INDEX < (sequence-size sequence)

an assertion violation is raised.

Function: sequence-fold COMBINER ACCUM-BASE sequence

Return the value obtained by iterating the COMBINER procedure over sequence in left–to–right order. The COMBINER procedure takes two arguments: the value of the position in the sequence, and an accumulator, and its return value is used as the value of the accumulator for the next call. The initial accumulator value is given by the ACCUM-BASE argument.

Function: sequence-fold-right COMBINER ACCUM-BASE sequence

Like sequence-fold, but the sequence is traversed in right–to–left order, rather than left–to–right.

Function: sequence-reverse sequence

Return a new sequence containing all the item of sequence, in reverse order.

Function: sequence-map mapper sequence

Return a new sequence obtained by applying the procedure mapper to each item of sequence in turn.

Function: sequence-filter predicate sequence

Return a new sequence containing all the items of sequence for which the predicate is true.


Next: , Previous: , Up: Top   [Contents][Index]

This document describes version 0.5.0-devel.1 of MMCK PFDS.