;;;; Generic sequence operations ;;; There are many kinds of data that can be used to represent sequences: ;;; examples include strings, lists, and vectors. ;;; There are operations that can be defined for all sequence types. ;;; Constructing ;;; ;;; (sequence:construct ... ) ;;; Constructs a new sequence of the given type and of size n with ;;; the given elements: item-1 ... item-n ;;; (sequence:null ) ;;; Produces the null sequence of the given type ;;; Selecting ;;; ;;; (sequence:ref ) ;;; Returns the ith element of the sequence. We use zero-based ;;; indexing, so for a sequence of length n the ith item is ;;; referenced by (sequence:ref ). ;;; (sequence:size ) ;;; Returns the number of elements in the sequence. ;;; (sequence:type ) ;;; Returns the predicate defining the type of the sequence given. ;;; Testing ;;; ;;; (sequence:null? ) ;;; Returns #t if the sequence is null, otherwise returns #f. ;;; (sequence:equal? ) ;;; Returns #t if the sequences are of the same type and have equal ;;; elements in the same order, otherwise returns #f. ; ADDITION: ;;; (sequence:elements-equal? ;;; Returns #t if the sequences have equal elements in the same order; ;;; the sequences do not have to be of the same type. Otherwise ;;; returns #f. ;;; Mutation ;;; ;;; Some sequences are immutable, while others can be changed. ;;; ;;; For those that can be modified we can change an element: ;;; ;;; (sequence:set! ) ;;; Sets the ith element of the sequence to v. ;;; Cutting and Pasting ;;; ;;; (sequence:subsequence ) ;;; The arguments start and end must be exact integers such that ;;; 0 <= start <= end <= (sequence:size ). ;;; Returns a new sequence of the same type as the given sequence, ;;; of size end-start with elements selected from the given sequence. ;;; The new sequence starts with the element of the given sequence ;;; referenced by start. It ends with the element of the given ;;; sequence referenced by end-1. ;CHANGED: ;;; (sequence:append ... ) ;;; Returns a new sequence of the type of the first sequence, formed ;;; by concatenating the elements of the given sequences. The size of ;;; the new sequence is the sum of the sizes of the given sequences. ;;; Iterators ;;; ;;; (sequence:generate ) ;;; Makes a new sequence of the given sequence type, of size n. ;;; The ith element of the new sequence is the value of the ;;; function at the index i. ; CHANGED: ;;; (sequence:map ... ) ;;; Requires that the sequences given are of the same size and ;;; that the arity of the function is n. The ith element ;;; of the new sequence is the value of the function applied to the ;;; n ith elements of the given sequences. ; CHANGED: ;;; (sequence:for-each ... ) ;;; Requires that the sequences given are of the same size and ;;; that the arity of the procedure is n. Applies the ;;; procedure to the n ith elements of the given sequences; ;;; discards the value. This is done for effect. ;;; Filtration and Search ;;; ;;; (sequence:filter ) ;;; Returns a new sequence with exactly those elements of the given ;;; sequence for which the predicate is true (does not return #f). ;;; ;;; (sequence:get-index ) ;;; Returns the index of the first element of the sequence that ;;; satisfies the predicate. Returns #f if no element of the ;;; sequence satisfies the predicate. ;;; ;;; (sequence:get-element ) ;;; Returns the first element of the sequence that satisfies the ;;; predicate. Returns #f if no element of the sequence satisfies ;;; the predicate. ;;; Accumulation ;;; ;;; (sequence:fold-right ) ;;; Returns the result of applying the given binary function, ;;; from the right, starting with the initial value. ;;; For example, ;;; (sequence:fold-right list 'end '(a b c)) ;;; => (a (b (c end))) ;;; ;;; (sequence:fold-left ) ;;; Returns the result of applying the given binary function, ;;; starting with the initial value, from the left. ;;; For example, ;;; (sequence:fold-left list 'start '(a b c)) ;;; => (((start a) b) c)