Previous: R7RS small language, Up: Library modules  R7RS standard libraries [Contents][Index]
R7RS large is still under development, and we’re gradually adding support of the libraries that has been passed.
• R7RS lists:  scheme.list
 
• R7RS vectors:  scheme.vector
 
• R7RS sort:  scheme.sort
 
• R7RS sets:  scheme.set
 
• R7RS character sets:  scheme.charset
 
• R7RS hash tables:  scheme.hashtable
 
• R7RS immutable deques:  scheme.ideque
 
• R7RS generators:  scheme.generator
 
• R7RS lazy sequences:  scheme.lseq
 
• R7RS boxes:  scheme.box
 
• R7RS list queues:  scheme.listqueue
 
• R7RS comparators:  scheme.comparator

Next: R7RS vectors, Previous: R7RS large, Up: R7RS large [Contents][Index]
scheme.list
 R7RS listsThis module is a rich collection of list manipulation procedures,
and same as srfi1
.
Note that Gauche supports quite a few scheme.list
procedures as builtin.
The following procedures can be used
without loading scheme.list
module. For the manual entries of
these procedures, Pairs and Lists.
nulllist? cons* last member take drop takeright dropright take! dropright! delete delete! deleteduplicates deleteduplicates! assoc alistcopy alistdelete alistdelete! any every filter filter! fold foldright find findtail splitat splitat! iota
[R7RS list]
{scheme.list}
Equivalent to (cons ca cd)
. Useful to pass to
higherorder procedures.
[R7RS list]
{scheme.list}
Constructs an nelement list, in which
each element is generated by (initproc i)
.
(listtabulate 4 values) ⇒ (0 1 2 3)
[R7RS list] {scheme.list} Constructs a circular list of the elements.
(circularlist 'z 'q) ⇒ (z q z q z q …)
[R7RS list]
{scheme.list}
Same as (lambda (x) (not (pair? x)))
.
SRFI1 says: Provided as a procedure as it can be useful as the termination condition for listprocessing procedures that wish to handle all finite lists, both proper and dotted.
[R7RS list] {scheme.list} Determines list equality by comparing every nth 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).
[SRFI1] {scheme.list} Returns nth element of the (maybe improper) list.
[R7RS list]
{scheme.list}
Returns two values, (car pair)
and (cdr pair)
.
[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 nelement 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) (circularlist #f #t)) ⇒ ((3 #f) (1 #t) (4 #f) (1 #t))
[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)
[R7RS list]
{scheme.list}
Like fold
and foldright
, but the procedure kons
gets each cdr
of the given clists, instead of car
.
(pairfold cons '() '(a b c d e)) ⇒ ((e) (d e) (c d e) (b c d e) (a b c d e)) (pairfoldright cons '() '(a b c d e)) ⇒ ((a b c d e) (b c d e) (c d e) (d e) (e))
[R7RS list] {scheme.list} Fundamental recursive list constructor. Defined by the following recursion.
(unfold p f g seed tailgen) ≡ (if (p seed) (tailgen 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)
[R7RS list] {scheme.list} Fundamental iterative list constructor. Defined by the following recursion.
(unfoldright p f g seed tail) ≡ (let lp ((seed seed) (lis tail)) (if (p seed) lis (lp (g seed) (cons (f seed) lis))))
(unfoldright (pa$ = 53) integer>char (pa$ + 1) 48) ⇒ (#\4 #\3 #\2 #\1 #\0)
[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.
[R7RS list]
{scheme.list}
A variant of map
, but it guarantees to apply f
on each elements of arguments in a lefttoright order.
Since Gauche’s map
implementation follows the same order,
this function is just a synonym of map
.
[R7RS list]
{scheme.list}
Like foreach
, but the procedure f is applied on
clists themselves first, then each cdr
s of them, and so on.
(pairforeach write '(a b c))
⇒ prints (a b c)(b c)(c)
[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 linearupdate variant. It may destructively
modifies list to produce the result.
[R7RS list] {scheme.list} Returns the longest initial prefix of clist whose elements all satisfy pred.
[R7RS list] {scheme.list} Drops the longest initial prefix of clist whose elements all satisfy pred, and returns the rest.
[R7RS list]
{scheme.list}
span
is equivalent to
(values (takewhile pred clist) (dropwhile pred clist))
.
break
inverts the sense of pred.
[R7RS list]
{scheme.list}
Returns the index of the leftmost element that satisfies pred.
If no element satisfies pred, #f
is returned.
[R7RS list]
{scheme.list}
Returns (cons (cons key datum) alist)
.
This is an alias of the Gauche builtin procedure acons
.
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.
[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.
[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
[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).
(lsetadjoin eq? '(a b c) 'a 'e) ⇒ '(e a b c)
[R7RS list] {scheme.list} Returns the union of the sets list1 ….
[R7RS list] {scheme.list} Returns a set of elements that are in every lists.
[R7RS list] {scheme.list} Returns a set of elements that are in list1 but not in list2. In nary case, binary differece operation is simply folded.
[R7RS list] {scheme.list} Returns the exclusiveor of given sets; that is, the returned set consists of the elements that are in either list1 or list2, but not in both. In nary case, binary xor operation is simply folded.
[R7RS list] {scheme.list} Returns two sets, a difference and an intersection of given sets.
[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: R7RS sort, Previous: R7RS lists, Up: R7RS large [Contents][Index]
scheme.vector
 R7RS vectorsThis module adds rich set of vector operations to the builtin / R7RS vector procedures.
The following procedures are builtin. See Vectors, for the description. We only explain the procedures that are not builtin.
makevector vector vector? vectorref vectorset! vectorlength vectorfill! vectorcopy vectorcopy! vectorappend vector>list list>vector reverselist>vector vector>string string>vector vectormap vectormap! vectorforeach
This module is srfi133
, which supersedes srfi43
(see Vector library (Legacy)).
Note that the interface of following procedures in srfi43
are changed for the consistency:
vectormap vectormap! vectorforeach vectorfold vectorfoldright vectorcount
Some of the functionalities
of srfi43
version is supported by builtin procedures
(e.g. Builtin vectormapwithindex
is the same as
srfi43
’s vectormap
). So there’s little point
for new code to use srfi43
.
[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.
(vectorunfold (^[i] (* i i)) 5) ⇒ #(0 1 4 9 16) (vectorunfold (^[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))
[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.
(vectorunfoldright (^[i] (* i i)) 5) ⇒ #(0 1 4 9 16) (vectorunfoldright (^[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))
[R7RS vector] {scheme.vector} Copies the vector vec with reversing its elements. Optional start and end arguments can limit the range of the input.
(vectorreversecopy '#(a b c d e) 1 4) ⇒ #(d c b)
[R7RS vector]
{scheme.vector}
Same as (apply vectorappend listofvectors)
.
[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:
(vectorappend (vectorcopy vec1 start1 end1) (vectorcopy vec2 start2 end2) …)
Here’s an example:
(vectorappendsubvectors '#(a b c d e) 0 3 '#(f g h i j) 2 5) ⇒ #(a b c h i j)
[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.
[R7RS vector]
{scheme.vector}
Compares vecs elementwise, 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.
[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 ith 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 vectorfold
.
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; vectorfoldleft
would be more consistent
name.
(vectorfold (^[a b] (cons b a)) '() '#(a b c d)) ⇒ (d c b a)
[R7RS vector]
{scheme.vector}
Like vectorfold
, but elements in the vec1 vec2 …
are visited from right to left.
Unlike foldright
(see Mapping over sequences),
the procedure kons takes the accumulated value in the
first argument.
(vectorfoldright (^[a b] (cons b a)) '() '#(a b c d)) ⇒ (a b c d)
[R7RS vector] {scheme.vector} Applies pred on each elements in argument vectors (if N vectors are given, pred takes N arguments, the first being ith element of vec1, the second being ith element of vec2, etc.) Then returns the number of times pred returned true value. The order pred applied to each element is unspecified.
(vectorcount odd? '#(0 1 2 3 4) ⇒ 2 (vectorcount < '#(7 3 9 1 5) '#(6 8 2 3 8 8)) ⇒ 3
[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 ith element of result vector is a result of procedure f called with i1th element of result vector and ith element of vec.
(vectorcumulate stringappend "z" '#("a" "b" "c")) ⇒ #("za" "zab" "zabc")
[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 vectorindex
, comparison ends at the end of the shortest vector.
For vectorindexright
, all the vectors must have the same length.
[R7RS vector]
{scheme.vector}
Like vectorindex
and vectorindexright
, 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.
[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 SRFI133, and can be used to limit the range of the search in startth element (inclusive) to endth element (exclusive).
[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.
[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.
(vectorevery < '#(1 2 3 4 5) '#(2 3 4 4 5) ⇒ #f (vectorevery (^[x y] (and (real? x) (real? y) ( x y))) '#(1 2 3) '#(2 4 6)) ⇒ 3
[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.
(vectorpartition odd? '#(1 2 3 4 5 6 7 8))
⇒ #(1 3 5 7 2 4 6 8) and 4
[R7RS vector] {scheme.vector} Swaps vector vec’s ith and jth elements. Returns unspecified value.
(rlet1 v (vector 'a 'b 'c 'd 'e) (vectorswap! v 0 2)) ⇒ #(c b a d e)
[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) (vectorreverse! v 0 4)) ⇒ #(d c b a e)
[R7RS vector]
{scheme.vector}
Like vectorcopy!
, but reverses the order of elements from start.
(rlet1 v (vector 'a 'b 'c 'd 'e) (vectorreversecopy! 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) (vectorreversecopy! v 1 v 1)) ⇒ #(a e d c b)
[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 vectorunfold!
,
and right to left by vectorunfoldright!
.
The return value is unspecified.
(let1 rvec (vector 'a 'b 'c 'd 'e 'f) (vectorunfold! (^[i] (+ i 1)) rvec 1 4) rvec) ⇒ #(a 2 3 4 e f) (let1 rvec (vector 'a 'b 'c 'd 'e 'f) (vectorunfoldright! (^[i] (+ i 1)) rvec 1 4) rvec) ⇒ #(a 2 3 4 e f) (let1 rvec (vector 'a 'b 'c 'd 'e 'f) (vectorunfold! (^[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) (vectorunfold! (^[i x] (values x (* x 2))) rvec 1 5 10) rvec) ⇒ #(a 80 40 20 10 f)
[R7RS vector]
{scheme.vector}
Same as (reverse (vector>list vec start end))
, but more efficient.
Next: R7RS sets, Previous: R7RS vectors, Up: R7RS large [Contents][Index]
scheme.sort
 R7RS sortProvides utilities to sort, and to work on sorted lists/vectors.
This module is the same as srfi132
.
Gauche has builtin 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.
[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 builtin
sort
, sort!
, stablesort
and stablesort!
,
except the Gauche’s version works on any sequences and takes
arguments differently. (See Sorting and merging.)
[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.
[R7RS sort] {scheme.sort} Given two sorted lists lis1 and lis2, returns a new sorted list according to the ordering predicate elt<.
Note that listmerge!
works inplace, that is, all the pairs
in lis1 and lis2 are reused.
See also merge
and merge! in Sorting and merging.
[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 stablesort
in Sorting and merging.
[R7RS sort] {scheme.sort} Sort elements “inplace” 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 stablesort!
in Sorting and merging.
[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.
[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 vectormerge allocates a fresh vector to hold the result, and returns it.
The sideeffecting version vectormerge! 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.
[R7RS sort] {scheme.sort} From the given list lis or vector vec, these procedures delete adjacent duplicate elements. Equivalence is checked by elt= procedure.
(listdeleteneighbordups eq? '(m i s s i s s i p p i)) ⇒ (m i s i s i p i)
The nondestructive versions listdeleteneighbordups
and
vectordeleteneighbordups
returns a freshly allocated
list and vector, respectively.
The destructive listdeleteneighbordups!
works inplace,
reusing pairs of lis. No allocation will be done.
The destructive vectordeleteneighbordups!
has a bit different
interface. It updates vec inplace, 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.
(vectordeleteneighbordups 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 (vectordeleteneighbordups! 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.
listdeleteneighbordups
deleteneighbordups
listdeleteneighbordups!
deleteneighbordupssqueeze!
vectordeleteneighbordups
deleteneighbordups
vectordeleteneighbordups!
deleteneighbordups!
[R7RS sort]
{scheme.sort}
Select kth 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.
[R7RS sort]
{scheme.sort}
Find kth 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 inplace divideandconquer algorithms. Runs in O(n) time.
[R7RS sort]
{scheme.sort}
Find median value of elements in vec, when ordered by
the ordering predicate elt<. Nondestructive version
vectorfindmedian
runs in O(n) time. The destructive
version vectorfindmedian!
is specified to leave
vec sorted, so it runs in O(n log n).
(vectorfindmedian < #() 0) ⇒ 0 (vectorfindmedian < #(78 61 19 38 51) 0) ⇒ 51 (vectorfindmedian < #(78 61 19 38 51 52) 0) ⇒ 103/2
Next: R7RS character sets, Previous: R7RS sort, Up: R7RS large [Contents][Index]
scheme.set
 R7RS setsSets 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 srfi113
, 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.
(coerceto <list> (set eqcomparator 'a 'b 'a 'b)) ⇒ (a b) ; order may differ (coerceto <list> (bag eqcomparator 'a 'b 'a 'b)) ⇒ (a a b b) ; order may differ
[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 eqcomparator 'a 'b 'a 'b)) ⇒ (a b) (bag>list (bag eqcomparator 'a 'b 'a 'b)) ⇒ (a a b b)
[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 (setunfold (^s (= s 75)) integer>char (^s (+ s 1)) 65 eqvcomparator)) ⇒ (#\D #\H #\A #\E #\I #\J #\B #\F #\C #\G)
[R7RS set] {scheme.set} Check if obj is in the set or the bag.
[R7RS set]
{scheme.set}
Returns #t
iff the given set or bag is empty.
[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.
[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 stringcicomparator "abc" def") (setmember s "ABC" #f)) ⇒ "abc"
[R7RS set] {scheme.set} Returns the comparator used to compare the elements for the set or the bag.
[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.
[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 stringcicomparator "ABC" "def"))) (set>list (setreplace s "abc"))) ⇒ ("abc" "def")
[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.
[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 eltlist.
[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.
[R7RS set] {scheme.set} Lookupandmodify 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 newitem retval)
. It replaces the matching item in the
set/bag with newitem, 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 setsearch!
and bagsearch!
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 setsearch!
/bagsearch!
, for
the procedures passed to success or failure are expected
to be tailcalled.
If there are more than one item that matches elt in a bag,
bagsearch!
only invokes success for the first item
it finds. You can recurse into bagsearch!
in the failure
procedure to visit all matching items. It is guaranteed that success
and failure procedures are tailcalled.
[R7RS set] {scheme.set} Returns the number of items in the set/bag.
[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.
[R7RS set] {scheme.set} Returns the number of items that satisfy pred in the set/bag.
[R7RS set] {scheme.set} Returns true iff any item in the set/bag satisfy pred.
[R7RS set] {scheme.set} Returns true iff every item in the set/bag satisfy pred.
[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.
[R7RS set] {scheme.set} Apply proc to each element in the set/bag. The result of proc is ignored. Return value is undefined.
[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 setfold
/bagfold
.
(bagfold + 0 (bag eqvcomparator 1 1 2 2 3 3 4 4)) ⇒ 20
[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 (setfilter odd? (set eqvcomparator 1 2 3 4 5))) ⇒ (1 3 5)
[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 (setremove odd? (set eqvcomparator 1 2 3 4 5))) ⇒ (2 4)
[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) (setremove odd? (set eqvcomparator 1 2 3 4 5))
(values (set>list in)
(set>list out)))
⇒ (1 3 5) and (2 4)
[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.
[R7RS set] {scheme.set} Returns a copy of the set/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.
[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 eltlist) (apply bag comparator eltlist)
[R7RS set] {scheme.set} Add items in eltlist to the existing set/bag, and returns the updated set/bag. The original set/bag is also modified. Functionally equivalent to the followings:
(apply setadjoin! set eltlist) (apply bagadjoin! bag eltlist)
[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.
[R7RS set] {scheme.set} Adds all items in set to bag, and returns bag. Both bag and set must have the same comparator.
[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.
[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.
[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.
[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.
[R7RS set] {scheme.set} Returns a newly allocated set or bag which is a union of all the sets/bags.
[R7RS set] {scheme.set} Returns a newly allocated set or bag which is an intersection of all the sets/bags.
[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 (setdifference (set eqvcomparator 1 2 3 4 5 6 7) (set eqvcomparator 3 5 7 9 11 13) (set eqvcomparator 4 8 16 32)))) ⇒ (1 2 6)
[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 (setxor (set eqvcomparator 2 3 5 7 11 13 17) (set eqvcomparator 3 5 7 9 11 13 15)))) ⇒ (2 9 15 17)
[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.
[R7RS set]
{scheme.set}
Returns a bag that gathers all the items in given bags, counting
duplicates. The functional version bagsum
always
creates new bag to return.
The linear update version bagsum!
is allowed to,
but not required to, modify bag1 to produce the result.
(sort (bag>list (bagsum (bag eqvcomparator 1 1 2 4 5 5 6) (bag eqvcomparator 3 3 5 9)))) ⇒ (1 1 2 3 3 4 5 5 5 6 9)
Note the difference from bagunion
:
(sort (bag>list (bagunion (bag eqvcomparator 1 1 2 4 5 5 6) (bag eqvcomparator 3 3 5 9)))) ⇒ (1 1 2 3 3 4 5 5 6 9)
[R7RS set]
{scheme.set}
Returns a bag that contains every item as ntimes
many as the original bag. A fresh bag is created and returned
by bagproduct
, while bagproduct!
may reuse
bag to produce the result.
(sort (bag>list (bagproduct 2 (bag eqcomparator 'a 'b 'r 'a)))) ⇒ (a a a a b b r r)
[R7RS set] {scheme.set} Returns the number of unique elements in bag.
(baguniquesize (bag eqvcomparator 1 1 2 2 3 3 4)) ⇒ 4
[R7RS set] {scheme.set} Returns the number of specified element elt in bag.
(bagelementcount (bag eqvcomparator 1 1 2 2 2 3 3) 2) ⇒ 3
[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.
[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 bagfoldunique
.
(sort (bagfoldunique acons '() (bag equalcomparator "a" "a" "b" "b" "b" "c" "d")) string<? car) ⇒ (("a" . 2) ("b" . 3) ("c" . 1) ("d" . 1))
[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 (bagdecrement! bag 'a 100)
, you get a bag
with zero a
’s.
[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: R7RS hash tables, Previous: R7RS sets, Up: R7RS large [Contents][Index]
scheme.charset
 R7RS character setsImplements character set library, originally defined as SRFI14. Note that the following characterset procedures are Gauche’s buildin. See Character set.
charset charset? charsetcontains? charsetcopy charsetcomplement charsetcomplement!
In Gauche,
the <charset>
class inherits <collection>
and implements
the collection protocol, so that the generic operations defined in
gauche.collection
can also be used (see Collection framework).
• Characterset constructors:  
• Characterset comparison:  
• Characterset iteration:  
• Characterset query:  
• Characterset algebra:  
• Predefined characterset: 
Next: Characterset comparison, Previous: R7RS character sets, Up: R7RS character sets [Contents][Index]
[R7RS comparator]
{scheme.charset}
Constructs a character set from a list of characters charlist.
If basecs is given, it must be a character set, and the characters
in it are added to the result character set.
List>charset!
is allowed, but not required, to reuse basecs
to store the result.
[R7RS charset]
{scheme.charset}
Like list>charset
and list>charset!
,
but take a list of characters from a string s.
[R7RS charset]
{scheme.charset}
Returns a character set containing every character c in
charset such that (pred c)
returns true.
If a character set basecs is given, its content is added to
the result. The linear update version charsetfilter!
is allowed, but not required, to modify basecs to store the result.
[R7RS charset] {scheme.charset} Creates
{scheme.charset}
[R7RS charset] {scheme.charset} A convenience function to coerce various kinds of objects to a charset. The argument x can be a collection of characters, a charset, or a character. If the argument is a charset, it is returned asis. If the argument is a character, a charset with that single character is returned.
Note: R7RS (scheme charset)
’s
>charset
only accepts a string, a charset
or a character as an argument. Gauche extends it so that it can
accept any collection of characters.
Next: Characterset iteration, Previous: Characterset constructors, Up: R7RS character sets [Contents][Index]
[R7RS charset]
{scheme.charset}
Returns #t
iff all the character sets have exactly the
same members.
(charset=) ⇒ #t (charset= (charset)) ⇒ #t (charset= (string>charset "cba") (list>charset #\a #\b #\c)) ⇒ #t
[R7RS charset] {scheme.charset}
[R7RS charset] {scheme.charset}
Next: Characterset query, Previous: Characterset comparison, Up: R7RS character sets [Contents][Index]
[R7RS charset] {scheme.charset}
[R7RS charset] {scheme.charset}
[R7RS charset] {scheme.charset}
[R7RS charset] {scheme.charset}
[R7RS charset] {scheme.charset}
[R7RS charset] {scheme.charset}
[R7RS charset] {scheme.charset}
[R7RS charset] {scheme.charset}
Next: Characterset algebra, Previous: Characterset iteration, Up: R7RS character sets [Contents][Index]
[R7RS charset] {scheme.charset} These procedures apply pred to each character in charset.
charsetevery
returns #f
as soon as pred returns
#f
. Otherwise, it returns the result of the last application of
pred.
charsetany
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.
charsetcount
returns the number of times
pred returns a true value.
Note that charset can be huge (e.g. a complement of small charset), which can make these procedures take very long.
[R7RS charset] {scheme.charset} Returns a list of each character, or a string consisting of each character, in charset, respectively. Be careful to apply this on a large char set.
Next: Predefined characterset, Previous: Characterset query, Up: R7RS character sets [Contents][Index]
[R7RS charset] {scheme.charset} Returns a character set that adds char1 … to charset.
[R7RS charset] {scheme.charset}
[R7RS charset] {scheme.charset}
[R7RS charset] {scheme.charset}
[R7RS charset] {scheme.charset}
[R7RS charset] {scheme.charset}
[R7RS charset] {scheme.charset}
Previous: Characterset algebra, Up: R7RS character sets [Contents][Index]
[R7RS charset] {scheme.charset}
[R7RS charset] {scheme.charset}
[R7RS charset] {scheme.charset}
[R7RS charset] {scheme.charset}
[R7RS charset] {scheme.charset}
[R7RS charset] {scheme.charset}
[R7RS charset] {scheme.charset}
[R7RS charset] {scheme.charset}
[R7RS charset] {scheme.charset}
[R7RS charset] {scheme.charset}
[R7RS charset] {scheme.charset}
[R7RS charset] {scheme.charset}
[R7RS charset] {scheme.charset}
Next: R7RS immutable deques, Previous: R7RS character sets, Up: R7RS large [Contents][Index]
scheme.hashtable
 R7RS hash tablesThis module provides hash table library, originally defined as srfi125
.
Hash table provided with this module is the same as Gauche’s builtin hash table. However, srfi125 introduces procedures that conflict with Gauche’s original procedures, so Gauche provides those procedures builtin but under aliases. See Hashtables, for the builtin hash table procedures.
With this module, procedures are provided as defined in R7RS. Use this module when you’re writing portable code.
Srfi125 also defines compatiblity procedures with srfi69, although saying they’re deprecated. Those deprecated procedures are supported in this module, too.
The following procedures are the same as Gauche’s builtin.
hashtableunfold hashtable? hashtablecontains? hashtableexists? hashtableempty? hashtable=? hashtablemutable? hashtableref hashtableref/default hashtableset! hashtableupdate!/default hashtableclear! hashtablesize hashtablekeys hashtablevalues hashtablecopy hashtableemptycopy hashtable>alist hashtableunion! hashtableintersection! hashtablediffernce! hashtablexor!
See Hashtables, for the description of those procedures.
The following procedures are also provided as Gauche’s builtin,
but with r7
suffix.
hashtable hashtabledelete! hashtableintern! hashtableupdate! hashtablepop! hashtablefind hashtablecount hashtablemap hashtableforeach hashtablemap! hashtablemap>list hashtableprune!
[R7RS hashtable]
{scheme.hashtable}
This enhances builtin makehashtable
with the second form,
that takes two procedures instead of one comparator, as srfi69.
In the srfi69 form, equalproc is a procedure taking two keys to see if they are the same, and hashproc 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.
[R7RS hashtable]
{scheme.hashtable}
This is the same as builtin hashtabler7
(see Hashtables).
Construct a new hash table with keycomparator 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 keyvalue list is not even.
Note that srfi125 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.
[R7RS hashtable]
{scheme.hashtable}
This enhances builtin alist>hashtable
with the second form,
that takes two procedures instead of one comparator, as srfi69.
In the srfi69 form, equalproc is a procedure taking two keys to see if they are the same, and hashproc 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.
[R7RS hashtable]
{scheme.hashtable}
This is the same as builtin hashtabledelete!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 builtin hashtabledelete!
in two points:
The bulitin one can take exactly one key, and returns
a boolean indicating if the entry is actually deleted.
[R7RS hashtable]
{scheme.hashtable}
This is the same as builtin hashtableintern!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.
[R7RS hashtable]
{scheme.hashtable}
This is the same as builtin hashtableupdate!r7
.
It takes differnt optional arguments from builtin hashtableupdate!
.
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.
(hashtableset! ht key (updater (hashtableref ht key failure success)))
[R7RS hashtable]
{scheme.hashtable}
This is the same as builtin hashtablepop!r7
.
It is a completely different procedure as builtin hashtablepop!
.
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.
[R7RS hashtable]
{scheme.hashtable}
This is the same as builtin hashtablefindr7
.
It takes different arguments from builtin hashtablefind
.
Calls proc with a key and a value of each entry in ht,
until proc returns nonfalse value. If proc returns
nonfalse value, hashtablefind
immediately returns it.
If proc returns #f
for all entries, calls a thunk
failure and returns its result.
[R7RS hashtable]
{scheme.hashtable}
This is the same as builtin hashtablecountr7
.
Calls proc with a key and a value of each entry in ht, and returns the number of times when proc returned true.
[R7RS hashtable]
{scheme.hashtable}
This is the same as builtin hashtablemapr7
.
This is different from builtin hashtablemap
.
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.
[R7RS hashtable]
{scheme.hashtable}
This is the same as builtin hashtablemap!r7
.
Calls proc on the value of each entry in ht, and update the entry with the result of proc.
[R7RS hashtable]
{scheme.hashtable}
This is the same as builtin hashtablemap>listr7
,
and same as builtin hashtablemap
(not the scheme.hashtable
’s
hashtablemap
) 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.
[R7RS hashtable] {scheme.hashtable} 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.hashtable
recommended one,
which is the same as builtin hashtableforeachr7
,
and the latter way is compatible with srfi69, which is
the same as builtin hashtableforeach
.
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 builtin interface, use (hashtableforeach ht proc)
.
If your module imports scheme.hashtable
,
use (hashtableforeach proc ht)
.
[R7RS hashtable] {scheme.hashtable} 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.hashtable
recommended one,
which is the same as builtin hashtablefoldr7
,
and the latter way is compatible with srfi69, which is
the same as builtin hashtablefold
.
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 builtin interface, use the second interface.
If your module imports scheme.hashtable
,
use the first interface.
[R7RS hashtable]
{scheme.hashtable}
This is the same as builtin hashtableprune!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.
[R7RS hashtable]
{scheme.hashtable}
This is the same as hashtableunion!
, and provided just
for the compatibility with srfi69. Deprecated.
[R7RS hashtable] {scheme.hashtable} Provided for the compatibility with srfi69, and are deprecated.
The first three are the same as builtin defaulthash
,
stringhash
, and stringcihash
, except that
these accept an optional second argument, which is ignored.
Note that hashbyidentity
is also defined as the same
as defaulthash
except the ignored optional second argument,
per srfi125, although the name suggests that it would work as if
eqhash
.
Do not use these procedures in the new code; you can use comparators
instead (defaultcomparator
, stringcomparator
,
stringcicomparator
and eqcomparator
,
see Predefined comparators). If you do need hash function,
you should still avoid hash
and hashbyidentity
,
and use defaulthash
and eqhash
instead.
[R7RS hashtable] {scheme.hashtable} Provided for the compatibility with srfi69, and are deprecated.
Returns the equivalence function and hash function of a hash table ht.
For the introspection, we recommend to use
builtin hashtablecomparator
. (Unfortunately, it is not
included in scheme.hashtable
, though.)
Next: R7RS generators, Previous: R7RS hash tables, Up: R7RS large [Contents][Index]
scheme.ideque
 R7RS immutable dequesThis module provides a functional doubleended 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 spaceefficient
deque, you can also use data.ringbuffer
as a deque
(see Ring buffer).
This module was originally defined as srfi134
, then
became a part of R7RS large.
Gauche’s data.ideque
is a superset of this module.
See Immutable deques.
[R7RS ideque] {scheme.ideque} Returns an ideque with the given elements.
[R7RS ideque] {scheme.ideque}
[R7RS ideque] {scheme.ideque}
[R7RS ideque] {scheme.ideque}
[R7RS ideque] {scheme.ideque}
[R7RS ideque] {scheme.ideque}
[R7RS ideque] {scheme.ideque}
[R7RS ideque] {scheme.ideque}
[R7RS ideque] {scheme.ideque}
[R7RS ideque] {scheme.ideque}
[R7RS ideque] {scheme.ideque}
[R7RS ideque] {scheme.ideque}
[R7RS ideque] {scheme.ideque}
[R7RS ideque] {scheme.ideque}
[R7RS ideque] {scheme.ideque}
[R7RS ideque] {scheme.ideque}
[R7RS ideque] {scheme.ideque}
[R7RS ideque] {scheme.ideque}
[R7RS ideque] {scheme.ideque}
[R7RS ideque] {scheme.ideque}
[R7RS ideque] {scheme.ideque}
[R7RS ideque] {scheme.ideque}
[R7RS ideque] {scheme.ideque}
[R7RS ideque] {scheme.ideque}
[R7RS ideque] {scheme.ideque}
[R7RS ideque] {scheme.ideque}
[R7RS ideque] {scheme.ideque}
[R7RS ideque] {scheme.ideque}
[R7RS ideque] {scheme.ideque}
[R7RS ideque] {scheme.ideque}
[R7RS ideque] {scheme.ideque}
[R7RS ideque] {scheme.ideque}
Next: R7RS lazy sequences, Previous: R7RS immutable deques, Up: R7RS large [Contents][Index]
scheme.generator
 R7RS generatorsA generator is a thunk to generate a sequence of values, potentially
terminated by EOF. The interface was first defined in srfi121, 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.
generator makeiotagenerator makerangegenerator makecoroutinegenerator makebitsgeneartor makeforeachgenerator makeunfoldgenerator list>generator vector>generator reversevector>generator string>generator
gcons* gappend gcombine gfilter gremove gtake gdrop gtakewhile gdropwhile gdelete gdeleteneighbordups gindex gselect
generator>list generator>reverselist generator>vector generator>vector! generator>string generatorcount generatorany genreatorevery generatorunfold
generatorfold generatorforeach generatorfind
Next: R7RS boxes, Previous: R7RS generators, Up: R7RS large [Contents][Index]
scheme.lseq
 R7RS lazy sequencesThis 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 builtin 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.
Srfi127, 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 uppercompatible,
except that the code that assumes the internal structure could break.
Notably, the constructor generator>lseq
is the same as
Gauche’s builtin, which returns Gauche’s lseq, undistinguishable
to the oridnary list.
(procedure? (generator>lseq (generator 1))) ;; => #t, in srfi127 reference implementation, ;; #f, in our implementation.
[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.
[R7RS lseq]
{scheme.lseq}
Compare two lseqs elementwise using elt=?
and returns #t
iff two lseqs are equal.
[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
.
[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
.
[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 lseqtake
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, lseqdrop
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.
[R7RS lseq] {scheme.lseq} Realizes all the elements in lseq, resulting an ordinary list.
[R7RS lseq]
{scheme.lseq}
Creates a generator from lseq. In Gauche, this is same
as list>generator
.
[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
.
[R7RS lseq]
{scheme.lseq}
Append one or more lseqs lazily. This is the same as lappend
in Gauche.
[R7RS lseq]
{scheme.lseq}
Returns a lazy sequence in which the first element is a list of
first elements of lseq
s, and so on.
[R7RS lseq]
{scheme.lseq}
Lazy map. The same as Gauche’s lmap
. Returns a lazy sequence.
[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 foreach
, for
Gauche doesn’t distinguish lseqs and ordinary lists.
[R7RS lseq]
{scheme.lseq}
Returns an lseq that contains elements from the input
lseq that satisfy or don’t satisfy pred, respectively.
Lseqfilter
is the same as Gauche’s lfilter
.
[R7RS lseq]
{scheme.lseq}
These are the same as Gauche’s ltakewhile
and dropwhile
(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.
[R7RS lseq]
{scheme.lseq}
In Gauche, these are the same as the corresponding list functions,
find
, findtail
, any
, every
,
listindex
, 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: R7RS list queues, Previous: R7RS lazy sequences, Up: R7RS large [Contents][Index]
scheme.box
 R7RS boxesThis 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 singleelement 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:
equal?
compares their contents when
two are not eqv?
. In the spec, when two boxes are eqv?
then they must also be equal?
to each other, but it’s up
to the implementation when two are not eqv?
.
When you’re writing portable code, be careful not to depend on the
equal?
behavoir.
[R7RS box]
{scheme.box}
Returns a fresh box object that contains the value val
.
[R7RS box]
{scheme.box}
Returns #t
iff obj is a box object.
[R7RS box] {scheme.box} Returns box’s content.
[R7RS box] {scheme.box} Mutate box’s content with val. Returns unspecified value.
Next: R7RS comparators, Previous: R7RS boxes, Up: R7RS large [Contents][Index]
scheme.listqueue
 R7RS list queuesA library of simple queue based on lists.
Gauche has a queue support in data.queue
module, which also
includes MTsafe queue (see Queue). This library is implemented
on top of data.queue
’s <queue>
object and mainly provided
for portable code.
The listqueue is just an instance of <queue>
, so you can
pass a queue created by makequeue
to scheme.listqueue
API and
a listqueue created by makelistqueue
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.
[R7RS listqueue]
{scheme.listqueue}
Creates and returns a listqueue 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, makelistqueue
will skip scanning lis
and just hold a reference to last as the tail of the queue.
[R7RS listqueue]
{scheme.listqueue}
Creates and returns a listqueue whose initial content is elt ….
In Gauche, a list queue is just an instance of <queue>
(see Queue).
[R7RS listqueue] {scheme.listqueue} Returns a copy of a listqueue queue.
[R7RS listqueue]
{scheme.listqueue}
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.
(listqueueunfold (pa$ = 5) ; p
(pa$ * 2) ; f
(pa$ + 1) ; g
0 ; seed
(listqueue 'x 'y 'z))
⇒ a queue containing (0 2 4 6 8 x y z)
[R7RS listqueue]
{scheme.listqueue}
Append queue with the items generated by
(unfoldright p f g seed)
and returns the updated queue.
See R7RS lists, for unfoldright
.
If queue is omitted, a fresh queue is created.
(listqueueunfoldright (pa$ = 5) ; p
(pa$ * 2) ; f
(pa$ + 1) ; g
0 ; seed
(listqueue 'x 'y 'z))
⇒ a queue containing (x y z 8 6 4 2 0)
[R7RS listqueue]
{scheme.listqueue}
Returns true iff queue is a listqueue.
In Gauche, it is the same as queue?
in the data.queue
module.
[R7RS listqueue]
{scheme.listqueue}
Returns true iff queue is empty.
Same as queueempty?
of data.queue
.
[R7RS listqueue]
{scheme.listqueue}
Returns the front element of the queue.
An error is thrown if queue is empty.
Same as queuefront
of data.queue
.
[R7RS listqueue]
{scheme.listqueue}
Returns the rear element of the queue.
An error is thrown if queue is empty.
Same as queuerear
of data.queue
.
[R7RS listqueue] {scheme.listqueue} 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 queuerelated operations with small overhead.
If you merely need a cheap access the content of the queue,
consider listqueueremoveall!
.
That returns the list of elements of the queue without copying, and
simultaneoulsy reset the queue to empty, so it’s safe.
[R7RS listqueue] {scheme.listqueue} 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 queuerelated operations with small overhead. This procedure should not be used in general.
[R7RS listqueue]
{scheme.listqueue}
Add elt to the front of queue.
Same as (queuepush! queue elt)
of data.queue
.
[R7RS listqueue]
{scheme.listqueue}
Add elt to the back of queue.
Same as (enqueue! queue elt)
of data.queue
.
[R7RS listqueue]
{scheme.listqueue}
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
.
[R7RS listqueue] {scheme.listqueue} 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 doubleended queue. (See Immutable deques, and also see Ring buffer.)
[R7RS listqueue]
{scheme.listqueue}
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 listqueuelist
, for it’s safer.
In Gauhce, this is the same as dequeueall!
in data.queue
.
[R7RS listqueue] {scheme.listqueue} 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.
[R7RS listqueue] {scheme.listqueue} Returns a fresh listqueue 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.
[R7RS listqueue]
{scheme.listqueue}
Returns a listqueue 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).
[R7RS listqueue]
{scheme.listqueue}
(apply listqueueappend queues)
.
[R7RS listqueue] {scheme.listqueue} Returns a fresh listqueue whose elements are obtained by applying proc on every elements in queue.
[R7RS listqueue] {scheme.listqueue} Replaces every element in queue by the result of application of proc on the element.
[R7RS listqueue] {scheme.listqueue} Applies proc on every element of queue. The results are discarded.
Previous: R7RS list queues, Up: R7RS large [Contents][Index]
scheme.comparator
 R7RS comparatorsThis module defines comparators and related procedures.
Originally called srfi128
.
Gauche supports comparators fully compatible to
scheme.comparator
builtin.
See Basic comparators, for the following procedures
defined in this module.
comparator? comparatorordered? comparatorhashable? makecomparator makepaircomparator makelistcomparator makevectorcomparator makeeqcomparator makeeqvcomparator makeequalcomparator booleanhash charhash charcihash stringhash stringcihash symbolhash numberhash hashbound hashsalt makedefaultcomparator defaulthash comparatorregisterdefault! comparatortypetestpredicate comparatorequalitypredicate comparatororderingpredicate comparatorhashfunction comparatortesttype comparatorchecktype comparatorhash =? <? >? <=? >=? comparatorif<=>
Previous: R7RS list queues, Up: R7RS large [Contents][Index]