You are looking at historical revision 28172 of this page. It may differ significantly from its current revision.

This page is maintained in the package's github repository.

= Traversal

This is a Chicken Scheme egg which contains various list and vector traversal functions. Many of the functions provided by this egg originate from Jeff Siskind's QobiScheme.

## overall

The final character of many of these functions denotes the compairson function being used. 'q' compares with 'eq?', 'v' compares with 'eqv?', 'e' with 'equal?', 'p' and the lack of a final character denotes that the function takes a user-provided predicate.

The following documentation uses the following notation: 'l' list, 'n' number, 'v' vector, 'p' procedure (usually a predicate).

Some of the functionality of this egg is provided by other eggs, like srfi-1, with different naming conventions.

### lists

*[procedure]*

`(countq x l)`

*[procedure]*

`(countv x l)`

*[procedure]*

`(counte x l)`

*[procedure]*

`(countp p x l)`

*[procedure]*

`(count-if p l)`

*[procedure]*

`(count-if-not p l)`

*[procedure]*

`(findq x l)`

*[procedure]*

`(findv x l)`

*[procedure]*

`(finde x l)`

*[procedure]*

`(findp p x l)`

*[procedure]*

`(find-if p l)`

*[procedure]*

`(find-if-not p l)`

*[procedure]*

`(positionq x l)`

*[procedure]*

`(positionv x l)`

*[procedure]*

`(positione x l)`

*[procedure]*

`(position p l)`

*[procedure]*

`(positionp p x l)`

*[procedure]*

`(position-if p l)`

*[procedure]*

`(position-if-not p l)`

*[procedure]*

`(vector-positione val vector)`

*[procedure]*

`(remove-if p l)`

*[procedure]*

`(remove-if-not p l)`

*[procedure]*

`(removee x l)`

*[procedure]*

`(removep p x l)`

*[procedure]*

`(removeq x l)`

*[procedure]*

`(removev x l)`

*[procedure]*

`(remove-duplicatesq x)`

*[procedure]*

`(remove-duplicatesv x)`

*[procedure]*

`(remove-duplicates x)`

*[procedure]*

`(remove-duplicatesp p x)`

*[procedure]*

`(list-set! l i x)`

*[procedure]*

`(list-insert l i x)`

*[procedure]*

`(list-remove l i)`

*[procedure]*

`(list-replace l i x)`

*[procedure]*

`(equivalence-classesq x)`

*[procedure]*

`(equivalence-classesv x)`

*[procedure]*

`(equivalence-classesp p x)`

*[procedure]*

`(equivalence-classes x)`

*[procedure]*

`(transitive-equivalence-classesp p x)`

*[procedure]*

`(adjoinq x l)`

*[procedure]*

`(adjoinv x l)`

*[procedure]*

`(adjoin x l)`

*[procedure]*

`(adjoinp p x l)`

*[procedure]*

`(rest l)`

*[procedure]*

`(but-last l)`

*[procedure]*

`(sublist list start end)`

*[procedure]*

`(every-other list)`

Misc list manipulation stuff.

*[procedure]*

`(sort list predicate key)`

Merge sort.

*[procedure]*

`(lexicographically<? <? =?)`

*[procedure]*

`(minimal-membersp <? =? l)`

*[procedure]*

`(unzip l)`

Transposes lists.

### creation

*[procedure]*

`(enumerate n)`

*[procedure]*

`(enumerate-vector n)`

Produce a list or a vector containing 0 through n-1.

### assertions

*[procedure]*

`(some p l)`

*[procedure]*

`(some-n p n)`

*[procedure]*

`(some-vector p v)`

*[procedure]*

`(every-n p n)`

*[procedure]*

`(every-vector p v)`

*[procedure]*

`(one p l . &rest)`

*[procedure]*

`(one-n p n)`

*[procedure]*

`(one-vector p v . &rest)`

*[procedure]*

`(pairwise? p l)`

Does p hold on each adjacent pair of elements in l.

### traversal

*[procedure]*

`(for-each-n f n)`

*[procedure]*

`(for-each-n-decreasing f n)`

*[procedure]*

`(map-n f n)`

*[procedure]*

`(map-n-vector f n)`

*[procedure]*

`(for-each-from-a-up-to-b f a b)`

*[procedure]*

`(for-each-m-n f m n)`

*[procedure]*

`(for-each-m-n-indexed f m n)`

*[procedure]*

`(for-each-m-n-dec f m n)`

*[procedure]*

`(map-m-n f m n)`

*[procedure]*

`(map-m-n-indexed f m n)`

*[procedure]*

`(for-each-vector f v . &rest)`

*[procedure]*

`(map-vector f v . &rest)`

Like 'vector-map' but take an arbitrary number of vectors.

*[procedure]*

`(map-linear f start end n)`

Map linearly between 'start' and 'end' in 'n' steps.

*[procedure]*

`(reduce-n f i n)`

*[procedure]*

`(reduce-vector f i v)`

*[procedure]*

`(map-reduce g i f l . ls)`

*[procedure]*

`(map-reduce-n g i f n)`

*[procedure]*

`(map-reduce-vector g i f v . vs)`

*[procedure]*

`(map-reduce2 g i f l)`

*[procedure]*

`(map-reduce3 g i f l1 l2)`

Reduces are left folds.

*[procedure]*

`(for-each-indexed f l)`

*[procedure]*

`(map-indexed f l)`

*[procedure]*

`(for-each-indexed-vector f v)`

*[procedure]*

`(map-indexed-vector f v . &rest)`

Passes 'f' both the element and an offset into the list/vector.

*[procedure]*

`(map-medial f l key)`

'f' is passed each adjacent pair of elements in l after being sorted by the key. Key must return a number given each element of l.

*[procedure]*

`(all-pairs l)`

*[procedure]*

`(map-all-pairs f l)`

'f' is passed each adjacent pair of elements in l.

*[procedure]*

`(memp p x l)`

*[procedure]*

`(assp p x alist)`

Like memq and assq but take a predicate for comparison.

*[procedure]*

`(map-accum f i l)`

f will be passed the accumulator and each element of the list.

### sets

*[procedure]*

`(unionq x y)`

*[procedure]*

`(unionv x y)`

*[procedure]*

`(union x y)`

*[procedure]*

`(unionp p x y)`

*[procedure]*

`(unionvt x y)`

*[procedure]*

`(set-differenceq x y)`

*[procedure]*

`(set-differencev x y)`

*[procedure]*

`(set-difference x y)`

*[procedure]*

`(set-differencep p x y)`

*[procedure]*

`(set-differencevt x y)`

*[procedure]*

`(intersectionq x y)`

*[procedure]*

`(intersectionv x y)`

*[procedure]*

`(intersection x y)`

*[procedure]*

`(intersectionp p x y)`

*[procedure]*

`(intersectionvt x y)`

*[procedure]*

`(set-equalq? x y)`

*[procedure]*

`(set-equalv? x y)`

*[procedure]*

`(set-equale? x y)`

*[procedure]*

`(set-equal? p x y)`

*[procedure]*

`(set-equalp? p x y)`

*[procedure]*

`(subsetq? x y)`

*[procedure]*

`(subsetv? x y)`

*[procedure]*

`(subsete? x y)`

*[procedure]*

`(subsetp? p x y)`

*[procedure]*

`(subsetvt? x y)`

### rings

*[procedure]*

`(ring-backward l)`

*[procedure]*

`(ring-forward l)`

*[procedure]*

`(ring-forward-between r a b)`

*[procedure]*

`(ring-forward-to l o)`

These manipulate a list while treating it as a ring.

### minimizing and maximizing

*[procedure]*

`(maximum l)`

*[procedure]*

`(minimum l)`

*[procedure]*

`(maximump p l)`

*[procedure]*

`(minimump p l)`

*[procedure]*

`(maximum-with-position l)`

*[procedure]*

`(minimum-with-position l)`

p is a function that returns a number.

### math

*[procedure]*

`(sum l)`

*[procedure]*

`(sum p n)`

*[procedure]*

`(sum p l)`

*[procedure]*

`(product l)`

*[procedure]*

`(product p n)`

*[procedure]*

`(product p l)`

*[procedure]*

`(factorial n)`

*[procedure]*

`(choose n m)`

### QobiScheme compatibility

*[procedure]*

`(qfind x l)`

*[procedure]*

`(qcount x l)`

*[procedure]*

`(qposition x l)`

*[procedure]*

`(qremove x l)`

*[procedure]*

`(qtopological-sort p l)`

*[procedure]*

`(qset-equal? x y)`

*[procedure]*

`(qreduce f l i)`

*[procedure]*

`(qreduce-vector f v i)`

*[procedure]*

`(qreduce-n f n i)`

*[procedure]*

`(qmap-reduce g i f l . ls)`

*[procedure]*

`(qmap-reduce-n g i f n)`

*[procedure]*

`(qmap-reduce-vector g i f v . vs)`

### License

Copyright 1993-1995 University of Toronto. All rights reserved. Copyright 1996 Technion. All rights reserved. Copyright 1996 and 1997 University of Vermont. All rights reserved. Copyright 1997-2001 NEC Research Institute, Inc. All rights reserved. Copyright 2002-2013 Purdue University. All rights reserved.

Contact Andrei Barbu at andrei@0xab.com.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses.