(((title . "Bites of Lists - Mapping and Filtering Sublists") (author (ast "span" ("Kurt Nørmark" #t " " #t (char-ref copy)) () double xhtml10-transitional ()) #t "normark@cs.aau.dk") (affiliation "Department of Computer Science," #t "Aalborg University," #t "Denmark.") (abstract . " 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. ") (scheme-source-file . "y:/Kurt/Files/.public_html/bites-of-lists/bite-stuff.scm/") (laml-resource . "false") (documentation-commenting-style . not-provided) (default-attribute-explanation . not-provided) (source-destination-delta . not-provided) (css-prestylesheet . "compact") (css-stylesheet . "argentina") (css-stylesheet-copying . "true") (make-dtd-manual-template . not-provided) (keep-syntactical-comment-file . "true") (manual-destination-name . not-provided) (mirror-names-defined . not-provided) (mirror-name-prefix . not-provided) (attribute-sorting . not-provided) (scheme-source-linking . "true")) ((kind "manual-section") (section-title "Higher-order bite functions.") (section-body "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 .") (section-id "higher-order-bite-functions")) ((kind "manual-page") (parameters (parameter "make-bite" "A function which returns the next bite. Signature: List, Int -> List. ") (parameter "bite-transf" "A function which transform a bite: Signature: List -> List. (Notice that this function only takes a single parameter).") (parameter "lst" "A list from which bites are taken, one at a time.")) (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. ") (title "map-bites") (form (map-bites make-bite bite-transf lst)) (cross-references (reference "Scheme source file" "map-bites" "bite-stuff-ep/bite-stuff-1.html#map-bites") (internal-references "Useful bite creators" "bite-while-element" "bite-of-length")) (examples (example "(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))") (example "(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))") (example "(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))") (example "(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))") (example "(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))") (example "(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))") (example "(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))") (example "(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))") (example "(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))") (example "(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))") (example "(map-bites (bite-while-monotone (make-comparator < >)) list '(1 2 1 2 1 2 3 4)) => ((1 2) (1 2) (1 2 3 4))") (example "(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))") (example "(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))") (example " (map-bites (bite-while-element number?) list\n '(1 -1 1 a 3 4 b 6 1 2 3)) => ((1 -1 1 a) (3 4 b) (6 1 2 3))") (example " (map-bites\n (bite-while-element number? 'sentinel \"alone\")\n list\n '(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))") (example "(map-bites sum-at-most-5 list\n '(1 2 1 1 -1 7 -1 3 1 4)) => ((1 2 1 1 -1) (7) (-1 3 1) (4))") (example " (map-bites increasing list \n '(2 6 6 7 5 1 -3 1 8 9)) => ((2 6 6 7) (5) (1) (-3 1 8 9))") (example " (map-bites monotone-ints list\n '(2 6 6 7 5 1 -3 1 8 9)) => ((2 6 6 7) (5 1 -3) (1 8 9))"))) ((cross-references (reference "Scheme source file" "map-n-bites" "bite-stuff-ep/bite-stuff-1.html#map-n-bites")) (kind "manual-page") (parameters (parameter "make-bite" "A function which returns the next bite. Signature: List, Int -> List. (The second parameter is a 1-based bite number).") (parameter "bite-transf" "A function which transform a bite: Signature: List, Int -> List. (The second parameter is a 1-based bite number).") (parameter "lst" "A list from which bites are taken, one at a time.")) (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. ") (title "map-n-bites") (form (map-n-bites make-bite bite-transf lst)) (examples)) ((kind "manual-page") (parameters (parameter "make-bite" "A function which returns the next bite. Signature: List, Int -> List. (The second parameter is a 1-based bite number).") (parameter "bite-pred" "A bite predicate. Signature: List -> Boolean.") (parameter "lst" "A list from which bites are taken, one at a time.")) (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. ") (title "filter-bites") (form (filter-bites make-bite bite-pred lst)) (cross-references (reference "Scheme source file" "filter-bites" "bite-stuff-ep/bite-stuff-1.html#filter-bites") (internal-references "Useful bite creators" "bite-while-element" "bite-of-length")) (examples (example "(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)") (example "(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)") (example " (filter-bites\n (bite-of-length 3) \n (lambda (bite) (number? (car bite)))\n '(1 -1 1 a b c 3 4 b 6 1 2 3)) => (1 -1 1 3 4 b 6 1 2 3)"))) ((cross-references (reference "Scheme source file" "filter-map-bites" "bite-stuff-ep/bite-stuff-1.html#filter-map-bites")) (kind "manual-page") (parameters (parameter "make-bite" "A function which returns the next bite. Signature: List, Int -> List. (The second parameter is a 1-based bite number).") (parameter "bite-pred" "A bite predicate. Signature: List -> Boolean.") (parameter "bite-transf" "A function which transform a bite: Signature: List -> List. (Notice that this function only takes a single parameter).") (parameter "lst" "A list from which bites are taken, one at a time.")) (description "Filter bites, but additionally map the resulting bites with bite-transf after the filtering. ") (title "filter-map-bites") (form (filter-map-bites make-bite bite-pred bite-transf lst)) (examples (example "(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))") (example " (filter-map-bites\n (bite-of-length 3)\n (lambda (bite) (number? (car bite)))\n list\n '(1 -1 1 a b c 3 4 b 6 1 2 3)) => ((1 -1 1) (3 4 b) (6 1 2) (3))"))) ((kind "manual-page") (parameters (parameter "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.") (parameter "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.") (parameter "bite-transf" "A transformation function on bites. Signature: List -> List.") (parameter "lst" "A list of elements.")) (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. ") (misc "Use this function to impose structure on a list, by successively attempting multiple possible bites of the list. ") (title "step-and-map-bites") (form (step-and-map-bites make-bite bite-pred bite-transf lst)) (cross-references (reference "Scheme source file" "step-and-map-bites" "bite-stuff-ep/bite-stuff-1.html#step-and-map-bites") (internal-references "Useful bite creators" "bite-while-element" "bite-of-length") (internal-references "Variant with bite numbers" "step-and-map-n-bites")) (examples (example "(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)") (example " (step-and-map-bites \n (bite-of-length 3)\n (lambda (bite) (if (even? (apply + bite))\n (length bite)\n -1))\n list\n '(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)") (example "(filter list?\n (step-and-map-bites \n (bite-of-length 3)\n (lambda (bite) (if (even? (apply + bite))\n 1 ; <-- The difference\n -1))\n list\n '(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))"))) ((kind "manual-page") (parameters (parameter "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.") (parameter "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.") (parameter "bite-transf" "A transformation function on bites and bite numbers. Signature: List, Int -> List.") (parameter "lst" "A list of elements.")) (description "A variant of step-and-map-bites that passes the bite number to bite-trans. ") (title "step-and-map-n-bites") (form (step-and-map-n-bites make-bite bite-pred bite-transf lst)) (cross-references (reference "Scheme source file" "step-and-map-n-bites" "bite-stuff-ep/bite-stuff-1.html#step-and-map-n-bites") (internal-references "More basic variant" "step-and-map-bites")) (examples)) ((kind "manual-section") (section-title "Bite Generators.") (section-body "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) ....)") (section-id "bite-generators")) ((cross-references (reference "Scheme source file" "bite-of-length" "bite-stuff-ep/bite-stuff-1.html#bite-of-length")) (kind "manual-page") (parameters (parameter "n" "A integer, n >= 1.") (parameter "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).")) (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. ") (form "(bite-of-length n [noise-element?])") (returns "A bite function of the signature List, int -> List. The integer parameter donotes the number of the bite (supplied by context).") (title "bite-of-length") (examples (example "((bite-of-length 3) '(1 2 3 4 5)) => (1 2 3)") (example "((bite-of-length 3) '(1 2)) => (1 2)") (example "((bite-of-length 3) '()) => ()") (example "((bite-of-length 3 number?) '(a b 1 c 2 3 d e f)) => (a b 1 c)") (example "((bite-of-length 3 number?) ' (1 0 -5 c 2 3 d e f g)) => (1 0 -5 c 2 3 d e)") (example "((bite-of-length 3) '(a b c d e)) => (a b c)") (example "((bite-of-length 3) '(a b c d e)) => (a b c)") (example " (filter-bites\n (bite-of-length 3) \n (lambda (bite) (number? (car bite)))\n '(1 -1 1 a b c 3 4 b 6 1 2 3)) => (1 -1 1 3 4 b 6 1 2 3)") (example " (filter-map-bites\n (bite-of-length 3)\n (lambda (bite) (number? (car bite)))\n list\n '(1 -1 1 a b c 3 4 b 6 1 2 3)) => ((1 -1 1) (3 4 b) (6 1 2) (3))") (example " (step-and-map-bites \n (bite-of-length 3)\n (lambda (bite) (if (even? (apply + bite))\n (length bite)\n -1))\n list\n '(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)") (example "(filter list?\n (step-and-map-bites \n (bite-of-length 3)\n (lambda (bite) (if (even? (apply + bite))\n 1 ; <-- The difference\n -1))\n list\n '(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))"))) ((cross-references (reference "Scheme source file" "bite-of-varied-length" "bite-stuff-ep/bite-stuff-1.html#bite-of-varied-length")) (kind "manual-page") (parameters (parameter "f" "A function of the bite number to the length of the desired bite.") (parameter "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).")) (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. ") (form "(bite-of-varied-length f [noise-element?])") (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).") (title "bite-of-varied-length") (examples (example "(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))") (example "(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))") (example "((bite-of-varied-length (lambda (n) (+ n 1))) '(1 2 3 4 5) 2) => (1 2 3)") (example "((bite-of-varied-length (lambda (n) (+ n 1))) '() 1) => ()"))) ((kind "manual-page") (parameters (parameter "el-pred:" "A list element predicate. Signature: List-element -> Boolean. ")) (xml-in-laml-attributes (xml-in-laml-attribute "sentinel" "implied" "Controls how/if a sentiel element takes part in the contextually formed bites.\n Possible sentinel-values are first, last, and alone (a string or symbol). Default value: last.\n The value last prescribes that a bite is terminated by a single sentinel value.\n The value first prescribes that a bite is starts with a single sentinel value.\n The value alone prescribes that a single sentinel value forms a bite by itself.")) (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. ") (form "(bite-while-element el-pred . attributes)") (returns "A function of the signature: List -> List, which returns a bit of the input list.") (title "bite-while-element") (cross-references (reference "Scheme source file" "bite-while-element" "bite-stuff-ep/bite-stuff-1.html#bite-while-element") (internal-references "Useful in context of" "map-bites" "filter-bites")) (examples (example "((bite-while-element number?) '(a b c)) => (a)") (example "((bite-while-element number?) '(1 2 a b c)) => (1 2 a)") (example "((bite-while-element number? 'sentinel \"last\") '(1 2 a b c)) => (1 2 a)") (example "((bite-while-element number? 'sentinel \"first\") '(a 1 2 a b c)) => (a 1 2)") (example "((bite-while-element number?) '()) => ()") (example "((bite-while-element number?) '(1 2)) => (1 2)") (example "((bite-while-element number? 'sentinel \"alone\") '(1 2 a b c)) => (1 2)") (example "((bite-while-element number? 'sentinel \"alone\") '(a 1 2 b c)) => (a)") (example "((bite-while-element even? 'sentinel \"first\")\n '(1 2 6 7 4)) => (1 2 6)") (example " ((bite-while-element even? 'sentinel \"alone\") \n '(1 2 6 7 4)) => (1)") (example " ((bite-while-element even? 'sentinel \"last\")\n '(1 2 6 7 4)) => (1)") (example " ((bite-while-element even? 'sentinel \"last\")\n '(2 6 7 4)) => (2 6 7)") (example " (map-bites (bite-while-element number?) list\n '(1 -1 1 a 3 4 b 6 1 2 3)) => ((1 -1 1 a) (3 4 b) (6 1 2 3))") (example " (map-bites\n (bite-while-element number? 'sentinel \"alone\")\n list\n '(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))"))) ((cross-references (reference "Scheme source file" "bite-while-element-with-accumulation" "bite-stuff-ep/bite-stuff-1.html#bite-while-element-with-accumulation")) (kind "manual-page") (parameters (parameter "pred" "A predicate with the signature: T, S -> Boolean. The first parameter is a list element. The second parameter is the accumulated value. ") (parameter "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.") (parameter "init-acc-val" "The initial value (first parameter, of type S) of the accumulated value.") (parameter "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).")) (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. ") (form "(bite-while-element-with-accumulation pred accumulator init-acc-val [noise-element?])") (title "bite-while-element-with-accumulation") (examples (example "((bite-while-element-with-accumulation (lambda (e v) (and (number? e) (<= v 5))) (lambda (v e) (+ v e)) 0) '()) => ()") (example "((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)") (example "((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)") (example "((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)") (example " ((bite-while-element-with-accumulation\n (lambda (e v) (<= (+ e v) 5))\n (lambda (v e) (+ v e))\n 0) '(1 2 1 1 -1 2 3 4)) => (1 2 1 1 -1)"))) ((cross-references (reference "Scheme source file" "bite-while-prefix" "bite-stuff-ep/bite-stuff-1.html#bite-while-prefix")) (kind "manual-page") (parameters (parameter "bite-pred" "A predicate on List-T, where T is the type of elements in the list. Signature T-List -> Boolean. ")) (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. ") (misc "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.") (title "bite-while-prefix") (form (bite-while-prefix bite-pred)) (examples)) ((kind "manual-page") (parameters (parameter "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.") (parameter "init-val" "The initial value (of type S).") (parameter "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. ") (parameter "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).")) (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. ") (form "(bite-while-accumulate bin-op init-val pred [noise-element?])") (returns "A bite function of the signature: T-List -> T-List.") (title "bite-while-accumulate") (cross-references (reference "Scheme source file" "bite-while-accumulate" "bite-stuff-ep/bite-stuff-1.html#bite-while-accumulate") (internal-references "Useful in context of" "map-bites" "filter-bites")) (examples (example "((bite-while-accumulate + 0 (lambda (n) (>= n 5))) '(1 1 1 2 3 4 5 6)) => (1 1 1 2)") (example "((bite-while-accumulate + 0 (lambda (n) (>= n 5))) '(1 1 1 1)) => (1 1 1 1)") (example "((bite-while-accumulate + 0 (lambda (n) (>= n 5))) '(6 1 2)) => (6)") (example "((bite-while-accumulate + 0 (lambda (n) (>= n 5))) '()) => ()") (example "((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)") (example "((bite-while-accumulate + 0 (lambda (n) (>= n 5)) symbol?) '(a b c 1 2 3 4 5)) => (a b c 1 2 3)") (example "((bite-while-accumulate + 0 (lambda (n) (>= n 5)) symbol?) '(1 a 2 b 3 c 4 d 5)) => (1 a 2 b 3)") (example "((bite-while-accumulate + 0 (lambda (n) (>= n 5)) symbol?) '(a b c)) => (a b c)"))) ((cross-references (reference "Scheme source file" "bite-while-compare" "bite-stuff-ep/bite-stuff-1.html#bite-while-compare")) (kind "manual-page") (parameters (parameter "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.") (parameter "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).")) (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. ") (form "(bite-while-compare el-relation [noise-element?])") (returns "A bite function of the signature: T-List -> T-List.") (title "bite-while-compare") (examples (example "((bite-while-compare <=) '(2 4 6 6 7 1 2)) => (2 4 6 6 7)") (example "((bite-while-compare <=) '(2 4 6 6 7)) => (2 4 6 6 7)") (example "((bite-while-compare <=) '(3 2 1)) => (3)") (example "((bite-while-compare <=) '()) => ()") (example "((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)") (example " ((bite-while-compare <=)\n '(2 6 6 7 1 2)) => (2 6 6 7)"))) ((kind "manual-page") (parameters (parameter "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.") (parameter "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).")) (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. ") (form "(bite-while-monotone el-comparator [noise-element?])") (returns "A bite function of the signature: T-List -> T-List.") (title "bite-while-monotone") (cross-references (reference "Scheme source file" "bite-while-monotone" "bite-stuff-ep/bite-stuff-1.html#bite-while-monotone") (internal-references "comparator generation" "make-comparator")) (examples (example "((bite-while-monotone (make-comparator < >)) '()) => ()") (example "((bite-while-monotone (make-comparator < >)) '(1)) => (1)") (example "((bite-while-monotone (make-comparator < >)) '(1 2)) => (1 2)") (example "((bite-while-monotone (make-comparator < >)) '(1 2 1)) => (1 2)") (example "((bite-while-monotone (make-comparator < >)) '(2 1 2 1)) => (2 1)") (example "((bite-while-monotone (make-comparator < >)) '(1 2 3 4 5 1 2)) => (1 2 3 4 5)") (example "((bite-while-monotone (make-comparator < >)) '(5 4 3 2 1 1)) => (5 4 3 2 1)") (example "((bite-while-monotone (make-comparator < >)) '(1 1 1 2 3)) => (1 1 1)") (example "((bite-while-monotone (make-comparator < >) symbol?) '(a)) => (a)") (example "((bite-while-monotone (make-comparator < >) symbol?) '(a b)) => (a b)") (example "((bite-while-monotone (make-comparator < >) symbol?) '(a 1 b c 2 1 d 1)) => (a 1 b c 2)") (example "(map-bites (bite-while-monotone (make-comparator < >)) list '(1 2 1 2 1 2 3 4)) => ((1 2) (1 2) (1 2 3 4))") (example " ((bite-while-monotone (make-comparator < >))\n '(1 2 3 2 1 0 1 2 3 1 2 1)) => (1 2 3)"))))