From 8e998f4e5be326a2bc91220e86d555ce79d2890e Mon Sep 17 00:00:00 2001 From: bnewbold Date: Wed, 11 Feb 2009 14:31:28 -0500 Subject: ps02 files --- ps02_generics/generic-specs.scm | 121 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 ps02_generics/generic-specs.scm (limited to 'ps02_generics/generic-specs.scm') diff --git a/ps02_generics/generic-specs.scm b/ps02_generics/generic-specs.scm new file mode 100644 index 0000000..ad07d96 --- /dev/null +++ b/ps02_generics/generic-specs.scm @@ -0,0 +1,121 @@ +;;;; 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. + + +;;; 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. + +;;; (sequence:append ... ) +;;; Requires that the sequences are all of the same type. Returns +;;; a new sequence of the type, 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. + +;;; (sequence:map ... ) +;;; Requires that the sequences given are of the same size and +;;; type, 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. + +;;; (sequence:for-each ... ) +;;; Requires that the sequences given are of the same size and +;;; type, 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) + + + -- cgit v1.2.3