For Gauche 0.9.6


Previous: , Up: Library modules - R7RS standard libraries   [Contents][Index]

10.3 R7RS large

R7RS large is still under development, and we’re gradually adding support of the libraries that has been passed.


Next: , Previous: , Up: R7RS large   [Contents][Index]

10.3.1 scheme.list - R7RS lists

Module: scheme.list

This module is a rich collection of list manipulation procedures, and same as srfi-1.

Note that Gauche supports quite a few scheme.list procedures as built-in. The following procedures can be used without loading scheme.list module. For the manual entries of these procedures, Pairs and Lists.

null-list? cons* last member
take drop take-right drop-right take! drop-right!
delete delete! delete-duplicates delete-duplicates!
assoc alist-copy alist-delete alist-delete!
any every filter filter! fold fold-right find find-tail
split-at split-at! iota

List constructors

Function: xcons cd ca

[R7RS list] {scheme.list} Equivalent to (cons ca cd). Useful to pass to higher-order procedures.

Function: list-tabulate n init-proc

[R7RS list] {scheme.list} Constructs an n-element list, in which each element is generated by (init-proc i).

(list-tabulate 4 values) ⇒ (0 1 2 3)
Function: circular-list elt1 elt2 …

[R7RS list] {scheme.list} Constructs a circular list of the elements.

(circular-list 'z 'q) ⇒ (z q z q z q …)

List predicates

Function: not-pair? x

[R7RS list] {scheme.list} Same as (lambda (x) (not (pair? x))).

SRFI-1 says: Provided as a procedure as it can be useful as the termination condition for list-processing procedures that wish to handle all finite lists, both proper and dotted.

Function: list= elt= list …

[R7RS list] {scheme.list} Determines list equality by comparing every n-th element of given lists by the procedure elt=.

It is an error to apply list= to anything except proper lists.

The equality procedure must be consistent with eq?, i.e.

(eq? x y) ⇒ (elt= x y).

List selectors

Function: first pair
Function: second pair
Function: third pair
Function: fourth pair
Function: fifth pair
Function: sixth pair
Function: seventh pair
Function: eighth pair
Function: ninth pair
Function: tenth pair

[SRFI-1] {scheme.list} Returns n-th element of the (maybe improper) list.

Function: car+cdr pair

[R7RS list] {scheme.list} Returns two values, (car pair) and (cdr pair).

List miscellaneous routines

Function: zip clist1 clist2 …

[R7RS list] {scheme.list} Equivalent to (map list clist1 clist2 …). If zip is passed n lists, it returns a list as long as the shortest of these lists, each element of which is an n-element list comprised of the corresponding elements from the parameter lists.

(zip '(one two three)
     '(1 2 3)
     '(odd even odd even odd even odd even))
     ⇒ ((one 1 odd) (two 2 even) (three 3 odd))

(zip '(1 2 3)) ⇒ ((1) (2) (3))

At least one of the argument lists must be finite:

(zip '(3 1 4 1) (circular-list #f #t))
     ⇒ ((3 #f) (1 #t) (4 #f) (1 #t))
Function: unzip1 list
Function: unzip2 list
Function: unzip3 list
Function: unzip4 list
Function: unzip5 list

[R7RS list] {scheme.list} unzip1 takes a list of lists, where every list must contain at least one element, and returns a list containing the initial element of each such list. unzip2 takes a list of lists, where every list must contain at least two elements, and returns two values: a list of the first elements, and a list of the second elements. unzip3 does the same for the first three elements of the lists, and so on.

(unzip2 '((1 one) (2 two) (3 three))) ⇒
   (1 2 3) and
   (one two three)

List fold, unfold & map

Function: pair-fold kons knil clist1 clist2 …
Function: pair-fold-right kons knil clist1 clist2 …

[R7RS list] {scheme.list} Like fold and fold-right, but the procedure kons gets each cdr of the given clists, instead of car.

(pair-fold cons '() '(a b c d e))
  ⇒ ((e) (d e) (c d e) (b c d e) (a b c d e))

(pair-fold-right cons '() '(a b c d e))
  ⇒ ((a b c d e) (b c d e) (c d e) (d e) (e))
Function: unfold p f g seed :optional tail-gen

[R7RS list] {scheme.list} Fundamental recursive list constructor. Defined by the following recursion.

(unfold p f g seed tail-gen) ≡
   (if (p seed)
       (tail-gen seed)
       (cons (f seed)
             (unfold p f g (g seed))))

That is, p determines where to stop, g is used to generate successive seed value from the current seed value, and f is used to map each seed value to a list element.

(unfold (pa$ = 53) integer->char (pa$ + 1) 48)
  ⇒ (#\0 #\1 #\2 #\3 #\4)
Function: unfold-right p f g seed :optional tail

[R7RS list] {scheme.list} Fundamental iterative list constructor. Defined by the following recursion.

(unfold-right p f g seed tail) ≡
  (let lp ((seed seed) (lis tail))
    (if (p seed)
        lis
        (lp (g seed) (cons (f seed) lis))))
(unfold-right (pa$ = 53) integer->char (pa$ + 1) 48)
 ⇒ (#\4 #\3 #\2 #\1 #\0)
Function: map! f clist1 clist2 …

[R7RS list] {scheme.list} The procedure f is applied to each element of clist1 and corresponding elements of clist2s, and the result is collected to a list. Cells in clist1 is reused to construct the result list.

Function: map-in-order f clist1 clist2 …

[R7RS list] {scheme.list} A variant of map, but it guarantees to apply f on each elements of arguments in a left-to-right order. Since Gauche’s map implementation follows the same order, this function is just a synonym of map.

Function: pair-for-each f clist1 clist2 …

[R7RS list] {scheme.list} Like for-each, but the procedure f is applied on clists themselves first, then each cdrs of them, and so on.

(pair-for-each write '(a b c))
 ⇒ prints (a b c)(b c)(c)

List partitioning

Function: partition pred list
Function: partition! pred list

[R7RS list] {scheme.list} filter and remove simultaneously, i.e. returns two lists, the first is the result of filtering elements of list by pred, and the second is the result of removing elements of list by pred.

(partition odd? '(3 1 4 5 9 2 6))
  ⇒ (3 1 5 9) (4 2 6)

partition! is the linear-update variant. It may destructively modifies list to produce the result.

List searching

Function: take-while pred clist
Function: take-while! pred list

[R7RS list] {scheme.list} Returns the longest initial prefix of clist whose elements all satisfy pred.

Function: drop-while pred clist

[R7RS list] {scheme.list} Drops the longest initial prefix of clist whose elements all satisfy pred, and returns the rest.

Function: span pred clist
Function: span! pred list
Function: break pred clist
Function: break! pred list

[R7RS list] {scheme.list} span is equivalent to (values (take-while pred clist) (drop-while pred clist)). break inverts the sense of pred.

Function: list-index pred clist1 clist2 …

[R7RS list] {scheme.list} Returns the index of the leftmost element that satisfies pred. If no element satisfies pred, #f is returned.

Association lists

Function: alist-cons key datum alist

[R7RS list] {scheme.list} Returns (cons (cons key datum) alist). This is an alias of the Gauche builtin procedure acons.

Lists as sets

These procedures use a list as a set, that is, the elements in a list matter, but their order doesn’t.

All procedures in this category takes a comparison procedure elt=, as the first argument, which is used to determine two elements in the given sets are the same.

Since lists require linear time to search, those procedures aren’t suitable to deal with large sets. See R7RS sets, if you know your sets will contain more than a dozen items or so.

See also Combination library, which concerns combinations of elements in the set.

Function: lset<= elt= list1 …

[R7RS list] {scheme.list} Returns #t iff all elements in list1 are also included in list2, and so on. If no lists are given, or a single list is given, #t is returned.

Function: lset= elt= list1 list2 …

[R7RS list] {scheme.list} Returns #t if all elements in list1 are in list2, and all elements in list2 are in list1, and so on.

(lset= eq? '(b e a) '(a e b) '(e e b a)) ⇒ #t
Function: lset-adjoin elt= list elt …

[R7RS list] {scheme.list} Adds elt … to the set list, if each one is not already a member of list. (The order doesn’t matter).

(lset-adjoin eq? '(a b c) 'a 'e) ⇒ '(e a b c)
Function: lset-union elt= list1 …

[R7RS list] {scheme.list} Returns the union of the sets list1 ….

Function: lset-intersection elt= list1 list2 …

[R7RS list] {scheme.list} Returns a set of elements that are in every lists.

Function: lset-difference elt= list1 list2 …

[R7RS list] {scheme.list} Returns a set of elements that are in list1 but not in list2. In n-ary case, binary differece operation is simply folded.

Function: lset-xor elt= list1 …

[R7RS list] {scheme.list} Returns the exclusive-or of given sets; that is, the returned set consists of the elements that are in either list1 or list2, but not in both. In n-ary case, binary xor operation is simply folded.

Function: lset-diff+intersection elt= list1 list2 …

[R7RS list] {scheme.list} Returns two sets, a difference and an intersection of given sets.

Function: lset-union! elt= list …
Function: lset-intersection! elt= list1 list2 …
Function: lset-difference! elt= list1 list2 …
Function: lset-xor! elt= list1 …
Function: lset-diff+intersection! elt= list1 list2 …

[R7RS list] {scheme.list} Linear update variant of the corresponding procedures. The cells in the first list argument may be reused to construct the result.


Next: , Previous: , Up: R7RS large   [Contents][Index]

10.3.2 scheme.vector - R7RS vectors

Module: scheme.vector

This module adds rich set of vector operations to the built-in / R7RS vector procedures.

The following procedures are built-in. See Vectors, for the description. We only explain the procedures that are not built-in.

make-vector          vector               vector?
vector-ref           vector-set!          vector-length
vector-fill!         vector-copy          vector-copy!
vector-append        vector->list         list->vector
reverse-list->vector vector->string       string->vector
vector-map           vector-map!          vector-for-each

This module is srfi-133, which supersedes srfi-43 (see Vector library (Legacy)). Note that the interface of following procedures in srfi-43 are changed for the consistency:

vector-map           vector-map!          vector-for-each
vector-fold          vector-fold-right    vector-count

Some of the functionalities of srfi-43 version is supported by built-in procedures (e.g. Built-in vector-map-with-index is the same as srfi-43’s vector-map). So there’s little point for new code to use srfi-43.

Vector constructors

Function: vector-unfold f length seed …

[R7RS vector] {scheme.vector} Creates a vector of length length, filling elements left to right by calling f repeatedly.

The procedure f must take as many arguments as one plus number of seed values, and must return the same number of values. The first argument is the index. The first return value is used for the element of the result vector, and the rest of return values are passed to the next call of f.

(vector-unfold (^[i] (* i i)) 5)
 ⇒ #(0 1 4 9 16)

(vector-unfold (^[i x] (values (cons i x) (* x 2))) 8 1)
 ⇒ #((0 . 1) (1 . 2) (2 . 4) (3 . 8)
    (4 . 16) (5 . 32) (6 . 64) (7 . 128))
Function: vector-unfold-right f length seed …

[R7RS vector] {scheme.vector} Creates a vector of length length, filling elements right to left by calling f repeatedly.

The procedure f must take as many arguments as one plus number of seed values, and must return the same number of values. The first argument is the index. The first return value is used for the element of the result vector, and the rest of return values are passed to the next call of f.

(vector-unfold-right (^[i] (* i i)) 5)
 ⇒ #(0 1 4 9 16)

(vector-unfold-right (^[i x] (values (cons i x) (* x 2))) 8 1)
 ⇒ #((0 . 128) (1 . 64) (2 . 32) (3 . 16)
    (4 . 8) (5 . 4) (6 . 2) (7 . 1))
Function: vector-reverse-copy vec :optional start end

[R7RS vector] {scheme.vector} Copies the vector vec with reversing its elements. Optional start and end arguments can limit the range of the input.

(vector-reverse-copy '#(a b c d e) 1 4)
 ⇒ #(d c b)
Function: vector-concatenate list-of-vectors

[R7RS vector] {scheme.vector} Same as (apply vector-append list-of-vectors).

Function: vector-append-subvectors spec …

[R7RS vector] {scheme.vector} The number of arguments must be multiple of 3. The argument list must be in the following format, where each vecN is a vector, and startN and endN are nonnegative integers:

vec1 start1 end1 vec2 start2 end2 …

This procedure creates a new vector by concatenating subvectors specified by each triplet. That is, it works as if it’s the following code, except it avoids copying each subvector:

(vector-append (vector-copy vec1 start1 end1)
               (vector-copy vec2 start2 end2)
               …)

Here’s an example:

(vector-append-subvectors '#(a b c d e) 0 3
                          '#(f g h i j) 2 5)
  ⇒ #(a b c h i j)

Vector predicates

Function: vector-empty? vec

[R7RS vector] {scheme.vector} Returns #t if vec’s length is zero, and #f if vec’s length is more than zero. Signals an error if vec is not a vector.

Function: vector= elt= vec …

[R7RS vector] {scheme.vector} Compares vecs element-wise, using given predicate elt=. Returns #t iff lengths of all the vectors are the same, and every corresponding elements are equal by elt=. Elt= is always called with two arguments and must return #t iff two are the same.

Vector iteration

Function: vector-fold kons knil vec1 vec2 …

[R7RS vector] {scheme.vector} Kons is a procedure that takes n+1 arguments, where n is the number of given vectors. For each element of the given vectors, kons is called as (kons seed e_1i e_2i …), where and e_ni is the i-th element of the vector n. If the lengths of the vectors differ, iteration stops when the shortest vector is exhausted.

The initial value of seed is knil, and the return value from kons is used as the next seed value. The last return value of kons is returned from vector-fold.

The iteration is strictly left to right.

Note that the seed value precedes elements, which is opposite to fold (see Mapping over collection). It’s an unfortunate historical glitch; vector-fold-left would be more consistent name.

(vector-fold (^[a b] (cons b a)) '() '#(a b c d))
  ⇒ (d c b a)
Function: vector-fold-right kons knil vec1 vec2 …

[R7RS vector] {scheme.vector} Like vector-fold, but elements in the vec1 vec2 … are visited from right to left.

Unlike fold-right (see Mapping over sequences), the procedure kons takes the accumulated value in the first argument.

(vector-fold-right (^[a b] (cons b a)) '() '#(a b c d))
  ⇒ (a b c d)
Function: vector-count pred vec1 vec2 …

[R7RS vector] {scheme.vector} Applies pred on each elements in argument vectors (if N vectors are given, pred takes N arguments, the first being i-th element of vec1, the second being i-th element of vec2, etc.) Then returns the number of times pred returned true value. The order pred applied to each element is unspecified.

(vector-count odd? '#(0 1 2 3 4)
  ⇒ 2

(vector-count < '#(7 3 9 1 5) '#(6 8 2 3 8 8))
  ⇒ 3
Function: vector-cumulate f seed vec

[R7RS vector] {scheme.vector} Returns a fresh vector with the same size of vec, with the elements calculated as follows:

The first element of result vector is a result of procedure f called with seed and the first element of vec.

The i-th element of result vector is a result of procedure f called with i-1-th element of result vector and i-th element of vec.

(vector-cumulate string-append "z" '#("a" "b" "c"))
  ⇒ #("za" "zab" "zabc")

Vector searching

Function: vector-index pred vec1 vec2 …
Function: vector-index-right pred vec1 vec2 …

[R7RS vector] {scheme.vector} Returns the index of the first or the last elements in vec1 vec2 … that satisfy pred, respectively. Returns #f if no elements satisfy pred. In vector-index, comparison ends at the end of the shortest vector. For vector-index-right, all the vectors must have the same length.

Function: vector-skip pred vec1 vec2 …
Function: vector-skip-right pred vec1 vec2 …

[R7RS vector] {scheme.vector} Like vector-index and vector-index-right, except that the result of pred is negated. That is, returns the index of the first or the last elements that don’t satisfy pred.

Function: vector-binary-search vec value cmp :optional start end

[R7RS+] {scheme.vector} Look for value in a sorted vector vec, and returns its index if it is found, or #f if it is not found.

Comparison of value and an element in vec is done by a procedure cmp, which takes two arguments, and should return a negative integer if the first argument is less than the second, 0 if they are the same, and a positive integer if the first is greater than the second.

Elements in vec must be ordered from smaller to greater w.r.t. cmp. Using that fact, this procedure performs binary search instead of linear search.

The optional arguments start and end are an extention to SRFI-133, and can be used to limit the range of the search in start-th element (inclusive) to end-th element (exclusive).

Function: vector-any pred vec1 vec2 …

[R7RS vector] {scheme.vector} Applies pred on each corresponding elements of vec1 vec2 … left to right, and as soon as pred returns non-#f value, the procedure stops iteration and returns the value.

If no elements that satisfy pred are found, it returns #f.

Vectors can have different lengths. Iteration stops at the end of the shortest.

Function: vector-every pred vec1 vec2 …

[R7RS vector] {scheme.vector} Applies pred on each corresponding elements of vec1 vec2 … left to right. If all the elements (when the lengths of vectors differ, the first N elements where N is the length of the shortest) satisfy pred, returns the last result of pred. If any of the elements don’t satisfy pred, it returns #f immediately without looking further.

(vector-every < '#(1 2 3 4 5) '#(2 3 4 4 5)
  ⇒ #f

(vector-every (^[x y] (and (real? x) (real? y) (- x y)))
              '#(1 2 3)
              '#(2 4 6))
  ⇒ -3
Function: vector-partition pred vec

[R7RS vector] {scheme.vector} Allocates a fresh vector of the same size as vec, then fill it with elements in vec that satisfy pred, followed by elements that don’t satisfy pred.

Returns two values, the newly created vector and an exact integer of the index of the first element that doesn’t satisfy pred in the returned vector.

(vector-partition odd? '#(1 2 3 4 5 6 7 8))
  ⇒ #(1 3 5 7 2 4 6 8) and 4

Vector mutators

Function: vector-swap! vec i j

[R7RS vector] {scheme.vector} Swaps vector vec’s i-th and j-th elements. Returns unspecified value.

(rlet1 v (vector 'a 'b 'c 'd 'e)
  (vector-swap! v 0 2))
  ⇒ #(c b a d e)
Function: vector-reverse! vec :optional start end

[R7RS vector] {scheme.vector} Reverse the elements of vec. Returns an undefined value. Optional start and end arguments can limit the range of operation.

(rlet1 v (vector 'a 'b 'c 'd 'e)
  (vector-reverse! v 0 4))
  ⇒ #(d c b a e)
Function: vector-reverse-copy! target tstart source :optional sstart send

[R7RS vector] {scheme.vector} Like vector-copy!, but reverses the order of elements from start.

(rlet1 v (vector 'a 'b 'c 'd 'e)
  (vector-reverse-copy! v 2 '#(1 2)))
  ⇒ #(a b 2 1 e)

It is ok to pass the same vector to target and source; it always works even if the regions of source and destination are overlapping.

(rlet1 v (vector 'a 'b 'c 'd 'e)
  (vector-reverse-copy! v 1 v 1))
  ⇒ #(a e d c b)
Function: vector-unfold! f rvec start end seeds …
Function: vector-unfold-right! f rvec start end seeds …

[R7RS vector] {scheme.vector} Fill rvec starting from index start (inclusive) and ending at index end (exclusive), with the elements calculated by f.

The procedure f takes the number of seed values seeds … plus one arguments. The first argument is the current index, followed by seed values. The same number of values as the arguments must be returned from f; the first return value is used to fill the current element of rvec, and the rest of the values are used as the next seed values.

The result vector is filled from left to right by vector-unfold!, and right to left by vector-unfold-right!. The return value is unspecified.

(let1 rvec (vector 'a 'b 'c 'd 'e 'f)
  (vector-unfold! (^[i] (+ i 1)) rvec 1 4)
  rvec)
 ⇒ #(a 2 3 4 e f)

(let1 rvec (vector 'a 'b 'c 'd 'e 'f)
  (vector-unfold-right! (^[i] (+ i 1)) rvec 1 4)
  rvec)
 ⇒ #(a 2 3 4 e f)

(let1 rvec (vector 'a 'b 'c 'd 'e 'f)
  (vector-unfold! (^[i x] (values x (* x 2))) rvec 1 5 10)
  rvec)
 ⇒ #(a 10 20 40 80 f)

(let1 rvec (vector 'a 'b 'c 'd 'e 'f)
  (vector-unfold! (^[i x] (values x (* x 2))) rvec 1 5 10)
  rvec)
 ⇒ #(a 80 40 20 10 f)

Vector conversion

Function: reverse-vector->list vec :optional start end

[R7RS vector] {scheme.vector} Same as (reverse (vector->list vec start end)), but more efficient.


Next: , Previous: , Up: R7RS large   [Contents][Index]

10.3.3 scheme.sort - R7RS sort

Module: scheme.sort

Provides utilities to sort, and to work on sorted lists/vectors. This module is the same as srfi-132.

Gauche has built-in sort and merge procedures (see Sorting and merging). This module has a bit different API. Notably, the ordering predicate comes first than the sequence to be sorted, and the procedures dealing with vectors uniformly support start/end arguments

This module also provide useful procedures working on sorted or partially sorted sequences.

Function: list-sort elt< lis
Function: list-sort! elt< lis
Function: list-stable-sort elt< lis
Function: list-stable-sort! elt< lis

[R7RS sort] {scheme.sort} Sort elements in a list lis according to the ordering predicate elt<, which takes two elements from lis and returns true iff the first argument is strictly less than the second argument.

Returns a sorted list. The procedures with bang are allowed, but not required, to reuse lis. The “stable” variation guarantees stable sort.

These are basically the same as Gauche’s built-in sort, sort!, stable-sort and stable-sort!, except the Gauche’s version works on any sequences and takes arguments differently. (See Sorting and merging.)

Function: list-sorted? elt< lis

[R7RS sort] {scheme.sort} Returns true if the list list is sorted according to the ordering predicate elt<.

See also sorted? in Sorting and merging.

Function: list-merge elt< lis1 lis2
Function: list-merge! elt< lis1 lis2

[R7RS sort] {scheme.sort} Given two sorted lists lis1 and lis2, returns a new sorted list according to the ordering predicate elt<.

Note that list-merge! works in-place, that is, all the pairs in lis1 and lis2 are reused.

See also merge and merge! in Sorting and merging.

Function: vector-sort elt< vec :optional start end
Function: vector-stable-sort elt< vec :optional start end

[R7RS sort] {scheme.sort} Sort elements in a vector vec according to the ordering predicate elt<, which takes two elements from vec and returns true iff the first argument is strictly less than the second argument. Returns a fresh sorted vector. The “stable” variation guarantees stable sort.

When the optional start and/or end arguments are given, only the portion from start (inclusive) and end (exlusive) of vec are looked at. The result vector’s length is end - start). When end is omitted, the length of vec is assumed.

See also sort and stable-sort in Sorting and merging.

Function: vector-sort! elt< vec :optional start end
Function: vector-stable-sort! elt< vec :optional start end

[R7RS sort] {scheme.sort} Sort elements “in-place” in a vector vec according to the ordering predicate elt<, which takes two elements from vec and returns true iff the first argument is strictly less than the second argument. Upon successful return, vec’s elements are sorted. Returns unspecified value; the caller must rely on the side effect.

When the optional start and/or end arguments are given, only the portion from start (inclusive) and end (exlusive) of vec are sorted; other elements will remain intact. When end is omitted, the length of vec is assumed.

See also sort! and stable-sort! in Sorting and merging.

Function: vector-sorted? elt< vec :optional start end

[R7RS sort] {scheme.sort} Returns true iff vec between start (inclusive) and end (exlusive) is sorted according to the ordering predicate elt<. If start and/or end is/are omitted, 0 and the length of vec are assumed, respectively.

See also sorted? in Sorting and merging.

Function: vector-merge elt< vec1 vec2 :optional start1 end1 start2 end2
Function: vector-merge! elt< rvec vec1 vec2 :optional rstart start1 end1 start2 end2

[R7RS sort] {scheme.sort} Merge two sorted vectors vec1 and vec2 into one vector, according to the ordering predicate elt<.

The optional argument start1 and end1 restricts vec1’s portion to be looked at, and start2 and end2 restricts vec2’s portion to be looked at.

The functional version vector-merge allocates a fresh vector to hold the result, and returns it.

The side-effecting version vector-merge! uses rvec. to hold the result. The procedure doesn’t return a meaningful value. The optional rstart argument specifies the index of rvec from which the result is filled; the default is 0.

Function: list-delete-neighbor-dups elt= lis
Function: list-delete-neighbor-dups! elt= lis
Function: vector-delete-neighbor-dups elt= vec :optional start end)
Function: vector-delete-neighbor-dups! elt= vec :optional start end)

[R7RS sort] {scheme.sort} From the given list lis or vector vec, these procedures delete adjacent duplicate elements. Equivalence is checked by elt= procedure.

(list-delete-neighbor-dups eq? '(m i s s i s s i p p i))
  ⇒ (m i s i s i p i)

The non-destructive versions list-delete-neighbor-dups and vector-delete-neighbor-dups returns a freshly allocated list and vector, respectively.

The destructive list-delete-neighbor-dups! works in-place, reusing pairs of lis. No allocation will be done.

The destructive vector-delete-neighbor-dups! has a bit different interface. It updates vec in-place, but since we can’t change the length of the vector, it gathers the result from the beginning of the vec, then returns the next index newend of vec—that is, after calling this procedure, [start, newend) holds the result. The elements between [newend, end) will remain intact.

The optional start and end arguments limits the region of vec to be looked at.

(vector-delete-neighbor-dups eq? '#(a a a b b c c d d e e f f) 3 10)
  ⇒ #(b c d e)

(let1 v '#(a a a b b c c d d e e f f)
  (cons (vector-delete-neighbor-dups! eq? v 3 10) v))
  ⇒ (7 . #(a a a b c d e d d e e f f))

Note: The gauche.sequence module provides neighbor duplicate deletion on generic sequences. Those procedures are implemented by the generic versions as shown below. See Other operations over sequences, for the details.

list-delete-neighbor-dups

delete-neighbor-dups

list-delete-neighbor-dups!

delete-neighbor-dups-squeeze!

vector-delete-neighbor-dups

delete-neighbor-dups

vector-delete-neighbor-dups!

delete-neighbor-dups!

Function: vector-select! elt< vec k :optional start end

[R7RS sort] {scheme.sort} Select k-th smallest element in vec according to the ordering predicate elt<. K is zero based, i.e. 0 means the smallest. The optional start and end arguments limits the range of vec to be looked at, and defaulted to 0 and the length of vec, respectively. K must satisfy start <= k < end.

This procedure runs in O(n) time, and requires no extra stroage. This procedure may partially modify vec.

Function: vector-separate! elt< vec k :optional start end

[R7RS sort] {scheme.sort} Find k-th smallerst element in vec (pivot) between between start and end, according to the ordering predicate elt<, then rearrange elements between start and end so that elements smaller than the pivot comes between start and start + k, and the rest of the elements come afterwards. When omitted, start is 0 and end is the lenght of the vec.

This can be used as a building block for in-place divide-and-conquer algorithms. Runs in O(n) time.

Function: vector-find-median elt< vec knil :optional mean
Function: vector-find-median! elt< vec knil :optional mean

[R7RS sort] {scheme.sort} Find median value of elements in vec, when ordered by the ordering predicate elt<. Non-destructive version vector-find-median runs in O(n) time. The destructive version vector-find-median! is specified to leave vec sorted, so it runs in O(n log n).

  1. If vec is empty, knil is returned. This is the only case knil is used.
  2. If vec has odd number of elements, the element falls in the exactly the midpoint when ordered, is returned.
  3. If vec has even number of elements, the two elements closest to the midpoint is chosen and passed to the procedure mean, and its result is returned. The default of mean is an arithmetic mean of numbers.
(vector-find-median < #() 0)
  ⇒ 0

(vector-find-median < #(78 61 19 38 51) 0)
  ⇒ 51

(vector-find-median < #(78 61 19 38 51 52) 0)
  ⇒ 103/2

Next: , Previous: , Up: R7RS large   [Contents][Index]

10.3.4 scheme.set - R7RS sets

Module: scheme.set

Sets and bags are unordered collection of Scheme values. A set doesn’t count duplicates; if you add an item which is already in a set, you still have one item of the kind. A bag counts duplicates; if you add an item which is already in a bag, you have two items of the kind.

To check whether the items are “the same”, sets and bags takes a comparator at constrution time. The comparator doesn’t need to have an ordering predicate (we don’t need to order the elements) but has to have a hash function. See Basic comparators, for the details of comparators.

This module is originally specified as srfi-113, and then incorporated to R7RS large.

As a Gauche’s extension, sets and bags implement collection protocol (see Collection framework, for the details), and generic collection operations can be applied.

(coerce-to <list> (set eq-comparator 'a 'b 'a 'b))
  ⇒ (a b)      ; order may differ

(coerce-to <list> (bag eq-comparator 'a 'b 'a 'b))
  ⇒ (a a b b)  ; order may differ

Constructors

Function: set comparator elt …
Function: bag comparator elt …

[R7RS set] {scheme.set} Creates a new set and bag from given elements elt …. Given comparator will be used to compare equality of elements.

(set->list (set eq-comparator 'a 'b 'a 'b))
  ⇒ (a b)

(bag->list (bag eq-comparator 'a 'b 'a 'b))
  ⇒ (a a b b)
Function: set-unfold stop? mapper successor seed comparator
Function: bag-unfold stop? mapper successor seed comparator

[R7RS set] {scheme.set} Procedurally creates a set or a bag. The first three arguments, stop?, mapper and successor, are all procedures that takes one argument, the current seed value. It may be easier to know their types:

seed      :: Seed
stop?     :: Seed -> Boolean
mapper    :: Seed -> ElementType
successor :: Seed -> Seed

The stop? procedure takes the current seed value and returns a boolean value - if it is true, iteration stops.

The mapper procedure takes the current seed value and returns an item, which is to be included in the resulting set or bag.

The successor procedure takes the current seed value and returns the next seed value.

And the seed argument gives the initial seed value.

(set->list (set-unfold (^s (= s 75))
                       integer->char
                       (^s (+ s 1))
                       65
                       eqv-comparator))
 ⇒ (#\D #\H #\A #\E #\I #\J #\B #\F #\C #\G)

Predicates

Function: set-contains? set obj
Function: bag-contains? bag obj

[R7RS set] {scheme.set} Check if obj is in the set or the bag.

Function: set-empty? set
Function: bag-empty? bag

[R7RS set] {scheme.set} Returns #t iff the given set or bag is empty.

Function: set-disjoint? set1 set2
Function: bag-disjoint? bag1 bag2

[R7RS set] {scheme.set} Returns #t iff the given arguments (sets or bags) don’t have common items. Both arguments must have the same comparator—otherwise an error is signaled.

Accessors

Function: set-member set obj default
Function: bag-member bag obj default

[R7RS set] {scheme.set} Returns an element in the given set or bag which is equal to obj in terms of the set’s or the bag’s comparator. If no such element is found, default will be returned.

Note that the returned object doesn’t need to be “the same” as obj in a usual sense. See the following example:

(let s (set string-ci-comparator "abc" def")
  (set-member s "ABC" #f))
  ⇒ "abc"
Function: set-element-comparator set
Function: bag-element-comparator bag

[R7RS set] {scheme.set} Returns the comparator used to compare the elements for the set or the bag.

Updaters

Function: set-adjoin set elt …
Function: bag-adjoin bag elt …

[R7RS set] {scheme.set} Returns a newly created set or bag that contains all the elements in the original set/bag, plus given elements. The new set/bag’s comparator is the same as the original set/bag’s one.

Function: set-replace set elt
Function: bag-replace bag elt

[R7RS set] {scheme.set} Returns a newly created set/bag with the same comparator with the original set/bag, and the same elements, except that the elements equal to elt (in terms of set/bag’s comparator) is replaced by elt. If the original set/bag doesn’t contain an element equal to elt, the original one is returned.

(let ((s (set string-ci-comparator "ABC" "def")))
  (set->list (set-replace s "abc")))
  ⇒ ("abc" "def")
Function: set-delete set elt …
Function: bag-delete bag elt …

[R7RS set] {scheme.set} Returns a newly created set or bag that has the same comparator and the same elements in the original set/bag, except that the item which is equal to elt.

Function: set-delete-all set elt-list
Function: bag-delete-all bag elt-list

[R7RS set] {scheme.set} Returns a newly created set or bag with the same comparator of the original set/bag, with the elements of the original set/bag except the ones listed in elt-list.

Function: set-adjoin! set elt …
Function: bag-adjoin! bag elt …
Function: set-replace! set elt
Function: bag-replace! bag elt
Function: set-delete! set elt …
Function: bag-delete! bag elt …
Function: set-delete-all! set elt-list
Function: bag-delete-all! bag elt-list

[R7RS set] {scheme.set} These are the linear update versions of their counterparts. It works just like the ones without !, except that the original set/bag may be reused to produce the result, instead of new one being allocated.

Note that it’s not guaranteed that the original set/bag is modified, so you should use the return value of them, instead of relying on the side effects.

Function: set-search! set elt failure success
Function: bag-search! bag elt failure success

[R7RS set] {scheme.set} Lookup-and-modify procedures. The failure and success arguments are procedures.

First, they search elt in the given set/bag. If an item that matches elt is found, the success procedure is called with three arguments, as follows:

(success item update remove)

The update argument is a procedure that takes two arguments, as (update new-item retval). It replaces the matching item in the set/bag with new-item, and returns retval. The remove argument is a procedure that takes one argument, as (remove retval). It removes the mathing item in the set/bag, and returns retval.

If an item that matches elt is not found, the failure procedure is called with two arguments, as follows:

(failure insert ignore)

The insert argument is a procedure that takes one argument, as (insert retval). It inserts elt into the set/bag, and returns retval. The ignore argument is a procedure that takes one argument, as (ignore retval). It just returns retval.

The return values of set-search! and bag-search! is the modified set/bag (which may or may not be eq? to the passed one), and the value returned by success or failure procedures.

Note that retval isn’t used in this process; it is just to provide one of the return values of set-search!/bag-search!, for the procedures passed to success or failure are expected to be tail-called.

If there are more than one item that matches elt in a bag, bag-search! only invokes success for the first item it finds. You can recurse into bag-search! in the failure procedure to visit all matching items. It is guaranteed that success and failure procedures are tail-called.

The whole set

Function: set-size set
Function: bag-size bag

[R7RS set] {scheme.set} Returns the number of items in the set/bag.

Function: set-find pred set failure
Function: bag-find pred bag failure

[R7RS set] {scheme.set} Apply pred on each item in the set/bag, and returns the first item on which pred returns true. Since sets and bags are unordered, if there are more than one items that satisfy pred, you won’t know which one will be returned.

If there’re no items that satisfy pred, a thunk failure is called and its result is returned.

Function: set-count pred set
Function: bag-count pred bag

[R7RS set] {scheme.set} Returns the number of items that satisfy pred in the set/bag.

Function: set-any? pred set
Function: bag-any? pred bag

[R7RS set] {scheme.set} Returns true iff any item in the set/bag satisfy pred.

Function: set-every? pred set
Function: bag-every? pred bag

[R7RS set] {scheme.set} Returns true iff every item in the set/bag satisfy pred.

Mapping and folding

Function: set-map comparator proc set
Function: bag-map comparator proc bag

[R7RS set] {scheme.set} Create and return a new set/bag with the comparator comparator, whose items are calculated by applying proc to each element in the original set/bag.

Function: set-for-each proc set
Function: bag-for-each proc bag

[R7RS set] {scheme.set} Apply proc to each element in the set/bag. The result of proc is ignored. Return value is undefined.

Function: set-fold proc seed set
Function: bag-fold proc seed bag

[R7RS set] {scheme.set} For each item in the set/bag, call proc with two arguments, an item and a seed value. What proc returns becomes the next seed value. The seed argument gives the initial seed value, and the last return value of proc will be the result of set-fold/bag-fold.

(bag-fold + 0 (bag eqv-comparator 1 1 2 2 3 3 4 4))
  ⇒ 20
Function: set-filter pred set
Function: bag-filter pred bag

[R7RS set] {scheme.set} Returns a newly created set/bag with the same comparator of the original set/bag, and its content consists of items from the original set/bag that satisfy pred.

(set->list (set-filter odd? (set eqv-comparator 1 2 3 4 5)))
  ⇒ (1 3 5)
Function: set-remove pred set
Function: bag-remove pred bag

[R7RS set] {scheme.set} Returns a newly created set/bag with the same comparator of the original set/bag, and its content consists of items from the original set/bag that does not satisfy pred.

(set->list (set-remove odd? (set eqv-comparator 1 2 3 4 5)))
  ⇒ (2 4)
Function: set-partition pred set
Function: bag-partition pred bag

[R7RS set] {scheme.set} Returns two sets or bags, both have the same comparator of the original set or bag. The first one consists of the items from the original set/bag that satisfy pred, and the second one consists of the items that don’t.

(receive (in out) (set-remove odd? (set eqv-comparator 1 2 3 4 5))
  (values (set->list in)
          (set->list out)))
  ⇒ (1 3 5) and (2 4)
Function: set-filter! pred set
Function: bag-filter! pred bag
Function: set-remove! pred set
Function: bag-remove! pred bag
Function: set-partition! pred set
Function: bag-partition! pred bag

[R7RS set] {scheme.set} Linear update versions of their counterparts (the procedures without !). They work like their respective counterpart, but they are allowed (but not required) to reuse the original set/bag to produce the result(s).

Note that it is not guaranteed that the original set/bag is modified, so you have to use the return value(s) instead of relying on the side effects.

Copying and conversion

Function: set-copy set
Function: bag-copy bag

[R7RS set] {scheme.set} Returns a copy of the set/bag.

Function: set->list set
Function: bag->list bag

[R7RS set] {scheme.set} Returns a list of all items in the set/bag. Since sets and bags are unordered, there’s no guarantee on the order of items.

Function: list->set comparator elt-list
Function: list->bag comparator elt-list

[R7RS set] {scheme.set} Creates a set or a bag with the given comparator, and the list of element. Functionally equivalent to the followings:

(apply set comparator elt-list)
(apply bag comparator elt-list)
Function: list->set! set elt-list
Function: list->bag! bag elt-list

[R7RS set] {scheme.set} Add items in elt-list to the existing set/bag, and returns the updated set/bag. The original set/bag is also modified. Functionally equivalent to the followings:

(apply set-adjoin! set elt-list)
(apply bag-adjoin! bag elt-list)
Function: bag->set bag
Function: set->bag set

[R7RS set] {scheme.set} Conversions between a bag and a set. Returns a newly created bag or set, respectively.

If bag has duplicated items, bag->set coerces them to one item.

Function: set->bag! bag set

[R7RS set] {scheme.set} Adds all items in set to bag, and returns bag. Both bag and set must have the same comparator.

Function: bag->alist bag

[R7RS set] {scheme.set} Returns a list of (item . count), where item is an item in bag, and count is the number of that item in the bag.

Function: alist->bag comparator alist

[R7RS set] {scheme.set} Creates a new bag with comparator, and fills it according to alist, which must be a list of (item . count).

If there’s duplicate items in alist, only fist one counts.

Subsets

Function: set=? set1 set2 …
Function: bag=? bag1 bag2 …

[R7RS set] {scheme.set} Returns true iff all sets/bags have exactly same items.

The comparators of the argument sets/bags are not checked, but assumed to be the same, in terms of the equality of items.

Function: set<? set1 set2 …
Function: bag<? bag1 bag2 …
Function: set>? set1 set2 …
Function: bag>? bag1 bag2 …
Function: set<=? set1 set2 …
Function: bag<=? bag1 bag2 …
Function: set>=? set1 set2 …
Function: bag>=? bag1 bag2 …

[R7RS set] {scheme.set} Returs true iff each preceding set/bag is a proper subset of, a proper superset of, a subset of, or a superset of the following set/bags, respectively.

Again, the comparators of the argument sets/bags are not checked, but assumed to be the same, in terms of the equality of items.

Set theory operations

Function: set-union set1 set2 …
Function: bag-union bag1 bag2 …

[R7RS set] {scheme.set} Returns a newly allocated set or bag which is a union of all the sets/bags.

Function: set-intersection set1 set2 …
Function: bag-intersection bag1 bag2 …

[R7RS set] {scheme.set} Returns a newly allocated set or bag which is an intersection of all the sets/bags.

Function: set-difference set1 set2 …
Function: bag-difference bag1 bag2 …

[R7RS set] {scheme.set} Returns a newly created set or bag that contains items in set1/bag1 except those are also in set2/bag2 ….

(sort (set->list (set-difference (set eqv-comparator 1 2 3 4 5 6 7)
                                 (set eqv-comparator 3 5 7 9 11 13)
                                 (set eqv-comparator 4 8 16 32))))
  ⇒ (1 2 6)
Function: set-xor set1 set2
Function: bag-xor bag1 bag2

[R7RS set] {scheme.set} Returns a newly created set or bag that consists of items that are either in set1/bag1 or set2/bag2, but not in both.

(sort (set->list (set-xor (set eqv-comparator 2 3 5 7 11 13 17)
                          (set eqv-comparator 3 5 7 9 11 13 15))))
  ⇒ (2 9 15 17)
Function: set-union! set1 set2 …
Function: bag-union! bag1 bag2 …
Function: set-intersection! set1 set2 …
Function: bag-intersection! bag1 bag2 …
Function: set-difference! set1 set2 …
Function: bag-difference! bag1 bag2 …
Function: set-xor! set1 set2
Function: bag-xor! bag1 bag2

[R7RS set] {scheme.set} Linear update versions of their corresponding procedures. Those procedures works like their !-less counterparts, except that they are allowed to, but not required to, reuse set1/bag1 to produce the result.

The caller should always use the returned set/bag instead of relying on the side effects.

Bag-specific procedures

Function: bag-sum bag1 bag2 …
Function: bag-sum! bag1 bag2 …

[R7RS set] {scheme.set} Returns a bag that gathers all the items in given bags, counting duplicates. The functional version bag-sum always creates new bag to return. The linear update version bag-sum! is allowed to, but not required to, modify bag1 to produce the result.

(sort (bag->list (bag-sum (bag eqv-comparator 1 1 2 4 5 5 6)
                          (bag eqv-comparator 3 3 5 9))))
  ⇒ (1 1 2 3 3 4 5 5 5 6 9)

Note the difference from bag-union:

(sort (bag->list (bag-union (bag eqv-comparator 1 1 2 4 5 5 6)
                            (bag eqv-comparator 3 3 5 9))))
  ⇒ (1 1 2 3 3 4 5 5 6 9)
Function: bag-product n bag
Function: bag-product! n bag

[R7RS set] {scheme.set} Returns a bag that contains every item as n-times many as the original bag. A fresh bag is created and returned by bag-product, while bag-product! may reuse bag to produce the result.

(sort (bag->list (bag-product 2 (bag eq-comparator 'a 'b 'r 'a))))
  ⇒ (a a a a b b r r)
Function: bag-unique-size bag

[R7RS set] {scheme.set} Returns the number of unique elements in bag.

(bag-unique-size (bag eqv-comparator 1 1 2 2 3 3 4))
 ⇒ 4
Function: bag-element-count bag elt

[R7RS set] {scheme.set} Returns the number of specified element elt in bag.

(bag-element-count (bag eqv-comparator 1 1 2 2 2 3 3) 2)
 ⇒ 3
Function: bag-for-each-unique proc bag

[R7RS set] {scheme.set} For each unique item in bag, calls proc with two arguments: The item, and the count of the item in the bag.

Function: bag-fold-unique proc seed bag

[R7RS set] {scheme.set} For each unique item in bag, calls proc with three arguments: The item, the count of the item, and the previous seed value. The seed argument provides the initial seed value; the result of proc is used for the next seed value, and the last result of proc is returned from bag-fold-unique.

(sort (bag-fold-unique acons '()
        (bag equal-comparator "a" "a" "b" "b" "b" "c" "d"))
      string<? car)
 ⇒ (("a" . 2) ("b" . 3) ("c" . 1) ("d" . 1))
Function: bag-increment! bag elt count
Function: bag-decrement! bag elt count

[R7RS set] {scheme.set} Linear update bag to increase or decrease the count of elt in it by count, which must be an exact integer. Note that the element count won’t get below zero; if a bag has two a’s, and you call (bag-decrement! bag 'a 100), you get a bag with zero a’s.

Comparators

Comparator: set-comparator
Comparator: bag-comparator

[R7RS comparator] {scheme.set} Comparators to be used to compare sets or bags. They don’t provide comparison procedure, for you cannot define a total order among sets or bags. They do provide hash functions.


Next: , Previous: , Up: R7RS large   [Contents][Index]

10.3.5 scheme.charset - R7RS character sets

Module: scheme.charset

Implements character set library, originally defined as SRFI-14. Note that the following character-set procedures are Gauche’s build-in. See Character set.

char-set char-set? char-set-contains? char-set-copy
char-set-complement char-set-complement!

In Gauche, the <char-set> class inherits <collection> and implements the collection protocol, so that the generic operations defined in gauche.collection can also be used (see Collection framework).


Next: , Previous: , Up: R7RS character sets   [Contents][Index]

10.3.5.1 Character-set constructors

Function: list->char-set char-list :optional base-cs
Function: list->char-set! char-list base-cs

[R7RS comparator] {scheme.charset} Constructs a character set from a list of characters char-list. If base-cs is given, it must be a character set, and the characters in it are added to the result character set. List->char-set! is allowed, but not required, to reuse base-cs to store the result.

Function: string->char-set s :optional base-cs
Function: string->char-set! s base-cs

[R7RS charset] {scheme.charset} Like list->char-set and list->char-set!, but take a list of characters from a string s.

Function: char-set-filter pred char-set :optional base-cs
Function: char-set-filter! pred char-set base-cs

[R7RS charset] {scheme.charset} Returns a character set containing every character c in char-set such that (pred c) returns true. If a character set base-cs is given, its content is added to the result. The linear update version char-set-filter! is allowed, but not required, to modify base-cs to store the result.

Function: ucs-range->char-set lower upper :optional error? base-cs
Function: ucs-range->char-set! lower upper error? base-cs

[R7RS charset] {scheme.charset} Creates

Function: integer-range->char-set lower upper :optional error? base-cs
Function: integer-range->char-set! lower upper error? base-cs

{scheme.charset}

Function: ->char-set x

[R7RS charset] {scheme.charset} A convenience function to coerce various kinds of objects to a char-set. The argument x can be a collection of characters, a char-set, or a character. If the argument is a char-set, it is returned as-is. If the argument is a character, a char-set with that single character is returned.

Note: R7RS (scheme charset)’s ->char-set only accepts a string, a char-set or a character as an argument. Gauche extends it so that it can accept any collection of characters.


Next: , Previous: , Up: R7RS character sets   [Contents][Index]

10.3.5.2 Character-set comparison

Function: char-set= char-set1 …

[R7RS charset] {scheme.charset} Returns #t iff all the character sets have exactly the same members.

(char-set=)  ⇒ #t
(char-set= (char-set)) ⇒ #t
(char-set= (string->char-set "cba")
           (list->char-set #\a #\b #\c))
  ⇒ #t
Function: char-set<= char-set1 …

[R7RS charset] {scheme.charset}

Function: char-set-hash char-set :optional bound

[R7RS charset] {scheme.charset}


Next: , Previous: , Up: R7RS character sets   [Contents][Index]

10.3.5.3 Character-set iteration

Function: char-set-cursor char-set

[R7RS charset] {scheme.charset}

Function: char-set-ref char-set cursor

[R7RS charset] {scheme.charset}

Function: char-set-cursor-next char-set cursor

[R7RS charset] {scheme.charset}

Function: end-of-char-set? ccursor

[R7RS charset] {scheme.charset}

Function: char-set-fold kons knil char-set

[R7RS charset] {scheme.charset}

Function: char-set-unfold pred fun gen seed :optional base-char-set
Function: char-set-unfold! pred fun gen seed base-char-set

[R7RS charset] {scheme.charset}

Function: char-set-for-each proc char-set

[R7RS charset] {scheme.charset}

Function: char-set-map proc char-set

[R7RS charset] {scheme.charset}


Next: , Previous: , Up: R7RS character sets   [Contents][Index]

10.3.5.4 Character-set query

Function: char-set-every pred char-set
Function: char-set-any pred char-set
Function: char-set-count pred char-set

[R7RS charset] {scheme.charset} These procedures apply pred to each character in char-set.

char-set-every returns #f as soon as pred returns #f. Otherwise, it returns the result of the last application of pred.

char-set-any returns as soon as pred returns a true value, and the return value is the one pred returns. If pred returns #f for all characters, #f is returned.

char-set-count returns the number of times pred returns a true value.

Note that char-set can be huge (e.g. a complement of small char-set), which can make these procedures take very long.

Function: char-set->list char-set
Function: char-set->string char-set

[R7RS charset] {scheme.charset} Returns a list of each character, or a string consisting of each character, in char-set, respectively. Be careful to apply this on a large char set.


Next: , Previous: , Up: R7RS character sets   [Contents][Index]

10.3.5.5 Character-set algebra

Function: char-set-adjoin char-set char1 …
Function: char-set-adjoin! char-set char1 …

[R7RS charset] {scheme.charset} Returns a character set that adds char1 … to char-set.

Function: char-set-delete char-set char1 …
Function: char-set-delete! char-set char1 …

[R7RS charset] {scheme.charset}

Function: char-set-union char-set …
Function: char-set-union! char-set1 char-set2 …

[R7RS charset] {scheme.charset}

Function: char-set-intersection char-set …
Function: char-set-intersection! char-set1 char-set2 …

[R7RS charset] {scheme.charset}

Function: char-set-difference char-set1 char-set2 …
Function: char-set-difference! char-set1 char-set2 …

[R7RS charset] {scheme.charset}

Function: char-set-xor char-set …
Function: char-set-xor! char-set1 char-set2 …

[R7RS charset] {scheme.charset}

Function: char-set-diff+intersection char-set1 char-set2 …
Function: char-set-diff+intersection! char-set1 char-set2 char-set3 …

[R7RS charset] {scheme.charset}


Previous: , Up: R7RS character sets   [Contents][Index]

10.3.5.6 Predefined character-set

Variable: char-set:letter

[R7RS charset] {scheme.charset}

Variable: char-set:blank

[R7RS charset] {scheme.charset}

Variable: char-set:iso-control

[R7RS charset] {scheme.charset}

Variable: char-set:digit
Variable: char-set:hex-digit

[R7RS charset] {scheme.charset}

Variable: char-set:graphic

[R7RS charset] {scheme.charset}

Variable: char-set:lower-case
Variable: char-set:upper-case
Variable: char-set:title-case

[R7RS charset] {scheme.charset}

Variable: char-set:printing

[R7RS charset] {scheme.charset}

Variable: char-set:punctuation

[R7RS charset] {scheme.charset}

Variable: char-set:whitespace

[R7RS charset] {scheme.charset}

Variable: char-set:symbol

[R7RS charset] {scheme.charset}

Variable: char-set:ascii

[R7RS charset] {scheme.charset}

Variable: char-set:empty

[R7RS charset] {scheme.charset}

Variable: char-set:full

[R7RS charset] {scheme.charset}


Next: , Previous: , Up: R7RS large   [Contents][Index]

10.3.6 scheme.hash-table - R7RS hash tables

Module: scheme.hash-table

This module provides hash table library, originally defined as srfi-125.

Hash table provided with this module is the same as Gauche’s built-in hash table. However, srfi-125 introduces procedures that conflict with Gauche’s original procedures, so Gauche provides those procedures built-in but under aliases. See Hashtables, for the built-in hash table procedures.

With this module, procedures are provided as defined in R7RS. Use this module when you’re writing portable code.

Srfi-125 also defines compatiblity procedures with srfi-69, although saying they’re deprecated. Those deprecated procedures are supported in this module, too.

The following procedures are the same as Gauche’s built-in.

hash-table-unfold   hash-table?       hash-table-contains?
hash-table-exists?  hash-table-empty? hash-table=?
hash-table-mutable? hash-table-ref    hash-table-ref/default
hash-table-set!     hash-table-update!/default
hash-table-clear!   hash-table-size   hash-table-keys
hash-table-values   hash-table-copy   hash-table-empty-copy
hash-table->alist   hash-table-union! hash-table-intersection!
hash-table-differnce!                 hash-table-xor!

See Hashtables, for the description of those procedures.

The following procedures are also provided as Gauche’s built-in, but with -r7 suffix.

hash-table         hash-table-delete! hash-table-intern!
hash-table-update! hash-table-pop!    hash-table-find
hash-table-count   hash-table-map     hash-table-for-each
hash-table-map!    hash-table-map->list
hash-table-prune!
Function: make-hash-table comparator arg …
Function: make-hash-table equal-proc hash-proc arg …

[R7RS hash-table] {scheme.hash-table} This enhances built-in make-hash-table with the second form, that takes two procedures instead of one comparator, as srfi-69.

In the srfi-69 form, equal-proc is a procedure taking two keys to see if they are the same, and hash-proc is a procedure taking a key to calculate its hash value (nonnegative fixnum). The compatibility form is deprecated and should be avoided in the new code.

The optional arg dots are ignored in Gauche.

Function: hash-table cmpr key value …

[R7RS hash-table] {scheme.hash-table} This is the same as built-in hash-table-r7 (see Hashtables).

Construct a new hash table with key-comparator cmpr. It is populated by key value …, which is a list with keys and values appear alternatively. It is an error if the length of key-value list is not even.

Note that srfi-125 defines this procedure to return an immutable hash table if the implementation supports one. Gauche doesn’t provide immutable hash tables (we do have immutable map instead, see Immutable map), but when you’re writing a portable program, be careful not to modify the table returned by this procedure.

Function: alist->hash-table alist cmpr arg …
Function: alist->hash-table equal-proc hash-proc cmpr arg …

[R7RS hash-table] {scheme.hash-table} This enhances built-in alist->hash-table with the second form, that takes two procedures instead of one comparator, as srfi-69.

In the srfi-69 form, equal-proc is a procedure taking two keys to see if they are the same, and hash-proc is a procedure taking a key to calculate its hash value (nonnegative fixnum). The compatibility form is deprecated and should be avoided in the new code.

The optional arg dots are ignored in Gauche.

Function: hash-table-delete! ht key …

[R7RS hash-table] {scheme.hash-table} This is the same as built-in hash-table-delete!-r7.

Deletes entries associated with the given keys from the table ht. It is ok if ht doesn’t have key. Returns the number of entries that are actually deleted.

It differs from built-in hash-table-delete! in two points: The bulit-in one can take exactly one key, and returns a boolean indicating if the entry is actually deleted.

Function: hash-table-intern! ht key failure

[R7RS hash-table] {scheme.hash-table} This is the same as built-in hash-table-intern!-r7.

Search key in ht. If it is found, returns the associated value. If it is not found, call failure without artuments, and insert a new entry associating key and the value failure returns, and returns that new value.

Function: hash-table-update! ht key updater :optional failure success

[R7RS hash-table] {scheme.hash-table} This is the same as built-in hash-table-update!-r7. It takes differnt optional arguments from built-in hash-table-update!.

Updater is a procedure that takes one argument, failure is a thunk, and success is a procedure that takes one argument.

Works the same as follows, except maybe more efficiently.

(hash-table-set! ht key (updater (hash-table-ref ht key failure success)))
Function: hash-table-pop! ht

[R7RS hash-table] {scheme.hash-table} This is the same as built-in hash-table-pop!-r7. It is a completely different procedure as built-in hash-table-pop!.

Removes an arbitrary entry in the hash table ht, and returns the removed entry’s key and value as two values.

If ht is empty, an error is signalled.

Function: hash-table-find proc ht failure

[R7RS hash-table] {scheme.hash-table} This is the same as built-in hash-table-find-r7. It takes different arguments from built-in hash-table-find.

Calls proc with a key and a value of each entry in ht, until proc returns non-false value. If proc returns non-false value, hash-table-find immediately returns it. If proc returns #f for all entries, calls a thunk failure and returns its result.

Function: hash-table-count ht

[R7RS hash-table] {scheme.hash-table} This is the same as built-in hash-table-count-r7.

Calls proc with a key and a value of each entry in ht, and returns the number of times when proc returned true.

Function: hash-table-map proc cmpr ht

[R7RS hash-table] {scheme.hash-table} This is the same as built-in hash-table-map-r7. This is different from built-in hash-table-map.

Creates a fresh hashtable with a key comparator cmpr, then populate it by inserting the key and the result of applying proc on the value of each entry in ht.

Function: hash-table-map! proc ht

[R7RS hash-table] {scheme.hash-table} This is the same as built-in hash-table-map!-r7.

Calls proc on the value of each entry in ht, and update the entry with the result of proc.

Function: hash-table-map->list proc ht

[R7RS hash-table] {scheme.hash-table} This is the same as built-in hash-table-map->list-r7, and same as built-in hash-table-map (not the scheme.hash-table’s hash-table-map) except the order of the arguments.

Apply proc on a key and a value of each entry in ht, in arbitrary order, and returns a list of results.

Function: hash-table-for-each proc ht
Function: hash-table-for-each ht proc

[R7RS hash-table] {scheme.hash-table} Apply proc on a key and a value of each entry in ht. The result of proc is discarded. Returns an unspecified value.

This procedure allows arguments in both order for the compatibility— the first way is the scheme.hash-table recommended one, which is the same as built-in hash-table-for-each-r7, and the latter way is compatible with srfi-69, which is the same as built-in hash-table-for-each.

It is unfortunate that this compatibility thing is extremely confusing; especially in Gauche, you can make anything applicable, so the distinction between procedures and other objects is blurred.

We recommend that you stick to one way or another within a module; if your module uses built-in interface, use (hash-table-for-each ht proc). If your module imports scheme.hash-table, use (hash-table-for-each proc ht).

Function: hash-table-fold proc seed ht
Function: hash-table-fold ht proc seed

[R7RS hash-table] {scheme.hash-table} The proc argument takes three arguments, a key, a value, and the current seed value. The procedure applies proc for each entry in ht, using seed as the first seed value, and using the previous result of proc as the subsequent seed value. Returns the result of the last call of seed.

This procedure allows arguments in both order for the compatibility— the first way is the scheme.hash-table recommended one, which is the same as built-in hash-table-fold-r7, and the latter way is compatible with srfi-69, which is the same as built-in hash-table-fold.

It is unfortunate that this compatibility thing is extremely confusing. We recommend that you stick to one way or another within a module; if your module uses built-in interface, use the second interface. If your module imports scheme.hash-table, use the first interface.

Function: hash-table-prune! proc ht

[R7RS hash-table] {scheme.hash-table} This is the same as built-in hash-table-prune!-r7.

Apply proc on a key and a value of each entry in ht, and deletes the entry if proc returns a true value. This procedure returns an unspecified value.

Function: hash-table-merge! ht1 ht2

[R7RS hash-table] {scheme.hash-table} This is the same as hash-table-union!, and provided just for the compatibility with srfi-69. Deprecated.

Function: hash obj :optional ignore
Function: string-hash obj :optional ignore
Function: string-ci-hash obj :optional ignore
Function: hash-by-identity obj :optional ignore

[R7RS hash-table] {scheme.hash-table} Provided for the compatibility with srfi-69, and are deprecated.

The first three are the same as built-in default-hash, string-hash, and string-ci-hash, except that these accept an optional second argument, which is ignored. Note that hash-by-identity is also defined as the same as default-hash except the ignored optional second argument, per srfi-125, although the name suggests that it would work as if eq-hash.

Do not use these procedures in the new code; you can use comparators instead (default-comparator, string-comparator, string-ci-comparator and eq-comparator, see Predefined comparators). If you do need hash function, you should still avoid hash and hash-by-identity, and use default-hash and eq-hash instead.

Function: hash-table-equivalence-function ht
Function: hash-table-hash-function ht

[R7RS hash-table] {scheme.hash-table} Provided for the compatibility with srfi-69, and are deprecated.

Returns the equivalence function and hash function of a hash table ht.

For the introspection, we recommend to use built-in hash-table-comparator. (Unfortunately, it is not included in scheme.hash-table, though.)


Next: , Previous: , Up: R7RS large   [Contents][Index]

10.3.7 scheme.ideque - R7RS immutable deques

Module: scheme.ideque

This module provides a functional double-ended queue (deque, pronounced as “deck”), with amortized O(1) access of queue operations on either end.

It also serves as a convenient bidrectional list structures in a sense that operations from the end of the list is just as efficient as the ones from the front.

Note: If you don’t need immutability and wants space-efficient deque, you can also use data.ring-buffer as a deque (see Ring buffer).

This module was originally defined as srfi-134, then became a part of R7RS large.

Gauche’s data.ideque is a superset of this module. See Immutable deques.

Function: ideque element …

[R7RS ideque] {scheme.ideque} Returns an ideque with the given elements.

Function: ideque-unfold p f g seed

[R7RS ideque] {scheme.ideque}

Function: ideque-unfold-right p f g seed

[R7RS ideque] {scheme.ideque}

Function: ideque-tabulate size init

[R7RS ideque] {scheme.ideque}

Function: ideque? idq

[R7RS ideque] {scheme.ideque}

Function: ideque-empty? idq

[R7RS ideque] {scheme.ideque}

Function: ideque-add-front idq x
Function: ideque-add-back idq x

[R7RS ideque] {scheme.ideque}

Function: ideque-front idq
Function: ideque-back idq

[R7RS ideque] {scheme.ideque}

Function: ideque-remove-front idq
Function: ideque-remove-back idq

[R7RS ideque] {scheme.ideque}

Function: ideque-reverse idq

[R7RS ideque] {scheme.ideque}

Function: ideque= idq idq2 …

[R7RS ideque] {scheme.ideque}

Function: ideque-ref idq n

[R7RS ideque] {scheme.ideque}

Function: ideque-take idq n
Function: ideque-take-right idq n

[R7RS ideque] {scheme.ideque}

Function: ideque-drop idq n
Function: ideque-drop-right idq n

[R7RS ideque] {scheme.ideque}

Function: ideque-split-at idq n

[R7RS ideque] {scheme.ideque}

Function: ideque-length idq

[R7RS ideque] {scheme.ideque}

Function: ideque-append idq …

[R7RS ideque] {scheme.ideque}

Function: ideque-zip idq idq2 …

[R7RS ideque] {scheme.ideque}

Function: ideque-map proc idq …

[R7RS ideque] {scheme.ideque}

Function: ideque-filter-map proc idq …

[R7RS ideque] {scheme.ideque}

Function: ideque-for-each proc idq …
Function: ideque-for-each-right proc idq …

[R7RS ideque] {scheme.ideque}

Function: ideque-fold proc knil idq …
Function: ideque-fold-right proc knil idq …

[R7RS ideque] {scheme.ideque}

Function: ideque-append-map proc idq …

[R7RS ideque] {scheme.ideque}

Function: ideque-filter pred idq
Function: ideque-remove pred idq

[R7RS ideque] {scheme.ideque}

Function: ideque-partition pred idq

[R7RS ideque] {scheme.ideque}

Function: ideque-find pred idq :optional failure
Function: ideque-find-right pred idq :optional failure

[R7RS ideque] {scheme.ideque}

Function: ideque-take-while pred idq
Function: ideque-take-while-right pred idq

[R7RS ideque] {scheme.ideque}

Function: ideque-drop-while pred idq
Function: ideque-drop-while-right pred idq

[R7RS ideque] {scheme.ideque}

Function: ideque-span pred idq
Function: ideque-break pred idq

[R7RS ideque] {scheme.ideque}

Function: ideque-any pred idq …
Function: ideque-every pred idq …

[R7RS ideque] {scheme.ideque}

Function: ideque->list idq
Function: list->ideque list

[R7RS ideque] {scheme.ideque}

Function: ideque->generator idq
Function: generator->ideque gen

[R7RS ideque] {scheme.ideque}


Next: , Previous: , Up: R7RS large   [Contents][Index]

10.3.8 scheme.generator - R7RS generators

Module: scheme.generator

A generator is a thunk to generate a sequence of values, potentially terminated by EOF. The interface was first defined in srfi-121, then incorporated R7RS large as (scheme generator).

Gauche provides a generator library gauche.generator, which is a superset of scheme.generator. See Generators, for the details.

The following procedures are defined in this module. Please see the respective manual section for each entry.


Next: , Previous: , Up: R7RS large   [Contents][Index]

10.3.9 scheme.lseq - R7RS lazy sequences

Module: scheme.lseq

This module provides lightweight lazy sequence (lseq), conceptually represented by a pair of element and generator. When the rest of sequence is taken, the generator is evaluated and yields another pair of element and generator, and so on. The overhead is one allocation of a pair per element. It is much lighter than streams (see Stream library), which requires to create a thunk for every element.

Gauche already has built-in support for such lazy sequences; we go futher to make it behave like ordinary pairs—that is, if you take cdr of a lazy pair, we automatically forces the generator so it is indistinguishable from an ordinary pair, modulo side effects. See Lazy sequences.

Srfi-127, the original srfi for this module, is a bit ambiguous whether its lazy sequence must be implemented with a pair whose cdr is a generator procedure, or it refers to the pair+generator as a conceptual model. Considering of the purpose of lazy sequence, the concrete implementation shouldn’t matter; that is, the user of lazy sequence should not count on the fact that the lseq is an improper list terminated by a generator procedure. Instead, an lseq should be treated as an opaque object that can be passed to scheme.lseq procedures.

With that premise, we implement this module as just a thin wrapper of Gauche’s native lazy sequence. It is upper-compatible, except that the code that assumes the internal structure could break. Notably, the constructor generator->lseq is the same as Gauche’s built-in, which returns Gauche’s lseq, undistinguishable to the oridnary list.

(procedure? (generator->lseq (generator 1))) 
  ;; => #t, in srfi-127 reference implementation,
  ;;    #f, in our implementation.
Function: lseq? x

[R7RS lseq] {scheme.lseq} Returns true iff x is an object that can be passed to lseq procedures. In Gauche, it returns #t if x is a pair or an empty list, since a lazy pair is indistinguishable from a pair.

Function: lseq=? elt=? lseq1 lseq2

[R7RS lseq] {scheme.lseq} Compare two lseqs element-wise using elt=? and returns #t iff two lseqs are equal.

Function: lseq-car lseq
Function: lseq-first lseq

[R7RS lseq] {scheme.lseq} Returns the first item of lseq. If lseq is empty, an error is raised. In Gauche, these are just aliases of car.

Function: lseq-cdr lseq
Function: lseq-rest lseq

[R7RS lseq] {scheme.lseq} Returns the rest of lseq. If lseq is empty, an error is raised. In Gauche, these are just aliases of cdr.

Function: lseq-take lseq k
Function: lseq-drop lseq k

[R7RS lseq] {scheme.lseq} Returns an lseq that has first k items, or an lseq that skips first k items, respectively.

An error is signaled when the resulting lseq of lseq-take reached at the end of sequence before k items are taken. It is different from Gauche’s ltake, which simply returns () in such case.

On the other hand, lseq-drop is the same as drop in Gauche; it just drops k items from the head of input sequence, regardless of whether it is an ordinary list or lseq.

Function: lseq-realize lseq

[R7RS lseq] {scheme.lseq} Realizes all the elements in lseq, resulting an ordinary list.

Function: lseq->generator lseq

[R7RS lseq] {scheme.lseq} Creates a generator from lseq. In Gauche, this is same as list->generator.

Function: lseq-length lseq

[R7RS lseq] {scheme.lseq} Returns the length of lseq. All the elements in lseq are realized as the side effect. In Gauche, this is same as length.

Function: lseq-append lseq lseq2 …

[R7RS lseq] {scheme.lseq} Append one or more lseqs lazily. This is the same as lappend in Gauche.

Function: lseq-zip lseq lseq2 …

[R7RS lseq] {scheme.lseq} Returns a lazy sequence in which the first element is a list of first elements of lseqs, and so on.

Function: lseq-map proc lseq lseq2 …

[R7RS lseq] {scheme.lseq} Lazy map. The same as Gauche’s lmap. Returns a lazy sequence.

Function: lseq-for-each proc lseq lseq2 …

[R7RS lseq] {scheme.lseq} This one consumes all the input lseqs, applying proc on each corresponding elements of the input sequences for the side effects. In Gauche, it is the same as for-each, for Gauche doesn’t distinguish lseqs and ordinary lists.

Function: lseq-filter pred lseq
Function: lseq-remove pred lseq

[R7RS lseq] {scheme.lseq} Returns an lseq that contains elements from the input lseq that satisfy or don’t satisfy pred, respectively. Lseq-filter is the same as Gauche’s lfilter.

Function: lseq-take-while pred lseq
Function: lseq-drop-while pred lseq

[R7RS lseq] {scheme.lseq} These are the same as Gauche’s ltake-while and drop-while (the latter doesn’t have l-prefix, since it just drops items from the head of the input sequence, regardless of whether it is an ordinary list or an lseq.

Function: lseq-find pred lseq
Function: lseq-find-tail pred lseq
Function: lseq-any pred lseq
Function: lseq-every pred lseq
Function: lseq-index pred lseq
Function: lseq-member pred lseq :optional eq
Function: lseq-memq pred lseq
Function: lseq-memv pred lseq

[R7RS lseq] {scheme.lseq} In Gauche, these are the same as the corresponding list functions, find, find-tail, any, every, list-index, member, memq and memv, respectively, for all of those functions won’t look at input more than necessary so lseqs work just as well as ordinary lists.


Next: , Previous: , Up: R7RS large   [Contents][Index]

10.3.10 scheme.box - R7RS boxes

Module: scheme.box

This module defines the box datatype, which is a simple container that can hold one Scheme object. It can be used as a minimal data storage, or a sort of mutable indirect “pointer”.

Traditionally a pair (with ignoring its cdr) or a single-element vector has been used for this purpose; in modern Scheme you can also define a record type with one mutable field. Nevertheless, a box is very common abstraction to describe various algorithms, and having common interface to it is useful.

The srfi leaves some details to implementations. Here are our choices:

When you’re writing portable code, be careful not to depend on the equal? behavoir.

Function: box val

[R7RS box] {scheme.box} Returns a fresh box object that contains the value val.

Function: box? obj

[R7RS box] {scheme.box} Returns #t iff obj is a box object.

Function: unbox box

[R7RS box] {scheme.box} Returns box’s content.

Function: set-box! box val

[R7RS box] {scheme.box} Mutate box’s content with val. Returns unspecified value.


Next: , Previous: , Up: R7RS large   [Contents][Index]

10.3.11 scheme.list-queue - R7RS list queues

Module: scheme.list-queue

A library of simple queue based on lists. Gauche has a queue support in data.queue module, which also includes MT-safe queue (see Queue). This library is implemented on top of data.queue’s <queue> object and mainly provided for portable code.

The list-queue is just an instance of <queue>, so you can pass a queue created by make-queue to scheme.list-queue API and a list-queue created by make-list-queue to Gauche’s queue API.

Note: Some API of this library requires to return internal pairs the queue uses, for the efficiency. The pair’s car/cdr will be mutated by subsequent queue operation, and also any mutation done on the pair would cause inconsistency in the original queue.

Function: make-list-queue lis :optional last

[R7RS list-queue] {scheme.list-queue} Creates and returns a list-queue whose initial content is lis. In Gauche, a list queue is just an instance of <queue> (see Queue).

The cells in lis are owned by the queue; the caller shouldn’t mutate it afterwords, nor assume its structure remains the same.

The optional last argument must be the last pair of lis. If it is passed, make-list-queue will skip scanning lis and just hold a reference to last as the tail of the queue.

Function: list-queue elt …

[R7RS list-queue] {scheme.list-queue} Creates and returns a list-queue whose initial content is elt …. In Gauche, a list queue is just an instance of <queue> (see Queue).

Function: list-queue-copy queue

[R7RS list-queue] {scheme.list-queue} Returns a copy of a list-queue queue.

Function: list-queue-unfold p f g seed :optional queue

[R7RS list-queue] {scheme.list-queue} Prepend queue with the items generated by (unfold p f g seed) and returns the updated queue. See R7RS lists, for unfold. If queue is omitted, a fresh queue is created.

(list-queue-unfold (pa$ = 5) ; p
                   (pa$ * 2) ; f
                   (pa$ + 1) ; g
                   0         ; seed
                   (list-queue 'x 'y 'z))
 ⇒ a queue containing (0 2 4 6 8 x y z)
Function: list-queue-unfold-right p f g seed :optional queue

[R7RS list-queue] {scheme.list-queue} Append queue with the items generated by (unfold-right p f g seed) and returns the updated queue. See R7RS lists, for unfold-right. If queue is omitted, a fresh queue is created.

(list-queue-unfold-right (pa$ = 5) ; p
                         (pa$ * 2) ; f
                         (pa$ + 1) ; g
                         0         ; seed
                         (list-queue 'x 'y 'z))
 ⇒ a queue containing (x y z 8 6 4 2 0)
Function: list-queue? obj

[R7RS list-queue] {scheme.list-queue} Returns true iff queue is a list-queue. In Gauche, it is the same as queue? in the data.queue module.

Function: list-queue-empty? queue

[R7RS list-queue] {scheme.list-queue} Returns true iff queue is empty. Same as queue-empty? of data.queue.

Function: list-queue-front queue

[R7RS list-queue] {scheme.list-queue} Returns the front element of the queue. An error is thrown if queue is empty. Same as queue-front of data.queue.

Function: list-queue-back queue

[R7RS list-queue] {scheme.list-queue} Returns the rear element of the queue. An error is thrown if queue is empty. Same as queue-rear of data.queue.

Function: list-queue-list queue

[R7RS list-queue] {scheme.list-queue} Returns the internal list of queue. Note that the list would be modified by subsequent operations of queue, and any modification on the list would make queue inconsistent. The primary purpose of this procedure is to implement other queue-related operations with small overhead.

If you merely need a cheap access the content of the queue, consider list-queue-remove-all!. That returns the list of elements of the queue without copying, and simultaneoulsy reset the queue to empty, so it’s safe.

Function: list-queue-fist-last queue

[R7RS list-queue] {scheme.list-queue} Returns two values, the first and last pair of queue. If the queue is empty, two empty lists are returned.

This also returns the internal pair of the queue, so any subsequent operations of queue would change the contents of the pairs, and any modification on the pairs would make queue inconsistent. The purpose of this procedure is to implement other queue-related operations with small overhead. This procedure should not be used in general.

Function: list-queue-add-front! queue elt

[R7RS list-queue] {scheme.list-queue} Add elt to the front of queue. Same as (queue-push! queue elt) of data.queue.

Function: list-queue-add-back! queue elt

[R7RS list-queue] {scheme.list-queue} Add elt to the back of queue. Same as (enqueue! queue elt) of data.queue.

Function: list-queue-remove-front! queue

[R7RS list-queue] {scheme.list-queue} Remove an element from the front of queue and returns the removed element. Throws an error if queue is empty. Same as dequeue! of data.queue.

Function: list-queue-remove-back! queue

[R7RS list-queue] {scheme.list-queue} Remove an element from the back of queue and returns the removed element. Throws an error if queue is empty. This isn’t guaranteed to be efficient; it is O(n) operation where n is the number of elements. In general, if you need this operation frequently, you should consider double-ended queue. (See Immutable deques, and also see Ring buffer.)

Function: list-queue-remove-all! queue

[R7RS list-queue] {scheme.list-queue} Remove all the elements from queue and returns them as a list. The list isn’t copied—this is O(1) operation. This should be preferred over list-queue-list, for it’s safer. In Gauhce, this is the same as dequeue-all! in data.queue.

Function: list-queue-set-list! queue lis :optional last

[R7RS list-queue] {scheme.list-queue} Modify queue to have the elements in lis as its element. The original content of queue is discarded. If the optional last argument is provided, it must be the last pair of lis, and the procedure uses that instead of scanning lis, to achieve O(1) operation.

After calling this, lis is owned by queue and it may be mutated. The caller shouldn’t change, or rely on lis afterwards.

Function: list-queue-append queue …

[R7RS list-queue] {scheme.list-queue} Returns a fresh list-queue whose contents are concatenation of queues. The contents of arguments are intact. This is O(n) operation where n is the total number of elements.

Function: list-queue-append! queue …

[R7RS list-queue] {scheme.list-queue} Returns a list-queue whose contents are concatenation of queues. During the operation, the contents of queues may be mutated, and they shouldn’t be used any longer. (In Gauche, to avoid accident, we actually empty all the queues.) It is also noted that the result doesn’t need to be eq? to any of the arguments. This is O(m) operation where m is the total number of queues (as opposed to the number of elements).

Function: list-queue-concatenate queues

[R7RS list-queue] {scheme.list-queue} (apply list-queue-append queues).

Function: list-queue-map proc queue

[R7RS list-queue] {scheme.list-queue} Returns a fresh list-queue whose elements are obtained by applying proc on every elements in queue.

Function: list-queue-map! proc queue

[R7RS list-queue] {scheme.list-queue} Replaces every element in queue by the result of application of proc on the element.

Function: list-queue-for-each proc queue

[R7RS list-queue] {scheme.list-queue} Applies proc on every element of queue. The results are discarded.


Previous: , Up: R7RS large   [Contents][Index]

10.3.12 scheme.comparator - R7RS comparators

Module: scheme.comparator

This module defines comparators and related procedures. Originally called srfi-128.

Gauche supports comparators fully compatible to scheme.comparator built-in. See Basic comparators, for the following procedures defined in this module.

comparator? comparator-ordered? comparator-hashable?
make-comparator make-pair-comparator
make-list-comparator make-vector-comparator
make-eq-comparator make-eqv-comparator make-equal-comparator

boolean-hash char-hash char-ci-hash string-hash
string-ci-hash symbol-hash number-hash
hash-bound hash-salt

make-default-comparator default-hash
comparator-register-default!

comparator-type-test-predicate comparator-equality-predicate
comparator-ordering-predicate comparator-hash-function
comparator-test-type comparator-check-type comparator-hash

=? <? >? <=? >=? comparator-if<=>

Previous: , Up: R7RS large   [Contents][Index]