Generated: Wednesday, March 28, 2012, 12:32:40 A SchemeDoc Manual

Bites of Lists - Mapping and Filtering Sublists

Kurt Nørmark © normark@cs.aau.dk Department of Computer Science, Aalborg University, Denmark.

Source file: y:/Kurt/Files/.public_html/bites-of-lists/man/../bite-stuff.scm

Bite filter and bite mapping functions, together with a number of bite generating functions. Accompanies the paper "Bites of Lists - Mapping and Filtering Sublists" by Kurt Nørmark, Aalborg University, 2010. Please notice that there is access to the Scheme source code from the "See also" clauses of all documented functions.

Table of Contents:
1. Higher-order bite functions. 2. Bite Generators.

Alphabetic index:
bite-of-length (bite-of-length n [noise-element?]) Generate and return a function: List -> List, which returns a bite of length n.
bite-of-varied-length (bite-of-varied-length f [noise-element?]) Generate and return a function: List Int -> List, which returns a bite of length f(n), where n is the bite number (1 based) passed as the second parameter to the generated function.
bite-while-accumulate (bite-while-accumulate bin-op init-val pred [noise-element?]) Generate and return a function, which returns the shortest (first) non-empty prefix bite that accumulates to a value which fulfills the predicate pred.
bite-while-compare (bite-while-compare el-relation [noise-element?]) Generate and return a function, which - when applied on a list - returns the longest bite of the list in which successive elements fulfill the binary relation el-relation.
bite-while-element (bite-while-element el-pred . attributes) Generate and return a function: List -> List, which returns the longest prefix bite in which each element, appart from sentinel elements, fulfills the prediciate el-pred.
bite-while-element-with-accumulation (bite-while-element-with-accumulation pred accumulator init-acc-val [noise-element?]) Generate and return a function: List -> List, which returns the longest prefix bite in which each element, appart from a sentinel element, fulfills the prediciate pred.
bite-while-monotone (bite-while-monotone el-comparator [noise-element?]) Generate and return a function, which - when applied on a list - returns the longest bite of the list in which successive elements are monotone measured by the el-comparator function.
bite-while-prefix (bite-while-prefix bite-pred) Generate and return a function: List -> List, which returns the longest bite of the input list, of which each prefix bite satisfies bite-pred.
filter-bites (filter-bites make-bite bite-pred lst) Successively take bites of list with make-bite, apply the predicate bite-pred on the bite, and splice the bite into the resulting list if bite-pred is true for the bite.
filter-map-bites (filter-map-bites make-bite bite-pred bite-transf lst) Filter bites, but additionally map the resulting bites with bite-transf after the filtering.
map-bites (map-bites make-bite bite-transf lst) Successively take bites of the list lst with make-bite, transform these bites with bite-transf, and splice (append accumulate) the transformed bites together.
map-n-bites (map-n-bites make-bite bite-transf lst) A variant of map-bites, which passes the bite number to both make-bite and to bite-transf.
step-and-map-bites (step-and-map-bites make-bite bite-pred bite-transf lst) A variant of filter-map-bites which successively and step-wise applies apply bite-pred to prefixes of lst.
step-and-map-n-bites (step-and-map-n-bites make-bite bite-pred bite-transf lst) A variant of step-and-map-bites that passes the bite number to bite-trans.


1 Higher-order bite functions.
Mapping and filtering functions that operate on bites (sublists) of a list. A bite of a non-empty list is a non-empty prefix of the list. Consequtive bites of a list must append-accumulate to the original list. There exists a number of higher-order bite function creators, such as bite-while-element and bite-of-length, see here .

map-bites
Form (map-bites make-bite bite-transf lst)
Description Successively take bites of the list lst with make-bite, transform these bites with bite-transf, and splice (append accumulate) the transformed bites together. The bite number (starting with 1) is passed as the second parameter to make-bite.
Parameters make-bite A function which returns the next bite. Signature: List, Int -> List.
bite-transf A function which transform a bite: Signature: List -> List. (Notice that this function only takes a single parameter).
lst A list from which bites are taken, one at a time.
Examples (map-bites (bite-while-element number?) list '(1 -1 1 a 3 4 b 6 1 2 3)) => ((1 -1 1 a) (3 4 b) (6 1 2 3))
(map-bites (bite-while-element (negate number?)) list '(a b 1 c d 2 e f g h i j 3 k l)) => ((a b 1) (c d 2) (e f g h i j 3) (k l))
(map-bites (bite-while-element number?) list '(a b 1 c d 2 e f g h i j 3 k l)) => ((a) (b) (1 c) (d) (2 e) (f) (g) (h) (i) (j) (3 k) (l))
(map-bites (bite-while-element symbol? 'sentinel "first") list '(a b 1 c d 2 e f g h i j 3 k l)) => ((a b) (1 c d) (2 e f g h i j) (3 k l))
(map-bites (bite-while-element symbol? 'sentinel "last") list '(a b 1 c d 2 e f g h i j 3 k l)) => ((a b 1) (c d 2) (e f g h i j 3) (k l))
(map-bites (bite-while-element symbol? 'sentinel "alone") list '(a b 1 c d 2 e f g h i j 3 k l)) => ((a b) (1) (c d) (2) (e f g h i j) (3) (k l))
(map-bites (bite-while-accumulate + 0 (lambda (sum) (>= sum 5))) list '(0 1 2 1 2 0 1 3 0 -2 1 3 4)) => ((0 1 2 1 2) (0 1 3 0 -2 1 3) (4))
(map-bites (bite-while-compare < symbol?) list '(a 0 b c 1 d 2 -1 e f g 7 2 3)) => ((a 0 b c 1 d 2) (-1 e f g 7) (2 3))
(map-bites (lambda (lst . r) (list-part 1 3 lst)) list '(a b c d e f g h i j k l)) => ((a b c) (d e f) (g h i) (j k l))
(map-bites (lambda (lst . r) (list-part 1 3 lst)) list '(a b c d e f g h i j k l)) => ((a b c) (d e f) (g h i) (j k l))
(map-bites (bite-while-monotone (make-comparator < >)) list '(1 2 1 2 1 2 3 4)) => ((1 2) (1 2) (1 2 3 4))
(map-bites (bite-of-varied-length (lambda (n) n)) list '(1 2 3 4 5 6 7 8)) => ((1) (2 3) (4 5 6) (7 8))
(map-bites (bite-of-varied-length (lambda (n) (if (even? n) 2 4))) list '(1 2 3 4 5 6 7 8 9 10 11 12)) => ((1 2 3 4) (5 6) (7 8 9 10) (11 12))
(map-bites (bite-while-element number?) list '(1 -1 1 a 3 4 b 6 1 2 3)) => ((1 -1 1 a) (3 4 b) (6 1 2 3))
(map-bites (bite-while-element number? 'sentinel "alone") list '(1 -1 1 a b c 3 4 b 6 1 2 3)) => ((1 -1 1) (a) (b) (c) (3 4) (b) (6 1 2 3))
(map-bites sum-at-most-5 list '(1 2 1 1 -1 7 -1 3 1 4)) => ((1 2 1 1 -1) (7) (-1 3 1) (4))
(map-bites increasing list '(2 6 6 7 5 1 -3 1 8 9)) => ((2 6 6 7) (5) (1) (-3 1 8 9))
(map-bites monotone-ints list '(2 6 6 7 5 1 -3 1 8 9)) => ((2 6 6 7) (5 1 -3) (1 8 9))
See also Scheme source file map-bites
Useful bite creators bite-while-element bite-of-length

map-n-bites
Form (map-n-bites make-bite bite-transf lst)
Description A variant of map-bites, which passes the bite number to both make-bite and to bite-transf. So the difference between map-n-bites and map-bites is whether bit-tranf takes a second parameter or not. With this function, the bite number is made available to the bite-transformation function. The first bite is number 1.
Parameters make-bite A function which returns the next bite. Signature: List, Int -> List. (The second parameter is a 1-based bite number).
bite-transf A function which transform a bite: Signature: List, Int -> List. (The second parameter is a 1-based bite number).
lst A list from which bites are taken, one at a time.
See also Scheme source file map-n-bites

filter-bites
Form (filter-bites make-bite bite-pred lst)
Description Successively take bites of list with make-bite, apply the predicate bite-pred on the bite, and splice the bite into the resulting list if bite-pred is true for the bite. The bite number (starting with 1) is passed as the second parameter to make-bite.
Parameters make-bite A function which returns the next bite. Signature: List, Int -> List. (The second parameter is a 1-based bite number).
bite-pred A bite predicate. Signature: List -> Boolean.
lst A list from which bites are taken, one at a time.
Examples (filter-bites (bite-while-element symbol?) (lambda (bite) (even? (length bite))) '(a 1 c d 2 e f g 3 l)) => (a 1 e f g 3)
(filter-bites (bite-while-accumulate + 0 (lambda (sum) (>= sum 5))) (lambda (bite) (even? (length bite))) '(0 1 2 1 2 3 4 0 -2 1 3 4)) => (3 4)
(filter-bites (bite-of-length 3) (lambda (bite) (number? (car bite))) '(1 -1 1 a b c 3 4 b 6 1 2 3)) => (1 -1 1 3 4 b 6 1 2 3)
See also Scheme source file filter-bites
Useful bite creators bite-while-element bite-of-length

filter-map-bites
Form (filter-map-bites make-bite bite-pred bite-transf lst)
Description Filter bites, but additionally map the resulting bites with bite-transf after the filtering.
Parameters make-bite A function which returns the next bite. Signature: List, Int -> List. (The second parameter is a 1-based bite number).
bite-pred A bite predicate. Signature: List -> Boolean.
bite-transf A function which transform a bite: Signature: List -> List. (Notice that this function only takes a single parameter).
lst A list from which bites are taken, one at a time.
Examples (filter-map-bites (bite-while-element number? 'sentinel "alone") (lambda (bite) (>= (length bite) 2)) list '(a b 1 2 c 3 d 4 5 6 e)) => ((1 2) (4 5 6))
(filter-map-bites (bite-of-length 3) (lambda (bite) (number? (car bite))) list '(1 -1 1 a b c 3 4 b 6 1 2 3)) => ((1 -1 1) (3 4 b) (6 1 2) (3))
See also Scheme source file filter-map-bites

step-and-map-bites
Form (step-and-map-bites make-bite bite-pred bite-transf lst)
Description A variant of filter-map-bites which successively and step-wise applies apply bite-pred to prefixes of lst. The bites are constructed by the function make-bite. Prefix bites are examined by bite-pred with the purpose of deciding if the bite should be transformed with bite-transf, or forward bite stepping should be applied. In case of forward bite stepping, the step value determines a new start position of the next bite to be taken out of list. Those bites which are selected by the predicate are transformed by the transformation function, and spliced into the resulting list. Bites which are 'stepped over' are passed non-transformed.
Parameters make-bite A function which selects a prefix of the list (a bite) for examination and possible transformation. The bite number (starting from 1) is passed to this function as the second parameter. Signature: List, Int -> List.
bite-pred A function from a sublist (the bite) to a selection value. Signature: List -> integer. A positive integer serves as boolean true (select). A negative integer n serves as boolean false (deselect) and (- n) is the stepping value. A positive result r means that a prefix of r elements (typically equal to the length of the bite) is selected for transformation, and that the next bite starts r elements ahead. A negative result n means that the next byte taken by make-bite starts (- n) steps ahead. I.e., (-n) elements are passed untransformed to the result, and the start of the next bite is (- r) elements ahead.
bite-transf A transformation function on bites. Signature: List -> List.
lst A list of elements.
Examples (step-and-map-bites (lambda (lst . rest) (list-part 1 3 lst)) (lambda (bite) (if (even? (apply + bite)) (length bite) -1)) list '(0 1 2 1 2 3 4 0 -2 1 3 4 5)) => (0 (1 2 1) 2 3 (4 0 -2) (1 3 4) 5)
(step-and-map-bites (bite-of-length 3) (lambda (bite) (if (even? (apply + bite)) (length bite) -1)) list '(0 1 2 1 2 3 4 0 -2 1 3 4 5)) => (0 (1 2 1) 2 3 (4 0 -2) (1 3 4) 5)
(filter list? (step-and-map-bites (bite-of-length 3) (lambda (bite) (if (even? (apply + bite)) 1 ; <-- The difference -1)) list '(0 1 2 1 2 3 4 0 -2 1 3 4 5))) => ((1 2 1) (1 2 3) (4 0 -2) (-2 1 3) (1 3 4) (3 4 5))
See also Scheme source file step-and-map-bites
Useful bite creators bite-while-element bite-of-length
Variant with bite numbers step-and-map-n-bites
Note Use this function to impose structure on a list, by successively attempting multiple possible bites of the list.

step-and-map-n-bites
Form (step-and-map-n-bites make-bite bite-pred bite-transf lst)
Description A variant of step-and-map-bites that passes the bite number to bite-trans.
Parameters make-bite A function which selects a prefix of the list (a bite) for examination and possible transformation. The bite number (starting from 1) is passed to this function as the second parameter. Signature: List, Int -> List.
bite-pred A function from a sublist (the bite) to a selection value. Signature: List -> integer. A positive integer serves as boolean true (select). A negative integer serves as boolean false (deselect). A positive result r means that a prefix of r elements (typically equal to the length of the bite) is selected for transformation, and that the next bite starts r elements ahead. A negative result r means that (- r) elements are passed untransformed to the result, and that the start of the next potential bite is (- r) elements ahead.
bite-transf A transformation function on bites and bite numbers. Signature: List, Int -> List.
lst A list of elements.
See also Scheme source file step-and-map-n-bites
More basic variant step-and-map-bites


2 Bite Generators.
This section contains higher-order bite generators, which can be used with the functions map-bites, filter-bites, and similar higher-order bite-processing functions, see here . In this context a bite of a non-empty list is a non-empty prefix of the list. Consequtive bites of a list must append-accumulate to the original list. The first parameter of bite functions is the list from which a bite is taken. A second optional parameter denotes the number of this bite (one-based) as supplied by the computational context. Because of this second parameter, all bite functions (programmed or generated) should accept a second parameter, or a rest parameter: (lambda (lst . rest) ....)

bite-of-length
Form (bite-of-length n [noise-element?])
Description Generate and return a function: List -> List, which returns a bite of length n. If the input list is of length shorter than n, just return the list.
Parameters n A integer, n >= 1.
noise-element? An optional predicate with the signature T -> Boolean. Elements that fulfill the predicate are not counted. Such elements are just passed to the resulting bite. The default value of this predicate is (lambda (e) #f).
Returns A bite function of the signature List, int -> List. The integer parameter donotes the number of the bite (supplied by context).
Examples ((bite-of-length 3) '(1 2 3 4 5)) => (1 2 3)
((bite-of-length 3) '(1 2)) => (1 2)
((bite-of-length 3) '()) => ()
((bite-of-length 3 number?) '(a b 1 c 2 3 d e f)) => (a b 1 c)
((bite-of-length 3 number?) ' (1 0 -5 c 2 3 d e f g)) => (1 0 -5 c 2 3 d e)
((bite-of-length 3) '(a b c d e)) => (a b c)
((bite-of-length 3) '(a b c d e)) => (a b c)
(filter-bites (bite-of-length 3) (lambda (bite) (number? (car bite))) '(1 -1 1 a b c 3 4 b 6 1 2 3)) => (1 -1 1 3 4 b 6 1 2 3)
(filter-map-bites (bite-of-length 3) (lambda (bite) (number? (car bite))) list '(1 -1 1 a b c 3 4 b 6 1 2 3)) => ((1 -1 1) (3 4 b) (6 1 2) (3))
(step-and-map-bites (bite-of-length 3) (lambda (bite) (if (even? (apply + bite)) (length bite) -1)) list '(0 1 2 1 2 3 4 0 -2 1 3 4 5)) => (0 (1 2 1) 2 3 (4 0 -2) (1 3 4) 5)
(filter list? (step-and-map-bites (bite-of-length 3) (lambda (bite) (if (even? (apply + bite)) 1 ; <-- The difference -1)) list '(0 1 2 1 2 3 4 0 -2 1 3 4 5))) => ((1 2 1) (1 2 3) (4 0 -2) (-2 1 3) (1 3 4) (3 4 5))
See also Scheme source file bite-of-length

bite-of-varied-length
Form (bite-of-varied-length f [noise-element?])
Description Generate and return a function: List Int -> List, which returns a bite of length f(n), where n is the bite number (1 based) passed as the second parameter to the generated function. If the input list is of length shorter than f(n) for some n, just return the list.
Parameters f A function of the bite number to the length of the desired bite.
noise-element? An optional predicate with the signature T -> Boolean. Elements that fulfill the predicate are not counted. Such elements are just passed to the resulting bite. The default value of this predicate is (lambda (e) #f).
Returns A bite function of the signature List, int -> List. The integer parameter denotes the number of the bite (supplied by context when applied by functions such as map-bites and filter-bites).
Examples (map-bites (bite-of-varied-length (lambda (n) n)) list '(1 2 3 4 5 6 7 8)) => ((1) (2 3) (4 5 6) (7 8))
(map-bites (bite-of-varied-length (lambda (n) (if (even? n) 2 4))) list '(1 2 3 4 5 6 7 8 9 10 11 12)) => ((1 2 3 4) (5 6) (7 8 9 10) (11 12))
((bite-of-varied-length (lambda (n) (+ n 1))) '(1 2 3 4 5) 2) => (1 2 3)
((bite-of-varied-length (lambda (n) (+ n 1))) '() 1) => ()
See also Scheme source file bite-of-varied-length

bite-while-element
Form (bite-while-element el-pred . attributes)
Description Generate and return a function: List -> List, which returns the longest prefix bite in which each element, appart from sentinel elements, fulfills the prediciate el-pred. The construction of the bite terminates if/when a sentinel element is encountered, which does not satisfy el-pred. Due to the definition of bites, the sentinel elements must (in one way or another) be part of the bites of list. The attribute named sentinel controls the location of sentinel elements relative to non-sentinel elements.
Parameters el-pred: A list element predicate. Signature: List-element -> Boolean.
Attributes
Required: *
sentinel Controls how/if a sentiel element takes part in the contextually formed bites. Possible sentinel-values are first, last, and alone (a string or symbol). Default value: last. The value last prescribes that a bite is terminated by a single sentinel value. The value first prescribes that a bite is starts with a single sentinel value. The value alone prescribes that a single sentinel value forms a bite by itself.
Returns A function of the signature: List -> List, which returns a bit of the input list.
Examples ((bite-while-element number?) '(a b c)) => (a)
((bite-while-element number?) '(1 2 a b c)) => (1 2 a)
((bite-while-element number? 'sentinel "last") '(1 2 a b c)) => (1 2 a)
((bite-while-element number? 'sentinel "first") '(a 1 2 a b c)) => (a 1 2)
((bite-while-element number?) '()) => ()
((bite-while-element number?) '(1 2)) => (1 2)
((bite-while-element number? 'sentinel "alone") '(1 2 a b c)) => (1 2)
((bite-while-element number? 'sentinel "alone") '(a 1 2 b c)) => (a)
((bite-while-element even? 'sentinel "first") '(1 2 6 7 4)) => (1 2 6)
((bite-while-element even? 'sentinel "alone") '(1 2 6 7 4)) => (1)
((bite-while-element even? 'sentinel "last") '(1 2 6 7 4)) => (1)
((bite-while-element even? 'sentinel "last") '(2 6 7 4)) => (2 6 7)
(map-bites (bite-while-element number?) list '(1 -1 1 a 3 4 b 6 1 2 3)) => ((1 -1 1 a) (3 4 b) (6 1 2 3))
(map-bites (bite-while-element number? 'sentinel "alone") list '(1 -1 1 a b c 3 4 b 6 1 2 3)) => ((1 -1 1) (a) (b) (c) (3 4) (b) (6 1 2 3))
See also Scheme source file bite-while-element
Useful in context of map-bites filter-bites

bite-while-element-with-accumulation
Form (bite-while-element-with-accumulation pred accumulator init-acc-val [noise-element?])
Description Generate and return a function: List -> List, which returns the longest prefix bite in which each element, appart from a sentinel element, fulfills the prediciate pred. The predicate pred depends on a single list element together with a value accumulated from all elements prior to (but not including) the current element. A sentinel element is an element which terminates a bites. In functions generated by bite-while-element-with-accumulation, a sentinel element may start a bite (thus this function always 'eats' the first element, without passing it to pred). Elements which fulfill the optional noise-element predicate are not tested by pred, they are not considered as sentinel elements, and they are not accumulated.
Parameters pred A predicate with the signature: T, S -> Boolean. The first parameter is a list element. The second parameter is the accumulated value.
accumulator A function of signature S, T -> S, where S is the type of init-acc-val, and T is the type of list elements in bites.
init-acc-val The initial value (first parameter, of type S) of the accumulated value.
noise-element? An optional predicate with the signature T -> Boolean. Elements that fulfill the predicate are not accumulated. Such elements are just passed to the resulting bite. The default value of this predicate is (lambda (e) #f).
Examples ((bite-while-element-with-accumulation (lambda (e v) (and (number? e) (<= v 5))) (lambda (v e) (+ v e)) 0) '()) => ()
((bite-while-element-with-accumulation (lambda (e v) (and (number? e) (<= v 5))) (lambda (v e) (+ v e)) 0) '(0 1 2 -3 3 4 4 2 2)) => (0 1 2 -3 3 4)
((bite-while-element-with-accumulation (lambda (e v) (and (number? e) (<= v 5))) (lambda (v e) (+ v e)) 0 symbol?) '(a 0 b 1 c d 2 -3 e f g 3 4 4 2 2)) => (a 0 b 1 c d 2 -3 e f g 3 4)
((bite-while-element-with-accumulation (lambda (e v) (and (number? e) (<= v 5))) (lambda (v e) (+ v e)) 0 symbol?) '(a 0 b 2 4 d e 5)) => (a 0 b 2 4 d e)
((bite-while-element-with-accumulation (lambda (e v) (<= (+ e v) 5)) (lambda (v e) (+ v e)) 0) '(1 2 1 1 -1 2 3 4)) => (1 2 1 1 -1)
See also Scheme source file bite-while-element-with-accumulation

bite-while-prefix
Form (bite-while-prefix bite-pred)
Description Generate and return a function: List -> List, which returns the longest bite of the input list, of which each prefix bite satisfies bite-pred. A prefix bite of length one is automatically accepted (bite-pred is not applied on it). This ensures that no empty bite is encountered.
Parameters bite-pred A predicate on List-T, where T is the type of elements in the list. Signature T-List -> Boolean.
See also Scheme source file bite-while-prefix
Note The automatic acceptance of unity bites naturally goes hand in hand with bite predicates that accept such bites. This function does not accept a noise element predicate, because it is more natural (and more efficient) to incorporate it in the bite predicate.

bite-while-accumulate
Form (bite-while-accumulate bin-op init-val pred [noise-element?])
Description Generate and return a function, which returns the shortest (first) non-empty prefix bite that accumulates to a value which fulfills the predicate pred. The last bite of a list is not required to accumulate to a result which fulfills the predicate. The accumulation is carried out by the function bin-op, which initially is applied on init-val and the first element of the list.
Parameters bin-op. A binary accumulator function of signature S x T -> S, where T is the type of the list elements, and S is the type of init-val.
init-val The initial value (of type S).
pred A predicate of signature: S -> Boolean, where S is the type of init-val. The predicate determines if a bite, as accumulated to some value in type S, is satisfactory.
noise-element? An optional predicate with the signature T -> Boolean. Elements that fulfill the predicate are not accumulated. Such elements are just passed to the resulting bite. The default value of this predicate is (lambda (e) #f).
Returns A bite function of the signature: T-List -> T-List.
Examples ((bite-while-accumulate + 0 (lambda (n) (>= n 5))) '(1 1 1 2 3 4 5 6)) => (1 1 1 2)
((bite-while-accumulate + 0 (lambda (n) (>= n 5))) '(1 1 1 1)) => (1 1 1 1)
((bite-while-accumulate + 0 (lambda (n) (>= n 5))) '(6 1 2)) => (6)
((bite-while-accumulate + 0 (lambda (n) (>= n 5))) '()) => ()
((bite-while-accumulate (lambda (x y) (cons y x)) '() (lambda (lst) (= 3 (length lst)))) '(a b c d e f g h)) => (a b c)
((bite-while-accumulate + 0 (lambda (n) (>= n 5)) symbol?) '(a b c 1 2 3 4 5)) => (a b c 1 2 3)
((bite-while-accumulate + 0 (lambda (n) (>= n 5)) symbol?) '(1 a 2 b 3 c 4 d 5)) => (1 a 2 b 3)
((bite-while-accumulate + 0 (lambda (n) (>= n 5)) symbol?) '(a b c)) => (a b c)
See also Scheme source file bite-while-accumulate
Useful in context of map-bites filter-bites

bite-while-compare
Form (bite-while-compare el-relation [noise-element?])
Description Generate and return a function, which - when applied on a list - returns the longest bite of the list in which successive elements fulfill the binary relation el-relation.
Parameters el-relation A function of the signature T x T -> Boolean, which compares two elements from the list. T is the type of non-noise (only!) elements in the list on which the generated function is to be applied.
noise-element? An optional predicate with the signature T -> Boolean. Elements that fulfill the predicate are not subject to comparison. Such elements are just passed to the resulting bite. The default value of this predicate is (lambda (e) #f).
Returns A bite function of the signature: T-List -> T-List.
Examples ((bite-while-compare <=) '(2 4 6 6 7 1 2)) => (2 4 6 6 7)
((bite-while-compare <=) '(2 4 6 6 7)) => (2 4 6 6 7)
((bite-while-compare <=) '(3 2 1)) => (3)
((bite-while-compare <=) '()) => ()
((bite-while-compare < symbol?) '(a 0 b c 1 d 2 -1 e f g 7 2 3)) => (a 0 b c 1 d 2)
((bite-while-compare <=) '(2 6 6 7 1 2)) => (2 6 6 7)
See also Scheme source file bite-while-compare

bite-while-monotone
Form (bite-while-monotone el-comparator [noise-element?])
Description Generate and return a function, which - when applied on a list - returns the longest bite of the list in which successive elements are monotone measured by the el-comparator function. Being monotone (in the context of this function) means to be either increasing, being decreasing, or being constant. Please notice that no fixed alternation between bites (such as increasing, decreasing, increasing, decreasing, ...) is assured by this function. When applied on a list of at least two element, a function generated by bite-while-monotone will never return a bite of length less than two.
Parameters el-comparator A function of the signature T x T -> Int which compares two elements from the list. T is the type of non-noise (only!) elements in the list on which the generated function is to be applied. (el-comparator x y) returns -1 if x is less than y, 0 if x equals y, and 1 if x is greater than y.
noise-element? An optional predicate with the signature T -> Boolean. Elements that fulfill the predicate are not subject to comparison. Such elements are just passed to the resulting bite. The default value of this predicate is (lambda (e) #f).
Returns A bite function of the signature: T-List -> T-List.
Examples ((bite-while-monotone (make-comparator < >)) '()) => ()
((bite-while-monotone (make-comparator < >)) '(1)) => (1)
((bite-while-monotone (make-comparator < >)) '(1 2)) => (1 2)
((bite-while-monotone (make-comparator < >)) '(1 2 1)) => (1 2)
((bite-while-monotone (make-comparator < >)) '(2 1 2 1)) => (2 1)
((bite-while-monotone (make-comparator < >)) '(1 2 3 4 5 1 2)) => (1 2 3 4 5)
((bite-while-monotone (make-comparator < >)) '(5 4 3 2 1 1)) => (5 4 3 2 1)
((bite-while-monotone (make-comparator < >)) '(1 1 1 2 3)) => (1 1 1)
((bite-while-monotone (make-comparator < >) symbol?) '(a)) => (a)
((bite-while-monotone (make-comparator < >) symbol?) '(a b)) => (a b)
((bite-while-monotone (make-comparator < >) symbol?) '(a 1 b c 2 1 d 1)) => (a 1 b c 2)
(map-bites (bite-while-monotone (make-comparator < >)) list '(1 2 1 2 1 2 3 4)) => ((1 2) (1 2) (1 2 3 4))
((bite-while-monotone (make-comparator < >)) '(1 2 3 2 1 0 1 2 3 1 2 1)) => (1 2 3)
See also Scheme source file bite-while-monotone
comparator generation make-comparator

Generated: Wednesday, March 28, 2012, 12:32:40
Generated by LAML SchemeDoc using LAML Version 39.0 (November 14, 2011, development)