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.
Currently R7RSlarge has two editions (Red and Tangerine), and Gauche supports them.
• R7RS lists:  scheme.list
 
• R7RS vectors:  scheme.vector
 
• R7RS uniform vectors:  scheme.vector.@
 
• R7RS sort:  scheme.sort
 
• R7RS sets:  scheme.set
 
• R7RS character sets:  scheme.charset
 
• R7RS hash tables:  scheme.hashtable
 
• R7RS immutable lists:  scheme.ilist
 
• R7RS randomaccess lists:  scheme.rlist
 
• R7RS immutable deques:  scheme.ideque
 
• R7RS immutable texts:  scheme.text
 
• R7RS generators:  scheme.generator
 
• R7RS lazy sequences:  scheme.lseq
 
• R7RS stream:  scheme.stream
 
• R7RS boxes:  scheme.box
 
• R7RS list queues:  scheme.listqueue
 
• R7RS ephemerons:  scheme.ephemeron
 
• R7RS comparators:  scheme.comparator
 
• R7RS regular expressions:  scheme.regex
 
• R7RS mappings:  scheme.mapping
 
• R7RS integer division:  scheme.division
 
• R7RS bitwise operations:  scheme.bitwise
 
• R7RS fixnum:  scheme.fixnum
 
• R7RS flonum:  scheme.flonum
 
• R7RS bytevectors:  scheme.bytevector
 
• R7RS combinator formatting:  scheme.show

Next: scheme.vector
 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 srfi.1
.
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).
[R7RS list] {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 scheme.set
 R7RS sets, if you
know your sets will contain more than a dozen items or so.
See also util.combinations
 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 difference 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: scheme.vector.@
 R7RS uniform vectors, Previous: scheme.list
 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 srfi.133
, which supersedes srfi.43
(see srfi.43
 Vector library (legacy)).
Note that the interface of following procedures in srfi.43
are changed for the consistency:
vectormap vectormap! vectorforeach vectorfold vectorfoldright vectorcount
Some of the functionalities
of srfi.43
version is supported by builtin procedures
(e.g. Builtin vectormapwithindex
is the same as
srfi.43
’s vectormap
). So there’s little point
for new code to use srfi.43
.
[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))
Note: This protocol is different from the list unfold
and most of other *unfold
constructors (see scheme.list
 R7RS lists).
For fixedlength strcuctures like vectors,
it makes more sense to know the final length beforehand, rather than
checking the termination condition for each iteration.
[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 exact 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.
When zero or one vector is passed, elt= won’t be called
and vector= always returns #t
.
[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.
If the lengths of the vectors differ, this procedure only looks up to the number of elements of the shortest vector and ignores any excessive elements. See the second example below.
Unlike foldright
(see Mapping over sequences),
the procedure kons takes the seed value in the
first argument.
(vectorfoldright (^[a b] (cons b a)) '() '#(a b c d)) ⇒ (a b c d) (vectorfoldright (^[s x y] (cons (list x y) s)) '() '#(a b c) '#(1 2 3 4)) ⇒ ((a 1) (b 2) (c 3))
[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 extension 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: scheme.sort
 R7RS sort, Previous: scheme.vector
 R7RS vectors, Up: R7RS large [Contents][Index]
scheme.vector.@
 R7RS uniform vectors@
is actually one of u8
, s8
, u16
, s16
,
u32
, s32
, u64
, s64
, f32
,
f64
, c64
or c128
.
(Gauche’s gauche.uvector
module also provides f16
and c32
vectors.)
These modules provides vectors that can hold specific range of numeric values. In Gauche we use packed representation, meaning numbers are tightly stored in consecutive memory region.
Additionally, scheme.vector.base
module exports basic procedures,
make@vector
, @vector
, @vector?
, @vectorlength
,
@vectorref
, @vectorset!
,
@vector>list
, list>@vector
, @?
,
for @
being over all element types.
The gauche.uvector
module is a superset of these modules, and
all procedures are described there. See Uniform vectors for the
details.
Next: scheme.set
 R7RS sets, Previous: scheme.vector.@
 R7RS uniform 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 srfi.132
.
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 linear update version. They 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 iff 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 (exclusive) 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.
Note that most of recent APIs with !
is linear updating,
meaning it may or may not change the argument, and the caller must use
the return value. On the other hand, vectorsort!
and
vectorstablesort!
are purely for side effects,
and use minimal space
(vectorsort!
doesn’t need extra space, while
vectorstablesort!
may allocate a temporary storage up to
the size of the input).
When the optional start and/or end arguments are given, only the portion from start (inclusive) and end (exclusive) 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 (exclusive) 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. Each is integer index to the corresponding vector, and the start index is inclusive, while the end index is exclusive.
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. The length of rvec must be greater than
rstart + (end1start1) + (end2start2).
[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.
It is a singlepass iterative algorithm, and the first cell of input
is the first cell of output (except when the input is an empty list).
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 in average, 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 length 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: scheme.charset
 R7RS character sets, Previous: scheme.sort
 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 construction 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 gauche.collection
 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:
(let1 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 an item that matches 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)
wheras, item is the matched item in the set/bag.
The update argument is a procedure that takes two arguments,
as (update newitem retval)
. It returns two values:
(1) A set/bag that are the same as the given one except
that item is replaced with newitem,
and (2) retval.
The remove argument is a procedure that takes one argument,
as (remove retval)
. It returns two values:
(1) A set/bag that are the same as the given one except
item is removed, and (2) 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 returns two values:
(1) a set/bag that has all the items in the given one plus elt,
and (2) retval.
The ignore argument is a procedure that takes one argument,
as (ignore retval)
. It returns two values:
(1) the original set/bag, and (2) retval.
The original set/bag may be reused to produce the result by update, remove and insert procedures.
The return values of setsearch!
and bagsearch!
is
what either success or failure procedure returns.
These callerprovided procedures should invoke the passedin procedures
(update, remove, insert or ignore) and return
their results—which is a potentially modified set/bag
(which may or may not be eq?
to the passed one) and the retval.
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 success
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 tailcalled.
NB: The API differs from find
in scheme.list
(builtin in Gauche),
that find
does not take failure procedure.
[R7RS set] {scheme.set} Returns the number of items that satisfy pred in the set/bag.
[R7RS set]
{scheme.set}
Returns #f
iff any item in the set/bag satisfy pred.
NB: It differs from any
defined in scheme.list
(builtin in Gauche)
that any
returns the true result of pred, while
setany?
always returns a boolean value (hence the question mark).
[R7RS set]
{scheme.set}
Returns #t
iff every item in the set/bag satisfy pred.
NB: It differs from every
defined in scheme.list
(builtin in Gauche)
that every
returns the last true result of pred when all the
elements satisfy pred, while
setevery?
always returns a boolean value (hence the question mark).
[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 may or may not be 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} Returns a bag that contains all items in set plus all iterms in bag, which may be modified to create the result. 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.
[R7RS set]
{scheme.set}
These predicates checks inclusion relationship between sets or bags.
For example, (set<? set1 set2)
is #t
iff set1
is a proper subset of set2, and
(bag>=? bag1 bag2)
is #t
iff
bag2 is a subset (including the ’equal to’ case) of bag1, etc.
If more than two arguments are given, the predicate returns #t
iff
every consecutive arguments satisfies the relationship.
[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}
Linearly 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: scheme.hashtable
 R7RS hash tables, Previous: scheme.set
 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 and predefined charsets are Gauche’s buildin. See Character Sets.
charset charset? charsetcontains? charsetcopy charsetcomplement charsetcomplement! charset:lowercase charset:uppercase charset:titlecase charset:letter charset:digit charset:letter+digit charset:graphic charset:printing charset:whitespace charset:isocontrol charset:punctuation charset:symbol charset:hexdigit charset:blank charset:ascii charset:empty charset:full
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 gauche.collection
 Collection framework).
• Characterset constructors:  
• Characterset comparison:  
• Characterset iteration:  
• Characterset query:  
• Characterset algebra: 
Next: Characterset comparison, Previous: scheme.charset
 R7RS character sets, Up: scheme.charset
 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 a character set containing every character whose ISO/IEC 10646 UCS4 code lies in the halfopen range [lower,upper).
If the range contains unassigned codepoint, they are silently ignored.
If the range contains a valid codepoint which isn’t supported in Gauche, it is ignored when error? is false (default), or an error is raised when error? has a true value. If you compile Gauche with utf8 native encoding (default), all valid Unicode codepoints are supported. If Gauche is compiled with other native encoding, some codepoints are not supported.
If a character set basecs is given, its content is added to
the result. The linear update version ucsrange>charset!
is allowed, but not required, to modify basecs to store the result.
{scheme.charset}
These are Gauchespecific procedures and not in scheme.charset
.
When Gauche is compiled with utf8 native encoding (default), they are
the same as ucsrange>charset
and ucsrange>charset!
,
respectively.
If Gauche is compiled with other native encoding, these interprets
the given range in its native encoding.
Meaning of error? and basecs are the same as
ucschar>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: scheme.charset
 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}
Returns #t
iff every charset argument is a subset of
the following charsets. If no arguments are given, #t
is returned.
[R7RS charset]
{scheme.charset}
Returns a nonnegative exact integer as a hash value of charset.
If optional bound argument is given, it must be a positive integer
that limits the range of the hash value, which will fall between
0 to ( bound 1)
, inclusive.
Next: Characterset query, Previous: Characterset comparison, Up: scheme.charset
 R7RS character sets [Contents][Index]
[R7RS charset]
{scheme.charset}
Returns an object that can point to a first character within charset
(here, ‘first’ merely means the beginning of iteration; the order of
iteration is implementationdependent and you can’t assume a specific
order).
The caller must treat the return value as an opaque object; it can only
be used to pass as the cursor argument of charsetref
,
charsetcursornext
and endofcharset?
.
[R7RS charset] {scheme.charset} Returns a character in charset pointed by cursor.
The cursor argument must be an object returned from
charsetcursor
or charsetcursornext
with charset.
The behavior is undefined if cursor is not a cursor
created from charset.
[R7RS charset] {scheme.charset} Returns a new cursor for the next character pointed by cursor within charset.
The cursor argument must be an object returned from
charsetcursor
or charsetcursornext
with charset.
The behavior is undefined if cursor is not a cursor
created from charset.
[R7RS charset]
{scheme.charset}
Returns #t
iff cursor points to the end of the charset.
[R7RS charset] {scheme.charset} Iterate over all characters in charset, calling the procedure kons with a character and the seed value. The return value of kons becomes the next seed value, while knil gives the first seed value. Returns the last seed value. The order of traversal isn’t specified.
[R7RS charset] {scheme.charset} Build a character set by calling fun on the seed value repeatedly. For each iteration, first pred is applied to the current seed value. If it returns true, a character set that gathers characters generated so far is returned. Otherwise, fun is called on the seed value, which must return a character. Then gen is called on the seed value to obtain the next seed value.
If basecharset is given, a union of it and the generated characters
is returned.
The linearupdate version charsetunfold!
may modify basecharset
to create the result.
[R7RS charset] {scheme.charset} Applies proc on each character in charset. The return value of proc is discarded. Returns undefined value.
[R7RS charset] {scheme.charset} Applies proc on each character in charset, which must return a character. Returns a new charset consists of the characters returned from proc.
Next: Characterset algebra, Previous: Characterset iteration, Up: scheme.charset
 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.
Previous: Characterset query, Up: scheme.charset
 R7RS character sets [Contents][Index]
[R7RS charset] {scheme.charset} Returns a character set that adds char1 … to charset.
The linear update version charsetadjoin!
may modify
charset.
[R7RS charset] {scheme.charset} Returns a character set that removes char1 … from charset. It is noop if charset doesn’t have char1 ….
The linear update version charsetdelete!
may modify
charset.
[R7RS charset] {scheme.charset} Returns a character set of all characters in any one of charset …. Without arguments, returns an empty charset.
The linear update version charsetunion!
may modify
charset1.
[R7RS charset]
{scheme.charset}
Returns a character set of every character that
is in all of charset ….
Without arguments, returns charset:full
.
The linear update version charsetintersection!
may modify
charset1.
[R7RS charset] {scheme.charset} Returns a character set of every character that is in charset1 but not in any of charset2 ….
The linear update version charsetdifference!
may modify
charset1.
[R7RS charset]
{scheme.charset}
With zero arguments, returns an empty charset.
With one argument, it is returned as is.
With two arguments, returns a character set of every character that
is in either one of two sets, but not in both.
With more than two arguments, it returns
(charsetxor (charsetxor set1 set2) set3 …)
.
The linear update version charsetxor!
may modify
charset1.
[R7RS charset]
{scheme.charset}
Returns two values, the result of
(charsetdifference charset1 charset2 …
and the result of
(charsetintersection charset1 charset2 …
.
Next: scheme.ilist
 R7RS immutable lists, Previous: scheme.charset
 R7RS character sets, Up: R7RS large [Contents][Index]
scheme.hashtable
 R7RS hash tablesThis module provides hash table library, originally defined as srfi.125
.
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 compatibility 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.
hashtable? hashtablecontains? hashtableexists? hashtableempty? hashtable=? hashtablemutable? hashtableref hashtableref/default hashtableset! hashtableupdate!/default hashtableclear! hashtablesize hashtablekeys hashtablevalues hashtablecopy hashtableemptycopy hashtable>alist hashtableunion! hashtableintersection! hashtabledifference! 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 … are implementationdependent, and specify various properties of the created hash table. They 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 data.imap
 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 … are implementationdependent, and specify various properties of the created hash table. They are ignored in Gauche.
[R7RS hashtable]
{scheme.hashtable}
Same as Gauche’s builtin hashtableunfold
, except that this
allows optional arguments, which are ignored. They are
implementationspecific parameters to tune the created hash tables.
See Hashtables, for the detailed description.
[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 builtin 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 different 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 key and value of each entry in ht, and update the entry of the key 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 is for portable R7RS code, 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.
Note that SRFI69’s hash function takes an optional bound argument;
so, if you build ht with a comparator or a hash function that does
not take optional argument, hashtablehashfunction
wraps the
real hash function with a procedure that allows optional bound
argument.
For the introspection, we recommend to use
builtin hashtablecomparator
(see Hashtables).
Next: scheme.rlist
 R7RS randomaccess lists, Previous: scheme.hashtable
 R7RS hash tables, Up: R7RS large [Contents][Index]
scheme.ilist
 R7RS immutable listsThis module provides a set of procedures that handles immutable pairs and lists.
The standard allows an implementation to have mutable pairs and immutable
pairs separately, so it defines immutable version of most scheme.list
procedures. In Gauche, mutable pairs and immutable pairs are both
abstract “pairs”, and all procedures that accesses pairs (without modifying
them) works seamlessly on both kind.
Consequently, the following procedures are just aliases of their
nonimmutable versions (just remove i
prefix from them).
Note that these procedures and variables in Gauche do not reject if the input is
mutable pairs/lists, but such usage may not be portable
(see Mutable and immutable pairs).
properilist? ilist? dottedilist? notipair? nullilist? ilist= icar icdr icaar icadr icdar icddr icaaar icaadr icadar icaddr icdaar icdadr icddar icdddr icaaaar icaaadr icaadar icaaddr icadaar icadadr icaddar icadddr icdaaar icdaadr icdadar icdaddr icddaar icddadr icdddar icddddr icar+icdr ilistref ifirst isecond ithird ifourth ififth isixth iseventh ieighth ininth itenth idrop ilisttail itakeright ilast lastipair ilength icount iforeach ifold ipairfold ireduce ifoldright ipairfoldright ireduceright ipairforeach imember imemv imemq ifindtail iany ievery ilistindex idropwhile iassoc iassq iassv iapply makeilistcomparator makeimproperilistcomparator makeicarcomparator makeicdrcomparator makeipaircomparator
Next: scheme.ideque
 R7RS immutable deques, Previous: scheme.ilist
 R7RS immutable lists, Up: R7RS large [Contents][Index]
scheme.rlist
 R7RS randomaccess listsThis module provides an alternative datatype for pairs and lists,
which are immutable and allows O(log n) random access, while
maintaining O(1) car
and cdr
operations.
This is originally defined as srfi.101
. We call this datatype
rlist in the following explanation.
The srfi allows a Scheme implementation to adopt rlist
as the builtin pairs and lists, so the procedure names are
duplicated from the Scheme primitives. If you use this module,
you might want to import with prefix
(e.g. (use scheme.rlist :prefix rlist:)
).
In Gauche, we implement rlist on top of skewlist
(see data.skewlist
 Skew binary randomaccess lists). The main difference
is that skewlist only allows proper lists, while rlist allows
improper lists (the cdr
of the last pair can be an arbitrary
objects).
However, having improper lists makes things a lot complicated. If you just need a list with fast random access, you want to use skewlist. Use rlist only if you need to deal with improper lists.
The following procedures behave just like the builtin counterparts,
except they take/return rlists instead of ordinary pairs and lists.
(NB: listref
and listtail
here doesn’t take the optional
fallback argument, for they are Gauche’s extension).
pair? cons car cdr caar cadr cdar cddr caaar caadr cadar caddr cdaar cdadr cddar cdddr caaaar caaadr caadar caaddr cadaar cadadr caddar cadddr cdaaar cdaadr cdadar cdaddr cddaar cddadr cdddar cddddr null? list? list makelist length append reverse listtail listref map foreach
This module also exports a syntax quote
, which denotes
the literal rlist. (quote (a (b c)))
becomes a literal
rlist consists of elements a
, and an rlist consists
of b
and c
.
Note that if you import scheme.rlist
without suffix,
the shorthand notation '(a (b c))
refers to scheme.rlist#quote
,
instead of builtin quote
.
[R7RS rlist] {scheme.rlist} Returns a new rlist which is the same as rlist except that its kth element is replaced with obj. This is O(log n) operation where n is the length of rlist.
[R7RS rlist]
{scheme.rlist}
Returns two values, the result of (listref rlist k)
and the result of (listset rlist k (proc (listref rlist k)))
,
but may be more efficient.
[R7RS rlist] {scheme.rlist} Convert a proper rlist to an ordinary list. An error is thrown when rlist is not proper. The conversion is only done in the “spine” of rlist; that is, if rlist is nested, only the outermost rlist is converted.
[R7RS rlist] {scheme.rlist} Convert a proper ordinary list to an rlist. An error is thrown when list is not proper. The conversion is only done in the “spine” of list; that is, if list is nested, only the outermost list is converted.
Next: scheme.text
 R7RS immutable texts, Previous: scheme.rlist
 R7RS randomaccess lists, 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 bidirectional 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 data.ringbuffer
 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 data.ideque
 Immutable deques.
[R7RS ideque] {scheme.ideque} Returns an ideque with the given elements.
[R7RS ideque]
{scheme.ideque}
Construct an ideque in the same way as unfold
(see scheme.list
 R7RS lists),
that is, a predicate p is applied to a current state value;
if it returns true, the iteration stops. Otherwise, an item
generator function f is applied to the current state value,
and its value becomes an element of the ideque. Then a
next state function g
is applied to the current state value,
and its result becomes the next state value, and we iterate.
The result of f is gathered in order, and becomes the content
of the returned ideque.
The seed argument specifies the initial state value.
(ideque>list (idequeunfold (cut > <> 10) square (cut + <> 1) 0)) ⇒ (0 1 4 9 16 25 36 49 64 81 100)
[R7RS ideque]
{scheme.ideque}
Similar to idequeunfold
, but the generated elements are
stored in the reverse order in the resulting ideque.
(ideque>list (idequeunfoldright (cut > <> 10) square (cut + <> 1) 0)) ⇒ (100 81 64 49 36 25 16 9 4 1 0)
[R7RS ideque]
{scheme.ideque}
Create an ideque of length size, whose ith element
is computed by (init i)
.
(ideque>list (idequetabulate 11 square)) ⇒ (0 1 4 9 16 25 36 49 64 81 100)
[R7RS ideque] {scheme.ideque} Returns true iff obj is an ideque.
[R7RS ideque] {scheme.ideque} Returns true iff an ideque idq is empty.
[R7RS ideque] {scheme.ideque} Returns an ideque with an item x added to the front or back of an ideque idq, respectively. These are O(1) operations.
[R7RS ideque] {scheme.ideque} Returns the front or back element of an ideque idq, respectively. An error is thrown if idq is empty. Thess are O(1) operations.
[R7RS ideque] {scheme.ideque} Returns an ideque with the front or back element of idq removed, respectively. An error is thrown if idq is empty. These are O(1) operations.
[R7RS ideque] {scheme.ideque} Returns an ideque with the elements of idq in reverse order. This is O(1) operation.
[R7RS ideque]
{scheme.ideque}
Returns #t
iff all ideques are of the same length,
and each corresponding element compares equal by elt=, which
is called with two arguments, one element from ith ideque and
another element from (i+1)th ideque.
If zero or one ideque is given, elt= won’t be called at all
and this procedure returns #t
.
[R7RS ideque] {scheme.ideque} Returns nth element of idq. An error is signaled if n is out of range.
[R7RS ideque] {scheme.ideque} Returns an ideque that has first or last n elements of idq, respectively An error is signaled if n is greater than the length of idq.
[R7RS ideque] {scheme.ideque} Returns an ideque that has elements of idq with first or last n elements removed, respectively. An error is signaled if n is greater than the length of idq.
[R7RS ideque]
{scheme.ideque}
Returns two ideques, the first one is (idequetake idq n)
and
the second one is (idequedrop idq n)
.
An error is signaled if n is greater than the length of idq.
[R7RS ideque] {scheme.ideque} Returns the length of idq.
[R7RS ideque] {scheme.ideque} Returns an ideque that concatenates contents of given ideques.
[R7RS ideque] {scheme.ideque} Returns an ideque whose ith element is a list of ith elements of given ideques. If the length of given ideques differ, the result terminates at the shortest ideque.
(ideque>list (idequezip (ideque 'a 'b 'c) (ideque 1 2) (ideque 'x 'y 'z))) ⇒ ((a 1 x) (b 2 y))
[R7RS ideque] {scheme.ideque} Applies proc to each element of idq, and returns an ideque containins the results in order. The dynamic order of calls of proc is unspecified. This is O(n) operation.
Note that R7RS ideque only supports single idq argument. It is Gauche’s extension to allow more than one idq arguments; in that case, proc gets as many arguments as the given ideques, each argument taken from each ideque. The length of the result ideque is limited to the shortest length of the input ideques.
(ideque>list (idequemap square (ideque 1 2 3 4 5))) ⇒ (1 4 9 16 25) (ideque>list (idequemap + (ideque 1 2 3 4 5) (ideque 2 2 2))) ⇒ (11 12 13)
[R7RS ideque]
{scheme.ideque}
Applies proc to each element of idq, and returns
an ideque containins the results in order, except #f
.
The dynamic order of calls of proc is unspecified.
Note that R7RS ideque only supports single idq argument. It is Gauche’s extension to allow more than one idq arguments; in that case, proc gets as many arguments as the given ideques, each argument taken from each ideque. The input is read until any of the idq reaches at the end.
[R7RS ideque]
{scheme.ideque}
Applies proc to each element of idq from left to right
(idequeforeach
) or right to left (idequeforeachright
).
Results of proc are discarded.
Returns an unspecified value.
Note that R7RS ideque only supports single idq argument. If more than one ideques are given, proc gets as many arguments as the given ideques, each argument taken from each ideque.
idequeforeach
takes each ideque’s elements from leftmost ones,
while idequeforeachright
takes each ideque’s elements from rightmost
ones. Both ends when the shortest ideque is exhausted.
(idequeforeach ($ display $ list $) (ideque 'a 'b 'c 'd 'e) (ideque 1 2 3)) ⇒ prints (a 1)(b 2)(c 3) (idequeforeachright ($ display $ list $) (ideque 'a 'b 'c 'd 'e) (ideque 1 2 3)) ⇒ prints (e 3)(d 2)(c 1)
[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: scheme.generator
 R7RS generators, Previous: scheme.ideque
 R7RS immutable deques, Up: R7RS large [Contents][Index]
scheme.text
 R7RS immutable textsThis module provides text type, an immutable string with O(1) random access. This is originally defined in SRFI135.
In Gauche, a string with index access generally takes O(n) because of
mulitbyte representation; however,
if the string is ASCIIonly or you precalculate string indexes,
index access becomes O(1) (see String indexing).
So, a text in Gauche is just an immutable indexed string. It satisfies
string?
, too.
Since text is not disjoint from string in Gauche, textual
type mentioned in this srfi
is equivalent to a string type, and many textual*
procedures are
just aliases to the corresponding string*
procedures.
However, if you’re writing portable code, keep it in mind that some implementation may have disjoint text and string types.
[R7RS text]
{scheme.text}
Returns #t
iff obj is a text, which is an immutable
indexed string in Gauche. Note that a text type is not disjoint
from a string in Gauche.
[R7RS text]
{scheme.text}
Returns #t
iff obj is either a text or a string.
In Gauche, this is just an alias of string?
.
[R7RS text]
{scheme.text}
Returns #t
iff obj is an empty string/text. In Gauche
this is just an alias of stringnull?
.
[R7RS text]
{scheme.text}
Like stringevery
and stringany
, but can work on both
texts and strings. In Gauche, these are just aliases of
stringevery
and stringany
.
[R7RS text]
{scheme.text}
In Gauche it is same as makestring
, except that the returned
string is immutable and indexed, and you can’t omit char.
[R7RS text]
{scheme.text}
Like string
, but returned string is immutable and indexed.
[R7RS text]
{scheme.text}
Like stringtabulate
, but returned string is immutable and indexed
(see String constructors).
[R7RS text]
{scheme.text}
Like stringunfold
and stringunfoldright
,
but returned string is immutable and indexed
(see String constructors). The mapper procedure f may return
a string instead of a character.
[R7RS text] {scheme.text} Returns the length of text. An error is signaled if text is not a text.
[R7RS text] {scheme.text} Returns indexth character of the text. Guaranteed to be O(1). An error is signaled if text is not a text.
[R7RS text]
{scheme.text}
Returns the length of a text or a string.
This is just an alias of stringlength
in Gauche.
[R7RS text]
{scheme.text}
Returns indexth character of the text.
This is just an alias of stringref
in Gauche.
[R7RS text] {scheme.text} Takes a string, and returns an immutable, indexed string of the same content. If textual is already a such string, it is returned as is.
[R7RS text]
{scheme.text}
Converts a textual to a fresh mutable string,
a vector and a list, respectively.
These are aliases of stringcopy
, string>vector
and string>list
in Gauche.
[R7RS text]
{scheme.text}
Convert a string, a vector of characters, and a list of characters
to an immutable indexed string.
If an immutable indexed string is given to string>text
without
start/end arguments, the input is returned as is.
[R7RS text]
{scheme.text}
Same as (list>text (reverse charlist))
but maybe more efficient.
[R7RS text]
{scheme.text}
Returns a bytevector (u8vector) that contains utf8 encoding of the input
textual. In Gauche, it is the same as string>utf8
(see Unicode transfer encodings).
[R7RS text]
{scheme.text}
Returns a bytevector (u8vector) that contains utf16 encoding of the input
textual, with BOM attached, and in the native byteorder.
In Gauche, it is the same as
(string>utf16 textual (nativeendian) #t [start end])
(see Unicode transfer encodings).
[R7RS text]
{scheme.text}
Returns a bytevector that contains utf16be and utf16le encoding of the input
textual. No BOM is attached.
In Gauche, they are the same as
(string>utf16 textual 'bigendian #f [start end])
and
(string>utf16 textual 'littleendian #t [start end])
(see Unicode transfer encodings).
[R7RS text] {scheme.text} Converts a utf8 octet sequence stored in bytevector (u8vector) to a text. If the octet sequence begins with BOM sequence, it is interpreted as a character U+FEFF. Optional start/end arguments limits the input range of bytevector.
If the input contains an invalid utf8 sequence, and Gauche’s native encoding is utf8, it is replaced by a unicode replacement character U+FFFD. (NB: SRFI135 says it is an error.)
[R7RS text]
{scheme.text}
Converts a utf16 octet sequence stored in bytevector to a text.
For utf16>text
, the sequence may begin with BOM,
in which case it determines the endianness.
Otherwise, platform’s native endianness is assumed.
Fro utf16be>text
and utf16le>text
, the input is
assumed to be in UTF16BE/UTF16LE respectively; if it begins with BOM
it is treated as a character U+FEFF.
Optional start/end arguments limits the input range of bytevector. If the length of input (end  start, if the range is limited) isn’t even, an error is thrown.
If the input contains an invalid utf16 sequence (unpaired surrogates), it is replaced by a unicode replacement character U+FFFD. (NB: SRFI135 says it is an error.)
[R7RS text] {scheme.text} Returns a text between startth (inclusive) and endth (exclusive) characters in the input.
[R7RS text] {scheme.text} Returns a copy of textual, optionally limited between start/end, as a text.
SRFI135 specifies that even the input is a text, the returned one
must be freshly allocated (as opposed to subtextual
, which
is allowed to return the result sharing the input).
In Gauche, string body is immutable anyway,
so it isn’t a big deal.
[R7RS text]
{scheme.text}
In Gauche, these are the same as corresponding string operations
(stringtake
, stringdrop
, stringtakeright
,
stringdropright
, stringpad
, stringpadright
,
stringtrim
, stringtirmright
, and stringtrimboth
),
except that the returned string is always immutable and indexed.
See String selection, for these string procedures.
[R7RS text]
{scheme.text}
In Gauche, this is same as stringreplace
,
except that the returned string is always immutable and indexed.
See Other string operations, for the details.
[R7RS text]
{scheme.text}
EN
In Gauche, these are just aliases of builtin
string=?
, string<?
, string>?
,
string<=?
and string>?
, respectively.
See String comparison, for the details.
[R7RS text]
{scheme.text}
In Gauche, these are just aliases of the unicode version of
stringci=?
, stringci<?
, stringci>?
,
stringci<=?
and stringci>?
, respectively.
See Full string case conversion, for the details.
[R7RS text]
{scheme.text}
In Gauche, these are just aliases of srfi.13
’s
stringprefixlength
, stringsuffixlength
,
stringprefix?
, and stringsuffix?
, respectively.
See String prefixes & suffixes, for the details.
[R7RS text]
{scheme.text}
In Gauche, these are just aliases of srfi.13
’s
stringindex
, stringindexright
,
stringskip
, stringskipright
,
stringcontains
, and stringcontainsright
, respectively.
See String searching, for the details.
[R7RS text]
{scheme.text}
In Gauche, these are the same as stringupcase
,
stringdowncase
, stringfoldcase
and stringtitlecase
of gauche.unicode
, respectively, except that the result is
always an immutable and indexed string.
See Full string case conversion, for the details.
[R7RS text]
{scheme.text}
In Gauche, these are the same as stringappend
and
stringconcatenate
respectively, except that the result
is always an immutable and indexed string.
[R7RS text] {scheme.text} The args must be a list of textuals (same as strings in Gauche). As to the optional arguments, finaltextual must be a textual, and end must be a nonnegative exact integer, if provided.
Without optional arguments, this is the same as
stringconcatenatereverse
of srfi.13
(see String reverse & append, except that
the result is always an immutable and indexed string.
If finaltextual is provided, it is appended to the last.
If end is also provided, (subtext finaltextual 0 end)
is
appended to the last.
[R7RS text]
{scheme.text}
This is the same as stringjoin
except that the result
is always an immutable and indexed string
(see String utilities).
[R7RS text]
{scheme.text}
These are just aliases of srfi.13
’s
stringfold
and stringfoldright
,
respectively (see String mapping).
[R7RS text] {scheme.text}
[R7RS text] {scheme.text}
[R7RS text] {scheme.text}
[R7RS text] {scheme.text}
[R7RS text] {scheme.text}
[R7RS text] {scheme.text}
[R7RS text] {scheme.text}
[R7RS text]
{scheme.text}
Like stringsplit
, except that the returned strings are all
immutable and indexed. See String utilities, for the details.
Next: scheme.lseq
 R7RS lazy sequences, Previous: scheme.text
 R7RS immutable texts, Up: R7RS large [Contents][Index]
scheme.generator
 R7RS generatorsThis module provides generators and accumulators.
They were first defined in SRFI121,
then enhanced in SRFI158, and finally
incorporated R7RS large as (scheme generator)
.
A generator is a thunk to generate a sequence of values, potentially
terminated by EOF. Procedures to deal with generators are
provided by gauche.generator
, which is a superset of SRFI121.
See gauche.generator
 Generators, for the details.
An accumulator is an opposite of generators. They are procedures that work as consumers. An accumulator takes one argument. When noneof value is given, the value is stored, and when EOF is given, the accumulated value is returned. How the values are accumulated depends on the accumulator.
Once EOF is given, the accumulator is “finalized”. Subsequent EOF makes it return the same accumulated value. It is undefined if other values are passed after EOF is passed.
The accumulator can be used to parameterize procedures that yield
aggregate objects. Consider the following procedure, which
takes items from two generators and accumulate them alternatively.
(Note that glet*
is Gauche’s procedure but not in SRFI158).
(define (intertwine acc gen1 gen2) (let loop () (glet* ([a (gen1)] [b (gen2)]) (acc a) (acc b) (loop))) (acc (eofobject)))
The procedure can return various type of collections, without knowing the actual type—the passed accumulator determines it.
(intertwine (listaccumulator) (giota 5) (giota 5 100)) ⇒ (0 100 1 101 2 102 3 103 4 104) (intertwine (vectoraccumulator) (giota 5) (giota 5 100)) ⇒ #(0 100 1 101 2 102 3 103 4 104) (intertwine (bytevectoraccumulator) (giota 5) (giota 5 100)) ⇒ #u8(0 100 1 101 2 102 3 103 4 104)
Note: In Gauche, you can also use classes to parameterize returned
container types (e.g. mapto
),
for many collection classes support builder protocol.
See gauche.collection
 Collection framework, for the details.
Accumulator has the flexibility that you can provide more than one
ways to construct return value on the same type (e.g. forward and reverse
list).
The following generator procedures are explained in
gauche.generator
section (see gauche.generator
 Generators):
generator circulargenerator makeiotagenerator makerangegenerator makecoroutinegenerator makeunfoldgenerator makeforeachgenerator list>generator vector>generator reversevector>generator string>generator bytevector>generator
gcons* gappend gflatten ggroup gmerge gmap gcombine gfilter gremove gstatefilter ggroup gtake gdrop gtakewhile gdropwhile gdelete gdeleteneighbordups gindex gselect
generator>list generator>reverselist generatormap>list generator>vector generator>vector! generator>string generatorcount generatorany generatorevery generatorunfold
generatorfold generatorforeach generatorfind
The following are accumulator procedures:
[R7RS generator]
{scheme.generator}
Creates and returns an accumulator with a state,
whose initial value is knil.
When nonEOF value v is passed to the accumulator,
kons is called as (kons v state)
, and its result
becomes the new state value. When EOF value is passed,
(finalizer state)
is called and its result becomes
the result of accumulator.
[R7RS generator]
{scheme.generator}
Creates and returns accumulators that return accumulated value
as a list, in the accumulated order (listaccumulator
)
or the reverse order (reverselistaccumulator
).
[R7RS generator]
{scheme.generator}
Returns accumulators that return accumulated value
as a fresh vector or bytevector (u8vector),
in the accumulated order (vectoraccumulator
,
bytevectoraccumulator
)
or the reverse order (reversevectoraccumulator
).
There’s no reversebytevectoraccumulator
.
[R7RS generator] {scheme.generator} The vec or bvec argument is a mutable vector or bytevector (u8vector), and is used as a buffer.
Returns an accumulator that stores the accumulated values in the buffer, starting from the index at. It is an error if the accumulator gets more values after the buffer reaches at the end.
Once EOF is passed to the accumulator, vec or bvec is returned, respectively.
[R7RS generator] {scheme.generator} Returns an accumulator that accepts characters and accumulates them to a string.
[R7RS generator] {scheme.generator} Returns accumulators that yield a scalar value.
The accumulator created by sumaccumulator
and
productaccumulator
accepts numbers,
and keep adding or multiplying it with the accumulated value
(the default value is 0 and 1, respectively).
The accumulator created by countaccumulator
accepts any
objects and just counting it.
Next: scheme.stream
 R7RS stream, Previous: scheme.generator
 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 util.stream
 Stream library),
which requires to create a thunk for every element.
Gauche already has builtin support for such lazy sequences; we go further 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 ordinary 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: scheme.box
 R7RS boxes, Previous: scheme.lseq
 R7RS lazy sequences, Up: R7RS large [Contents][Index]
scheme.stream
 R7RS streamThis module provides utilities for lazily evaluated streams. It is more heavyweight than lazy sequences (see Lazy sequences), but it strictly implements “as lazy as possible” semantics—elements are never evaluated until it is actually accessed.
The following procedures are provided in Gauche’s util.stream
module;
see util.stream
 Stream library for their description:
streamnull streamcons stream? streamnull? streampair? streamcar streamcdr streamlambda definestream list>stream port>stream stream>list streamappend streamconcat streamconstant streamdropwhile streamfilter streamfold streamforeach streamfrom streamiterate streamlength streamlet streammap streammatch streamof streamrange streamref streamreverse streamscan streamtakewhile streamunfold streamunfolds streamzip
The following macro and procedures have different interface from
Gauche’s util.stream
module:
stream streamtake streamdrop
[R7RS stream] {scheme.stream} Returns a new stream whose elements are the result of expr …. Arguments won’t be evaluated until required.
This differs from SRFI40 and util.stream
’s stream
,
which is a procedure so arguments are evaluated
(see Stream constructors, for the details).
[R7RS stream]
{scheme.stream}
Returns a stream that contains first n elements from stream,
or elements without first n elements from it, respectively.
If stream has less than n elements, streamtake
returns a copy of the entire stream, while streamdrop
returns a null stream.
Note that the argument order doesn’t follow the Scheme tradition,
which takes the main object (stream in this case) first, then
the count. Procedures with the same name is provided in util.stream
with the different argument order.
Next: scheme.listqueue
 R7RS list queues, Previous: scheme.stream
 R7RS stream, Up: R7RS large [Contents][Index]
scheme.box
 R7RS boxesGauche supports boxes builtin (see Boxes), so this module is merely a facade that exports the following identifiers:
box box? unbox setbox!
Next: scheme.ephemeron
 R7RS ephemeron, Previous: scheme.box
 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 data.queue
 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 data.queue
 Queue).
The cells in lis are owned by the queue; the caller shouldn’t mutate it afterwards, 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 data.queue
 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 scheme.list
 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 scheme.list
 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
simultaneously 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 data.ideque
 Immutable deques, and also
see data.ringbuffer
 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 Gauche, 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.
Next: scheme.comparator
 R7RS comparators, Previous: scheme.listqueue
 R7RS list queues, Up: R7RS large [Contents][Index]
scheme.ephemeron
 R7RS ephemeronThis module defined ephemerons, a weak reference structure to hold keyvalue association. This is originally defined as SRFI142.
Gauche supports weak pointers in the form of weak vectors (see Weak vectors), but it is known that a simple weak pointer (a single pointer that doesn’t prevent the pointed object from being collected) isn’t enough to implement weak keyvalue association such as mappings.
An ephemeron is a record that points to a key and an associated datum, with the following characteristics:
Implementing the proper ephemeron requires deep integration with the GC. At this moment, Gauche’s ephemeron is implemented separately from GC, and has the following limitations:
ephemeronbroken?
needs to be called in order
to trigger the collection of the datum.
Since the timing of collection isn’t specified in the spec, Gauche’s implementation still conforms SRFI142, but in practice you need to be aware of these limitations. Eventually we want to support full ephemeron integrated with GC.
Once the key and/or the datum is collected (we call such ephemeron “broken”), referencing them returns a bogus value. The proper way to use an ephemeron e is the following pattern:
(let ([k (ephemeronkey e)] [d (ephemerondatum e)]) (if (ephemeronbroken? e) (... k and d are invalid ...) (... k and d are valid ...)))
You should take values, then check if the ephemeron isn’t broken yet.
If you call ephemeronbroken?
first, there’s a chance
that the ephemeron is broken between the check and the time
you reference it.
[R7RS ephemeron] {scheme.ephemeron} Create a new ephemeron associating the key to the datum.
[R7RS ephemeron]
{scheme.ephemeron}
Returns #t
iff obj is an ephemeron.
[R7RS ephemeron]
{scheme.ephemeron}
Returns the key and the datum of ephemeron, respectively.
If the ephemeron is already broken, there’s no guarantee
on what is returned. Thus you should always call ephemeronbroken?
after calling these procedure to ensure the values are
meaningful. See the scheme.ephemeron
entry for the details.
[R7RS ephemeron]
{scheme.ephemeron}
Returns #t
iff ephemeron has been broken, that is,
its key and/or datum may be collected and cannot be reliably retrieved.
See the scheme.ephemeron
entry for the details.
[R7RS ephemeron] {scheme.ephemeron} This procedure does nothing by itself, but guarantees key is strongly reference until returning from this procedure.
Next: scheme.regex
 R7RS regular expressions, Previous: scheme.ephemeron
 R7RS ephemeron, Up: R7RS large [Contents][Index]
scheme.comparator
 R7RS comparatorsThis module defines comparators and related procedures.
Originally called srfi.128
.
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<=>
Next: scheme.mapping
 R7RS mappings, Previous: scheme.comparator
 R7RS comparators, Up: R7RS large [Contents][Index]
scheme.regex
 R7RS regular expressionsThis module provides operations on Scheme Regular Expressions (SRE).
Originally defined as srfi.115
.
Gauche has builtin support of regular expressions, and this module
simply tranlsates SRE to Gauche’s native regular expressions.
The regular expression object returned from the regexp
procedure
in this module is Gauche’s <regexp>
object, for example.
You can pass Gauche’s regexp object to the procedures that expects
compiled SRE in this module as well.
SRE is just an Sexpression with the structure summarized below.
With the exception of or
, any syntax that takes multiple
<sre>
processes them in a sequence. In other words (foo
<sre> ...)
is equivalent to (foo (seq <sre> ...))
.
Note: SRE uses the symbol 
for alteration, but the vertical bar
character is used for symbol escape in Gauche (and R7RS), so you have to
write such symbol as \
. We recommend to use or
instead.
<sre> ::=  <string> ; A literal string match.  <csetsre> ; A character set match.  (* <sre> ...) ; 0 or more matches.  (zeroormore <sre> ...)  (+ <sre> ...) ; 1 or more matches.  (oneormore <sre> ...)  (? <sre> ...) ; 0 or 1 matches.  (optional <sre> ...)  (= <n> <sre> ...) ; <n> matches.  (exactly <n> <sre> ...)  (>= <n> <sre> ...) ; <n> or more matches.  (atleast <n> <sre> ...)  (** <n> <m> <sre> ...) ; <n> to <m> matches.  (repeated <n> <m> <sre> ...)  (\ <sre> ...) ; Alternation.  (or <sre> ...)  (: <sre> ...) ; Sequence.  (seq <sre> ...)  ($ <sre> ...) ; Numbered submatch.  (submatch <sre> ...)  (> <name> <sre> ...) ; Named submatch. <name> is  (submatchnamed <name> <sre> ...) ; a symbol.  (w/case <sre> ...) ; Introduce a casesensitive context.  (w/nocase <sre> ...) ; Introduce a caseinsensitive context.  (w/unicode <sre> ...) ; Introduce a unicode context.  (w/ascii <sre> ...) ; Introduce an ascii context.  (w/nocapture <sre> ...) ; Ignore all enclosed submatches.  bos ; Beginning of string.  eos ; End of string.  bol ; Beginning of line.  eol ; End of line.  bow ; Beginning of word.  eow ; End of word.  nwb ; A nonword boundary.  (word <sre> ...) ; An SRE wrapped in word boundaries.  (word+ <csetsre> ...) ; A single word restricted to a cset.  word ; A single word.  bog ; Beginning of a grapheme cluster.  eog ; End of a grapheme cluster.  grapheme ; A single grapheme cluster.  (?? <sre> ...) ; A nongreedy pattern, 0 or 1 match.  (nongreedyoptional <sre> ...)  (*? <sre> ...) ; Nongreedy 0 or more matches.  (nongreedyzeroormore <sre> ...)  (**? <m> <n> <sre> ...) ; Nongreedy <m> to <n> matches.  (nongreedyrepeated <sre> ...)  (atomic <sre> ...) ; Atomic clustering.  (lookahead <sre> ...) ; Zerowidth lookahead assertion.  (lookbehind <sre> ...) ; Zerowidth lookbehind assertion.  (neglookahead <sre> ...) ; Zerowidth negative lookahead assertion.  (neglookbehind <sre> ...) ; Zerowidth negative lookbehind assertion.  (backref <norname>) ; Match a previous submatch.
The grammar for csetsre
is as follows.
<csetsre> ::=  <char> ; literal char  "<char>" ; string of one char  <charset> ; embedded SRFI 14 char set  (<string>) ; literal char set  (charset <string>)  (/ <rangespec> ...) ; ranges  (charrange <rangespec> ...)  (or <csetsre> ...) ; union  (\ <csetsre> ...)  (and <csetsre> ...) ; intersection  (& <csetsre> ...)  ( <csetsre> ...) ; difference  ( <difference> ...)  (~ <csetsre> ...) ; complement of union  (complement <csetsre> ...)  (w/case <csetsre>) ; case and unicode toggling  (w/nocase <csetsre>)  (w/ascii <csetsre>)  (w/unicode <csetsre>)  any  nonl  ascii  lowercase  lower  uppercase  upper  titlecase  title  alphabetic  alpha  alphanumeric  alphanum  alnum  numeric  num  punctuation  punct  symbol  graphic  graph  whitespace  white  space  printing  print  control  cntrl  hexdigit  xdigit <rangespec> ::= <string>  <char>
<string>
A literal string.
(regexpsearch "needle" "hayneedlehay") ⇒ #<regexpmatch> (regexpsearch "needle" "haynEEdlehay") ⇒ #f
(seq <sre> ...)
(: <sre> ...)
A sequence of patterns that should be matched in the same order. This
is the same as RE syntax (?:re…)
(regexpsearch '(: "one" space "two" space "three") "one two three") ⇒ #<regexpmatch>
(or <sre> ...)
(\ <sre> ...)
Matches one of the given patterns. This is the same as
RE syntax pattern1pattern2…
(regexpsearch '(or "eeney" "meeney" "miney") "meeney") ⇒ #<regexpmatch> (regexpsearch '(or "eeney" "meeney" "miney") "moe") ⇒ #f
(w/nocase <sre> ...)
Changes to match the given patterns caseinsensitively. Subpatterns
can still be made sensitive with w/case
. This is the same as
RE syntax (?i:re…)
(regexpsearch "needle" "haynEEdlehay") ⇒ #f (regexpsearch '(w/nocase "needle") "haynEEdlehay") ⇒ #<regexpmatch> (regexpsearch '(~ ("Aab")) "B") ⇒ #<regexpmatch> (regexpsearch '(~ ("Aab")) "b") ⇒ #f (regexpsearch '(w/nocase (~ ("Aab"))) "B") ⇒ #f (regexpsearch '(w/nocase (~ ("Aab"))) "b") ⇒ #f (regexpsearch '(~ (w/nocase ("Aab"))) "B") ⇒ #f (regexpsearch '(~ (w/nocase ("Aab"))) "b") ⇒ #f
(w/case <sre> ...)
Changes to match the given patterns casesensitively. Subpatterns can
still be made caseinsensitive. This is the same as RE syntax
(?i:re…)
. This is the default.
(regexpsearch '(w/nocase "SMALL" (w/case "BIG")) "smallBIGsmall") ⇒ #<regexpmatch> (regexpsearch '(w/nocase (~ (w/case ("Aab")))) "b") ⇒ #f
(w/ascii <sre> ...)
Limits the character sets and other predefined patterns to ASCII. This
affects patterns or character sets like any
, alpha
,
(word)
…
(regexpsearch '(w/ascii bos (* alpha) eos) "English") ⇒ #<regexpmatch> (regexpsearch '(w/ascii bos (* alpha) eos) "Ελληνική") ⇒ #f
(w/unicode <sre> ...)
Changes the character sets and other predefined patterns back to
Unicode if w/ascii
has been used in the outer scope. This is
the default.
(regexpsearch '(w/unicode bos (* alpha) eos) "English") ⇒ #<regexpmatch> (regexpsearch '(w/unicode bos (* alpha) eos) "Ελληνική") ⇒ #<regexpmatch>
(w/nocapture <sre> ...)
Disables capturing for all submatch
and submatchnamed
inside.
(let ((number '($ (+ digit)))) (cdr (regexpmatch>list (regexpsearch `(: ,number "" ,number "" ,number) "5558675309"))) ; ⇒ '("555" "867" "5309") (cdr (regexpmatch>list (regexpsearch `(: ,number "" (w/nocapture ,number) "" ,number) "5558675309")))) ⇒ '("555" "5309")
(optional <sre> ...)
(? <sre> ...)
Matches the pattern(s) one or zero times.
(regexpsearch '(: "match" (? "es") "!") "matches!") ⇒ #<regexpmatch> (regexpsearch '(: "match" (? "es") "!") "match!") ⇒ #<regexpmatch> (regexpsearch '(: "match" (? "es") "!") "matche!") ⇒ #f
(zeroormore <sre> ...)
(* <sre> ...)
Matches the pattern(s) zero or more times.
(regexpsearch '(: "<" (* (~ #\>)) ">") "<html>") ⇒ #<regexpmatch> (regexpsearch '(: "<" (* (~ #\>)) ">") "<>") ⇒ #<regexpmatch> (regexpsearch '(: "<" (* (~ #\>)) ">") "<html") ⇒ #f
(oneormore <sre> ...)
(+ <sre> ...)
Matches the pattern(s) at least once.
(regexpsearch '(: "<" (+ (~ #\>)) ">") "<html>") ⇒ #<regexpmatch> (regexpsearch '(: "<" (+ (~ #\>)) ">") "<a>") ⇒ #<regexpmatch> (regexpsearch '(: "<" (+ (~ #\>)) ">") "<>") ⇒ #f
(atleast n <sre> ...)
(>= n <sre> ...)
Matches the pattern(s) at least n
times.
(regexpsearch '(: "<" (>= 3 (~ #\>)) ">") "<table>") ⇒ #<regexpmatch> (regexpsearch '(: "<" (>= 3 (~ #\>)) ">") "<pre>") ⇒ #<regexpmatch> (regexpsearch '(: "<" (>= 3 (~ #\>)) ">") "<tr>") ⇒ #f
(exactly n <sre> ...)
(= n <sre> ...)
Matches the pattern(s) exactly n
times.
(regexpsearch '(: "<" (= 4 (~ #\>)) ">") "<html>") ⇒ #<regexpmatch> (regexpsearch '(: "<" (= 4 (~ #\>)) ">") "<table>") ⇒ #f
(repeated from to <sre> ...)
(** from to <sre> ...)
Matches the pattern(s) at least from
times and up to to
times.
(regexpsearch '(: (= 3 (** 1 3 numeric) ".") (** 1 3 numeric)) "192.168.1.10") ⇒ #<regexpmatch> (regexpsearch '(: (= 3 (** 1 3 numeric) ".") (** 1 3 numeric)) "192.0168.1.10") ⇒ #f
(submatch <sre> ...)
($ <sre> ...)
Captures the matched string. Each capture is numbered increasing from one (capture zero is the entire matched string). For nested captures, the numbering scheme is depthfirst walk.
(submatchnamed <name> <sre> ...)
(> <name> <sre> ...)
Captures the matched string and assigns a name to it in addition to a
number. This is the equivalent of (?<name>re…)
(backref <norname>)
Matches a previously matched submatch. This is the same as
RE syntax \n
or \k<name>
.
<char>
A character set contains a single character.
(regexpmatches '(* #\) "") ⇒ #<regexpmatch> (regexpmatches '(* #\) "_") ⇒ #f
"<char>"
A character set contains a single character. This is technically ambiguous with SRE matching a literal string. However the end result of both syntaxes is the same.
<charset>
A SRFI14 character set.
Note that while currently there is no portable written representation
of SRFI 14 character sets, you can use Gauche reader syntax
#[charsetspec]
, see Character Sets.
(regexppartition `(+ ,charset:vowels) "vowels") ⇒ ("v" "o" "w" "e" "ls")
(charset <string>)
(<string>)
A character set contains the characters in the given string. This is
the same as `(charset ,(string>charset <string>))
.
(regexpmatches '(* ("aeiou")) "oui") ⇒ #<regexpmatch> (regexpmatches '(* ("aeiou")) "ouais") ⇒ #f (regexpmatches '(* ("e\x0301")) "e\x0301") ⇒ #<regexpmatch> (regexpmatches '("e\x0301") "e\x0301") ⇒ #f (regexpmatches '("e\x0301") "e") ⇒ #<regexpmatch> (regexpmatches '("e\x0301") "\x0301") ⇒ #<regexpmatch> (regexpmatches '("e\x0301") "\x00E9") ⇒ #f
(charrange <rangespec> ...)
(/ <rangespec> ...)
A character set contains the characters within
<rangeset>
. This is the same as RE syntax []
.
(regexpmatches '(* (/ "AZ09")) "R2D2") ⇒ #<regexpmatch> (regexpmatches '(* (/ "AZ09")) "C3PO") ⇒ #f
(or <csetsre> ...)
(\ <csetsre> ...)
A shorthand for `(charset ,(charsetunion <csetsre>...))
.
(complement <csetsre> ...)
(~ <csetsre> ...)
A shorthand for `(charset ,(charsetcomplement <csetsre>...))
.
(difference <csetsre> ...)
( <csetsre> ...)
A shorthand for `(charset ,(charsetdifference <csetsre>...))
.
(regexpmatches '(* ( (/ "az") ("aeiou"))) "xyzzy") ⇒ #<regexpmatch> (regexpmatches '(* ( (/ "az") ("aeiou"))) "vowels") ⇒ #f
(and <csetsre> ...)
(& <csetsre> ...)
A shorthand for `(charset ,(charsetintersection <csetsre>...))
.
(regexpmatches '(* (& (/ "az") (~ ("aeiou")))) "xyzzy") ⇒ #<regexpmatch> (regexpmatches '(* (& (/ "az") (~ ("aeiou")))) "vowels") ⇒ #f
(w/case <csetsre>)
(w/nocase <csetsre>)
(w/ascii <csetsre>)
(w/unicode <csetsre>)
This is similar to the SRE equivalent, listed to indicate that they can also be applied on character sets.
Note that if w/ascii
is in effect, these character sets will
return the ASCII subset. Otherwise they return full Unicode ones.
any
Matches any character. This is the .
in regular expression.
nonl
Matches any character other than #\return
or #\newline
.
ascii
A shorthand for `(charset ,charset:ascii)
.
lowercase
lower
A shorthand for `(charset ,charset:lowercase)
.
uppercase
upper
A shorthand for `(charset ,charset:uppercase)
.
titlecase
title
A shorthand for `(charset ,charset:titlecase)
.
alphabetic
alpha
A shorthand for `(charset ,charset:letter)
.
numeric
num
A shorthand for `(charset ,charset:digit)
.
alphanumeric
alphanum
alnum
A shorthand for `(charset ,charset:letter+digit)
.
punctuation
punct
A shorthand for `(charset ,charset:punctuation)
.
symbol
A shorthand for `(charset ,charset:symbol)
.
graphic
graph
A shorthand for `(charset ,charset:graphic)
.
(or alphanumeric punctuation symbol)
whitespace
white
space
A shorthand for `(charset ,charset:whitespace)
.
printing
print
A shorthand for `(charset ,charset:printing)
.
control
cntrl
A character set contains ASCII characters with from 0 to 31.
hexdigit
xdigit
A shorthand for `(charset ,charset:hexdigit)
.
bos
eos
Matches the beginning of the string. If start/end parameters are specified, matches the start or end of the substring as specified.
bol
eol
Matches the beginning or end of a line (or the string). For single
line matching, this is the same as bos
and eos
. A line
is interpreted the same way with readline
.
bow
eow
Matches the beginning or the end of a word.
(regexpsearch '(: bow "foo") "foo") ⇒ #<regexpmatch> (regexpsearch '(: bow "foo") "<foo>>") ⇒ #<regexpmatch> (regexpsearch '(: bow "foo") "snafoo") ⇒ #f (regexpsearch '(: "foo" eow) "foo") ⇒ #<regexpmatch> (regexpsearch '(: "foo" eow) "foo!") ⇒ #<regexpmatch> (regexpsearch '(: "foo" eow) "foobar") ⇒ #f
nwb
A shorthand for (neglookahead (or bow eow))
.
(word <sre> ...)
Matches the word boundary around the given SRE:
(: bow <sre> ... eow)
(word+ <csetsre> ...)
Matches a single word composed of characters of the given characters sets:
(word (+ (and (or alphanumeric "_") (or csetsre ...))))
word
A shorthand for (word+ any)
.
bog
eog
Matches the beginning or end of a graphame cluster. See Unicode text segmentation, for the lowlevel grapheme cluster segmentation.
grapheme
Matches a single grapheme cluster. See Unicode text segmentation, for the lowlevel grapheme cluster segmentation.
(nongreedyoptional <sre> ...)
(?? <sre> ...)
The nongreedy equivalent of (optional <sre>...)
. This is the
same as RE syntax re??
(nongreedyzeroormore< <sre> ...)
(*? <sre> ...)
The nongreedy equivalent of (zeroormore <sre>...)
. This is
the same as RE syntax re*?
(nongreedyrepeated <m> <n> <sre> ...)
(**? <m> <n> <sre> ...)
The nongreedy equivalent of (repeated <sre>...)
. This is the
same as RE syntax re{n,m}?
(atomic <sre> ...)
Atomic clustering. Once <sre> ...
matches, the match is fixed;
even if the following pattern fails, the engine won’t backtrack to try
the alternative match in <sre> ...
. This is Gauche extension
and is the same as RE syntax (?>pattern)
(lookahead <sre> ...)
Zerowidth lookahead assertion. Asserts the sequence matches from the
current position, without advancing the position. This is the same as
RE syntax (?=pattern)
(regexpmatches '(: "regular" (lookahead " expression") " expression") "regular expression") ⇒ #<regexpmatch> (regexpmatches '(: "regular" (lookahead " ") "expression") "regular expression") ⇒ #f
(lookbehind <sre> ...)
Zerowidth lookbehind assertion. Asserts the sequence matches behind
the current position, without advancing the position. It is an error
if the sequence does not have a fixed length. This is the same as RE
syntax (?<=pattern)
(neglookahead <sre> ...)
Zerowidth negative lookahead assertion. This is the same as
RE syntax (?!pattern)
(neglookbehind <sre> ...)
Zerowidth negative lookbehind assertion. This is the same as RE
syntax (?<!pattern)
[R7RS regex]
{scheme.regex}
Compiles the given Scheme Regular Expression into a <regexp>
object. If re is already a regexp object, the object is
returned asis.
[R7RS regex]
{scheme.regex}
A macro shorthand for (regexp `(: sre ...))
.
[R7RS regex] {scheme.regex} Returns the SRE corresponding to the given given regexp object. Note that if the regexp object is not created from an SRE, it may contain features that cannot be expressed in SRE and cause an error.
[R7RS regex]
{scheme.regex}
Returns the SRE of the given character set. Currently this is not
optimized. If you convert any
to SRE for example, you may get
an SRE listing every single character.
[R7RS regex] {scheme.regex} Returns true iff obj can be safely passed to regexp.
[R7RS regex] {scheme.regex} Returns true iff obj is a regexp.
[R7RS regex]
{scheme.regex}
Returns an <regexpmatch>
object if re successfully matches the
entire string str or optionally from start (inclusive) to
end (exclusive), or #f
is the match fails.
For convenience, end accepts #f
and interprets it as the
end of the string.
The regexpmatch object will contain information needed to extract any submatches.
[R7RS regex]
{scheme.regex}
Similar to regexpmatches
but returns #t
instead of a
<regexpmatch>
object.
[R7RS regex]
{scheme.regex}
Similar to regexpmatches
except that re only has to
match a substring in str instead.
[R7RS regex] {scheme.regex} Calls the procedure kons for every match found in str with following four arguments:
<regexpmatch>
object.
If finish is given, it is called after all matches with the same
parameters as calling kons except that #f
is passed
instead of <regexpmatch>
and the result is returned. Otherwise
the result of the last kons call is returned.
(regexpfold 'word (lambda (i m str acc) (let ((s (regexpmatchsubmatch m 0))) (cond ((assoc s acc) => (lambda (x) (setcdr! x (+ 1 (cdr x))) acc)) (else `((,s . 1) ,@acc))))) '() "to be or not to be") ⇒ '(("not" . 1) ("or" . 1) ("be" . 2) ("to" . 2))
[R7RS regex] {scheme.regex} Returns a list of matched string or an empty list if no matches.
(regexpextract '(+ numeric) "192.168.0.1") ⇒ ("192" "168" "0" "1")
[R7RS regex]
{scheme.regex}
Returns a list of not matched substrings. This can be seen as the
opposite of regexpextract
where the matched strings are
removed instead of returned.
(regexpsplit '(+ space) " fee fi fo\tfum\n") ⇒ ("fee" "fi" "fo" "fum") (regexpsplit '(",;") "a,,b,") ⇒ ("a" "" "b" "") (regexpsplit '(* numeric) "abc123def456ghi789") ⇒ ("abc" "def" "ghi" "")
[R7RS regex]
{scheme.regex}
Returns a list of all matched and not matched substrings. In other
words it’s the combination of regexpextract
and
regexpsplit
where the boundary of matched strings are used to
split the original string.
(regexppartition '(+ (or space punct)) "") ⇒ ("") (regexppartition '(+ (or space punct)) "Hello, world!\n") ⇒ ("Hello" ", " "world" "!\n") (regexppartition '(+ (or space punct)) "¿Dónde Estás?") ⇒ ("" "¿" "Dónde" " " "Estás" "?") (regexppartition '(* numeric) "abc123def456ghi789") ⇒ ("abc" "123" "def" "456" "ghi" "789")
[R7RS regex] {scheme.regex} Returns a new string where the first matched substring is replaced with subst. If count is specified, the countth match will be replaced instead of the first one.
subst can be either a string (the replacement), an integer or a symbol to refer to the capture group that will be used as the replacement, or a list of those.
The special symbols pre
and post
use the substring to
the left or right of the match as replacement, respectively.
subst could also be a procedure, which is called with the given match object and the result will be used as the replacement.
The optional parameters start and end essentially transform the substitution into this
(regexpreplace re (substring str start end) subst)
except that end can take #f
which is the same as
(stringlength str)
.
(regexpreplace '(+ space) "one two three" "_") ⇒ "one_two three" (regexpreplace '(+ space) "one two three" "_" 1 10) ⇒ "ne_two th" (regexpreplace '(+ space) "one two three" "_" 0 #f 0) ⇒ "one_two three" (regexpreplace '(+ space) "one two three" "_" 0 #f 1) ⇒ "one two_three" (regexpreplace '(+ space) "one two three" "_" 0 #f 2) ⇒ "one two three"
Note that Gauche also has a builtin procedure of the same name, but works slightly differently, see Using regular expressions.
[R7RS regex]
{scheme.regex}
Returns a new string where all matches in str are replaced with
subst. subst can also take a string, a number, a symbol or
a procedure similar to regexpreplace
.
(regexpreplaceall '(+ space) "one two three" "_") ⇒ "one_two_three"
Note that Gauche also has a builtin procedure of the same name, but works slightly differently, see Using regular expressions.
[R7RS regex]
{scheme.regex}
Returns true iff obj is a <regexpmatch>
object.
(regexpmatch? (regexpmatches "x" "x")) ⇒ #t (regexpmatch? (regexpmatches "x" "y")) ⇒ #f
[R7RS regex]
{scheme.regex}
Returns the number of matches in match except the implicit zero
full match. This is just an alias of rxmatchnummatches
minus
one.
(regexpmatchcount (regexpmatches "x" "x")) ⇒ 0 (regexpmatchcount (regexpmatches '($ "x") "x")) ⇒ 1
[R7RS regex]
{scheme.regex}
This is an alias of rxmatchsubstring
(regexpmatchsubmatch (regexpsearch 'word "**foo**") 0) ⇒ "foo" (regexpmatchsubmatch (regexpsearch '(: "*" ($ word) "*") "**foo**") 0) ⇒ "*foo*" (regexpmatchsubmatch (regexpsearch '(: "*" ($ word) "*") "**foo**") 1) ⇒ "foo"
[R7RS regex]
{scheme.regex}
This is an alias of regexpmatchsubmatchstart
.
(regexpmatchsubmatchstart (regexpsearch 'word "**foo**") 0) ⇒ 2 (regexpmatchsubmatchstart (regexpsearch '(: "*" ($ word) "*") "**foo**") 0) ⇒ 1 (regexpmatchsubmatchstart (regexpsearch '(: "*" ($ word) "*") "**foo**") 1) ⇒ 2
[R7RS regex]
{scheme.regex}
This is an alias of regexpmatchsubmatchend
.
(regexpmatchsubmatchend (regexpsearch 'word "**foo**") 0) ⇒ 5 (regexpmatchsubmatchend (regexpsearch '(: "*" ($ word) "*") "**foo**") 0) ⇒ 6 (regexpmatchsubmatchend (regexpsearch '(: "*" ($ word) "*") "**foo**") 1) ⇒ 5
[R7RS regex]
{scheme.regex}
This is an alias of rxmatchsubstrings
(regexpmatch>list (regexpsearch '(: ($ word) (+ (or space punct)) ($ word)) "cats & dogs")) ⇒ '("cats & dogs" "cats" "dogs")
Next: scheme.division
 R7RS integer division, Previous: scheme.regex
 R7RS regular expressions, Up: R7RS large [Contents][Index]
scheme.mapping
 R7RS mappingsThis module defines immutable mappings from keys to values.
Originally called srfi.146
and srfi.146.hash
.
The scheme.mapping
module provides mapping objects,
where keys have total order. The scheme.mapping.hash
module
provides hashmap
objects, where keys can be hashed.
Currently, Gauche uses builtin <treemap>
for the mapping object
(see Treemaps),
and builtin <hashtable>
for the hashmap object (see Hashtables).
The actual implementation
may be changed in future versions, so the user must not rely on the
underlying implementations.
The caller must treat mappings and hashmaps as immutable object.
The modules also provide “linear update” APIs, which is allowed
to mutate the mappings passed to the arguments, under assumption
that the argument won’t be used afterwards. The linear update APIs
are marked with !
at the end of the name.
You should always use the returned value of the linear update APIs,
for the side effect isn’t guaranteed.
• Mappings:  
• Hashmaps: 
Next: Hashmaps, Previous: scheme.mapping
 R7RS mappings, Up: scheme.mapping
 R7RS mappings [Contents][Index]
{scheme.mapping}
The class for the mappings.
On Gauche, this is just an alias of <treemap>
.
[R7RS mapping] {scheme.mapping} Creates a new mapping with the given comparator, whose initial content is provided by key value ….
The comparator argument must be a comparator, with comparison/ordering procedure (see Basic comparators).
The key value … arguments must be even length, alternating keys and values.
(define m (mapping defaultcomparator 'a 1 'b 2)) (mappingref m 'a) ⇒ 1 (mappingref m 'b) ⇒ 2
[R7RS mapping] {scheme.mapping} Creates a new mapping, whose content is populated by three procedures, p, f and g, and a seed value seed, as follows.
In each iteration, we have a current seed value, whose initial value is seed.
First, p, a stop predicate, is applied to the current seed value. If it returns true, we stop iteration and returns the new mapping.
Next, f is applied to the current seed value. It must return two values. The first one is for a key and the second one for the value. We add this pair to the mapping.
Then, g is applied to the current seed value. The result becomes the seed value of the next iteration. And we iterate.
The following example creates a mapping that maps ASCII characters to their character codes:
(mappingunfold (cut >= <> 128) (^c (values (integer>char c) c)) (cut + <> 1) 0 defaultcomparator)
[R7RS mapping]
{scheme.mapping}
Similar to mapping
, but keys are given in the ascending order
w.r.t. the comparator. An implementation may use more efficient algorithm
than mapping
. In Gauche, this is the same as mapping
at this moment.
[R7RS mapping]
{scheme.mapping}
Similar to mappingunfold
, but keys are generated in the
ascending order
w.r.t. the comparator. An implementation may use more efficient algorithm
than mappingunfold
.
In Gauche, this is the same as mappingunfold
at this moment.
[R7RS mapping]
{scheme.mapping}
Returns #t
iff obj is a mapping object.
[R7RS mapping]
{scheme.mapping}
M must be a mapping.
Returns #t
if m is empty, #f
otherwise.
In Gauche, this is same as treemapempty?
(see Treemaps).
[R7RS mapping]
{scheme.mapping}
M must be a mapping.
Returns #t
if m has an entry with key,
#f
otherwise.
In Gauche, this is same as treemapexists?
(see Treemaps).
[R7RS mapping]
{scheme.mapping}
Returns #t
iff two mappings m1 and m2 have no keys
in common. In other words, there’s no such key K that
satisfy both (mappingcontains? m1 K)
and
(mappingcontains? m2 K)
.
[R7RS mapping] {scheme.mapping} Get the value from a mapping m associated with key, and calls success on the value, and returns its result. If m doesn’t have key, failure is invoked with no arguments and its result is returned. Both success and failure is called in tail context.
When failure is omitted and key is not found, an error
is signaled. When success is omitted, identity
is
assumed.
[R7RS mapping] {scheme.mapping} Returns the value associated to key from a mapping m. If m doesn’t have key, default is returned.
[R7RS mapping] {scheme.mapping} Returns a comparator used to compare keys in a mapping m. See Basic comparators, for the details of comparators.
Note that the basic premise of mappings srfi is to treat mappings as immutable. Each updating operation comes with a purely functional version (without bang) and a linear update version (with bang), but the linear update version may not require to destructively modiy the passed mapping; it’s merely a hint that it may reuse the argument for the efficiency. You always need to use the returned mapping as the result of update. If you use linear update versions, you shouldn’t use the passed mapping afterwards, for there’s no guarantee how the state of the passed mapping is.
[R7RS mapping]
{scheme.mapping}
The arg … are alternating between key and value. Returns
a mapping that contains all the entries in m plus given
keys and values, with the same comparator as m.
Linear update version mappingadjoin!
may destructively modify
m to create the return value, while mappingadjoin
creates a new mapping.
Arguments are processed in order. If there’s already an entry in m with the same key as given to arg, the original entry remains.
(mappingadjoin (mapping defaultcomparator 'a 1 'b 2) 'c 3 'a 4 'c 5)
⇒ mapping with a → 1, b → 2, c → 3
[R7RS mapping]
{scheme.mapping}
The arg … are alternating between key and value. Returns
a mapping that contains all the entries in m plus given
keys and values, with the same comparator as m.
Linear update version mappingset!
may destructively modify
m to create the return value, while mappingset
creates a new mapping.
Arguments are processed in order. If there’s already an entry in m with the same key as given to arg, the new keyvalue pair supersedes the old one.
(mappingset (mapping defaultcomparator 'a 1 'b 2) 'c 3 'a 4 'c 5)
⇒ mapping with a → 4, b → 2, c → 5
[R7RS mapping] {scheme.mapping} If the mapping m has an entry of key, return a mapping with the value of the entry replaced for value. If m doesn’t have an entry with key, m is returned unchanged.
Linear update version mappingreplace!
may destructively modify
m to produce the return value, while mappingreplace
creates a new mapping.
(mappingreplace (mapping defaultcomparator 'a 1 'b 2) 'a 3) ⇒ mapping with a → 3, b → 2 (mappingreplace (mapping defaultcomparator 'a 1 'b 2) 'c 3) ⇒ mapping with a → 1, b → 2
[R7RS mapping] {scheme.mapping} Returns a mapping that is the same as m except its entries with any of the given key … being removed. Keys that are not in m are ignored.
Linear update version mappingdelete!
may destructively modify
m to produce the return value, while mappingdelete
creates a new mapping.
[R7RS mapping] {scheme.mapping} Returns a mapping that is the same as m except its entries with any of the given keys in keylist being removed. Keys that are not in m are ignored.
Linear update version mappingdeleteall!
may destructively modify
m to produce the return value, while mappingdeleteall
creates a new mapping.
[R7RS mapping] {scheme.mapping} Looks up key in the mapping m, and returns two values, m and the associated value. If m does not contain an entry with key, a thunk makevalue is invoked, and creates a new mapping that contains all entries in m plus a new entry with key and the return value of makevalue, then returns the new mapping and the return value of makevalue.
Linear update version mappingintern!
may destructively modify
m to produce the return value, while mappingintern
creates a new mapping.
(mappingintern (mapping defaultcomparator 'a 1) 'b (^[] 2)) ⇒ mapping with a → 1, b → 2 and 2 (mappingintern (mapping defaultcomparator 'a 1) 'a (^[] 2)) ⇒ mapping with a → 1 and 1
[R7RS mapping] {scheme.mapping} Semantically equivalent to this:
(mappingset m var (updater (mappingref m key failure success)))
The failure and success optional arguments are procedures
with zero and one arguments, respectively. When omitted,
failure defaults to a thunk that raises an error,
and success defaults to identity
.
First, key is looked up in m. If an entry is found, the associated value is passed to success; otherwise, failure is called with no arguments. Either way, let the returned value be v0.
Then, v0 is passed to updater. Let its result be v1.
Finally, a mapping with the same entries as m except the value of key is altered to v1 is returned.
Linear update version mappingupdate!
may destructively modify
m to produce the return value, while mappingupdate
creates a new mapping.
(mappingupdate (mapping defaultcomparator 'a 1) 'a (pa$ + 1)) ⇒ mapping with a → 2 (mappingupdate (mapping defaultcomparator) 'a (pa$ + 1) (^[] 0)) ⇒ mapping with a → 1
[R7RS mapping] {scheme.mapping}
[R7RS mapping] {scheme.mapping}
[R7RS mapping] {scheme.mapping}
[R7RS mapping] {scheme.mapping}
[R7RS mapping] {scheme.mapping}
[R7RS mapping] {scheme.mapping}
[R7RS mapping] {scheme.mapping}
[R7RS mapping] {scheme.mapping}
[R7RS mapping] {scheme.mapping}
[R7RS mapping] {scheme.mapping}
[R7RS mapping] {scheme.mapping}
[R7RS mapping] {scheme.mapping}
[R7RS mapping] {scheme.mapping}
[R7RS mapping] {scheme.mapping}
[R7RS mapping] {scheme.mapping}
[R7RS mapping] {scheme.mapping}
[R7RS mapping] {scheme.mapping}
[R7RS mapping] {scheme.mapping}
[R7RS mapping] {scheme.mapping}
[R7RS mapping] {scheme.mapping}
[R7RS mapping] {scheme.mapping}
[R7RS mapping] {scheme.mapping}
[R7RS mapping] {scheme.mapping}
[R7RS mapping] {scheme.mapping}
[R7RS mapping] {scheme.mapping}
[R7RS mapping] {scheme.mapping}
[R7RS mapping] {scheme.mapping}
[R7RS mapping] {scheme.mapping}
[R7RS mapping] {scheme.mapping}
[R7RS mapping] {scheme.mapping}
[R7RS mapping] {scheme.mapping}
[R7RS mapping] {scheme.mapping}
Previous: Mappings, Up: scheme.mapping
 R7RS mappings [Contents][Index]
[R7RS mapping] {scheme.mapping.hash} Creates a new hashmap with the given comparator, whose initial content is provided by key value ….
The comparator argument must be a comparator (see Basic comparators).
The key value … arguments must be even length, alternating keys and values.
(define m (hashmap defaultcomparator 'a 1 'b 2)) (hashmapref m 'a) ⇒ 1 (hashmapref m 'b) ⇒ 2
[R7RS mapping] {scheme.mapping.hash} Creates a new hashmap, whose content is populated by three procedures, p, f and g, and a seed value seed, as follows.
In each iteration, we have a current seed value, whose initial value is seed.
First, p, a stop predicate, is applied to the current seed value. If it returns true, we stop iteration and returns the new hashmap.
Next, f is applied to the current seed value. It must return two values. The first one is for a key and the second one for the value. We add this pair to the hashmap.
Then, g is applied to the current seed value. The result becomes the seed value of the next iteration. And we iterate.
The following example creates a hashmap that maps ASCII characters to their character codes:
(hashmapunfold (cut >= <> 128) (^c (values (integer>char c) c)) (cut + <> 1) 0 defaultcomparator)
[R7RS mapping]
{scheme.mapping.hash}
Returns #t
iff obj is a hashmap object.
[R7RS mapping]
{scheme.mapping.hash}
M must be a hashmap.
Returns #t
if m is empty, #f
otherwise.
In Gauche, this is same as treemapempty?
(see Treemaps).
[R7RS mapping]
{scheme.mapping.hash}
M must be a hashmap.
Returns #t
if m has an entry with key,
#f
otherwise.
In Gauche, this is same as treemapexists?
(see Treemaps).
[R7RS mapping]
{scheme.mapping.hash}
Returns #t
iff two hashmaps m1 and m2 have no keys
in common. In other words, there’s no such key K that
satisfy both (hashmapcontains? m1 K)
and
(hashmapcontains? m2 K)
.
[R7RS mapping] {scheme.mapping.hash} Get the value from a hashmap m associated with key, and calls success on the value, and returns its result. If m doesn’t have key, failure is invoked with no arguments and its result is returned. Both success and failure is called in tail context.
When failure is omitted and key is not found, an error
is signaled. When success is omitted, identity
is
assumed.
[R7RS mapping] {scheme.mapping.hash} Returns the value associated to key from a hashmap m. If m doesn’t have key, default is returned.
[R7RS mapping] {scheme.mapping.hash} Returns a comparator used to compare keys in a hashmap m. See Basic comparators, for the details of comparators.
Note that the basic premise of hashmaps srfi is to treat hashmaps as immutable. Each updating operation comes with a purely functional version (without bang) and a linear update version (with bang), but the linear update version may not require to destructively modiy the passed hashmap; it’s merely a hint that it may reuse the argument for the efficiency. You always need to use the returned hashmap as the result of update. If you use linear update versions, you shouldn’t use the passed hashmap afterwards, for there’s no guarantee how the state of the passed hashmap is.
[R7RS mapping] {scheme.mapping.hash}
[R7RS mapping] {scheme.mapping.hash}
[R7RS mapping] {scheme.mapping.hash}
[R7RS mapping] {scheme.mapping.hash}
[R7RS mapping] {scheme.mapping.hash}
[R7RS mapping] {scheme.mapping.hash}
[R7RS mapping] {scheme.mapping.hash}
[R7RS mapping] {scheme.mapping.hash}
[R7RS mapping] {scheme.mapping.hash}
[R7RS mapping] {scheme.mapping.hash}
[R7RS mapping] {scheme.mapping.hash}
[R7RS mapping] {scheme.mapping.hash}
[R7RS mapping] {scheme.mapping.hash}
[R7RS mapping] {scheme.mapping.hash}
[R7RS mapping] {scheme.mapping.hash}
[R7RS mapping] {scheme.mapping.hash}
[R7RS mapping] {scheme.mapping.hash}
[R7RS mapping] {scheme.mapping.hash}
[R7RS mapping] {scheme.mapping.hash}
[R7RS mapping] {scheme.mapping.hash}
[R7RS mapping] {scheme.mapping.hash}
[R7RS mapping] {scheme.mapping.hash}
[R7RS mapping] {scheme.mapping.hash}
[R7RS mapping] {scheme.mapping.hash}
[R7RS mapping] {scheme.mapping.hash}
[R7RS mapping] {scheme.mapping.hash}
[R7RS mapping] {scheme.mapping.hash}
[R7RS mapping] {scheme.mapping.hash}
[R7RS mapping] {scheme.mapping.hash}
[R7RS mapping] {scheme.mapping.hash}
[R7RS mapping] {scheme.mapping.hash}
[R7RS mapping] {scheme.mapping.hash}
[R7RS mapping] {scheme.mapping.hash}
[R7RS mapping] {scheme.mapping.hash}
Next: scheme.bitwise
 R7RS bitwise operations, Previous: scheme.mapping
 R7RS mappings, Up: R7RS large [Contents][Index]
scheme.division
 R7RS integer divisionThis module provides a comprehensive set of integer division operators.
Quotient and remainder in integer divisions can be defined in multiple
ways, when you consider the choice of sign of the result with regard to
the operands. Gauche has builtin procedures in several flavors:
R5RS quotient
, remainder
and modulo
,
R6RS div
, mod
, div0
and mod0
,
and R7RS floorquotient
, floorremainder
, floor/
,
truncatequotient
, truncateremainder
, truncate/
.
This module complements R7RS procedures, by adding ceiling
,
round
, euclidean
and balanced
variants.
The following procedures are in scheme.division but builtin in Gauche (see Arithmetics).
floorquotient floorremainder floor/ truncatequotient truncateremainder truncate/
[R7RS division] {scheme.division}
ceilingquotient = ceiling(n / d) ceilingremainder = n  d * ceilingquotient ceiling/ = values(ceilingquotient, ceilingremainder)
[R7RS division] {scheme.division}
roundquotient = round(n/d) roundremainder = n  d * roundquotient round/ = values(roundquotient, roundremainder)
[R7RS division] {scheme.division}
euclideanquotient = floor(n / d) if d > 0 ceiling(n / d) if d < 0 euclideanremainder = n  d * euclideanquotient euclidean/ = values(euclideanquotient, euclideanremainder)
The Eclidean variant satisfies a property 0 <= remainder < abs(d)
.
These are the same as R6RS’s div
, mod
, and divandmod
,
except that they accept nonintegers (see Arithmetics)
[R7RS division] {scheme.division}
balancedquotient = roundup(n / d) balancedremainder = n  d * balancedquotient balanced/ = values(balancedquotient, balancedremainder) where roundup(x) rounds towards zero if x  floor(x) < 0.5, and away from zero if x  floor(x) >= 0.5,
The balanced variant satisfies a property
abs(d/2) <= remainder < abs(d/2)
.
These are the same as R6RS’s div0
, mod0
, and
div0andmod0
, except that they accept nonintegers
(see Arithmetics).
Next: scheme.fixnum
 R7RS fixnums, Previous: scheme.division
 R7RS integer division, Up: R7RS large [Contents][Index]
scheme.bitwise
 R7RS bitwise operationsThis module provides comprehensive bitwise operations.
Originally it was SRFI151.
It is mostly a superset of SRFI60, with some change of names for the consistency
and the compatibility (see srfi.60
 Integers as bits). We keep SRFI60 for
legacy code, while recommend this module to be used in the new code.
The following procedures are Gauche builtin. See Basic bitwise operations, for the description.
integerlength copybit bitfield
[R7RS bitwise]
{scheme.bitwise}
Returns the bitwise complement of n.
Same as builtin lognot
(see Basic bitwise operations).
[R7RS bitwise]
{scheme.bitwise}
When no arguments are given, these procedures returns 1
, 0
,
0
and 1
, respectively. With one arguments, they return the
argument as is. With two arguments, they return bitwise and, ior, xor,
and eqv (complement of xor). With three or more arguments, they apply
binary operations associaively, that is,
(bitwisexor a b c) ≡ (bitwisexor a (bitwisexor b c)) ≡ (bitwisexor (bitwisexor a b) c)
Be careful that multiargument bitwiseeqv
does not produce
bit 1 everywhere that all the argument’s bit agree.
The first three procedures are the same as builtin
logand
, logior
and logxor
, respectively
(see Basic bitwise operations).
[R7RS bitwise] {scheme.bitwise} These operations are not associative.
nand n0 n1 ≡ (NOT (AND n0 n1)) nor n0 n1 ≡ (NOT (OR n0 n1)) andc1 n0 n1 ≡ (AND (NOT n0) n1) andc2 n0 n1 ≡ (AND n0 (NOT n1)) orc1 n0 n1 ≡ (OR (NOT n0) n1) orc2 n0 n1 ≡ (OR n0 (NOT n1))
[R7RS bitwise] {scheme.bitwise} Shift n for count bits to left; if count is negative, it shifts n to right for count bits.
Same as builtin ash
(see Basic bitwise operations).
[R7RS bitwise]
{scheme.bitwise}
If n is positive, returns the number of 1
’s in n.
If n is negative, returns the number of 0
’s in n.
Same as builtin logcount
(see Basic bitwise operations).
[R7RS bitwise] {scheme.bitwise} Returns integer, whose nth bit is taken as follows: If the nth bit of mask is 1, the nth bit of n0; otherwise, the nth bit of n1.
(bitwiseif #b10101100 #b00110101 #b11001010) ⇒ #b01100110
[R7RS bitwise]
{scheme.bitwise}
Returns #t
or #f
if indexth bit (counted from LSB)
of n is 1
or 0
, respectively.
Same as builtin logbit?
(see Basic bitwise operations).
[R7RS bitwise] {scheme.bitwise} Returns an integer with index1th bit and index2th bit are swapped. Index is counted from LSB.
[R7RS bitwise]
{scheme.bitwise}
Returns #t
iff any/all bits set in mask are also set in n.
anybitset?
is the same as builtin logtest
,
except logtest
accepts one or more arguments
(see Basic bitwise operations).
[R7RS bitwise]
{scheme.bitwise}
Returns the number of factors of two of integer n; that is,
returns a maximum k
such that (expt 2 k)
divides
n without a remainder.
It is the same as the index of the least significant 1
in n,
hence the alias firstsetbit
.
(firstsetbit 0) ⇒ 1 ; edge case
(firstsetbit 1) ⇒ 0
(firstsetbit 2) ⇒ 1
(firstsetbit 15) ⇒ 0
(firstsetbit 16) ⇒ 4
This is equivalent to Gauche’s builtin twosexponentfactor
(see Basic bitwise operations).
[R7RS bitwise]
{scheme.bitwise}
Returns #t
iff any/all bits of n from start (inclusive)
to end (exclusive) are set.
[R7RS bitwise]
{scheme.bitwise}
Returns n with the bits from start (inclusive)
to end (exclusive) are set to all 0
’s/1
’s.
[R7RS bitwise] {scheme.bitwise} Returns dst with the bitfield from start to end are replaced with the leastsignificant (endstart) bits of src.
(bitfieldreplace #b101010 #b010 1 4) ⇒ #b100100
Same as builtin copybitfield
(see Basic bitwise operations).
[R7RS bitwise]
{scheme.bitwise}
Returns dst with the bitfield from start to end
are replaced with the src
’s bitfield from start to end.
(bitfieldreplacesame #b111111 #b100100 1 4) ⇒ #b110101
[R7RS bitwise] {scheme.bitwise} Rotate the region of n between startth bit (inclusive) and endth bit (exclusive) by count bits to the left. If count is negative, it rotates to the right by count bits.
(bitfieldrotate #b110100100010000 1 5 9) ⇒ 26768 ;#b110100010010000 (bitfieldrotate #b110100100010000 1 5 9) ⇒ 26672 ;#b110100000110000
[R7RS bitwise] {scheme.bitwise} Reverse the order of bits of n between startth bit (inclusive) and endth bit (exclusive).
(bitfieldreverse #b10100111 0 8) ⇒ 229 ; #b11100101
[R7RS bitwise]
{scheme.bitwise}
Returns a list/vector of booleans of length len,
corresponding to each bit in nonnegative integer n, LSBfirst.
When len is omitted, (integerlength n)
is used.
(bits>vector #b101101110) ⇒ #(#f #t #t #t #f #t #t #f #t)
Note: SRFI60 has a similar integer>list
, but the order of
bits is reversed.
[R7RS bitwise] {scheme.bitwise} Returns an exact integer formed from boolean values in given list/vector, LSB first. The result will never be negative.
(list>bits '(#f #t #t #t #f #t #t #f #t)) ⇒ #b101101110
Note: SRFI60 has a similar list>integer
, but the order of
bits is reversed.
[R7RS bitwise] {scheme.bitwise} Returns the integer coded by bools, LSB first. The result will never be negative.
(bits #f #t #t #t #f #t #t #f #t) ⇒ #b101101110
Note: SRFI60 has a similar booleans>integer
, but the order of
bits is reversed.
[R7RS bitwise]
{scheme.bitwise}
Traverse bits in integer n from LSB to the (integerlength n)
bit,
applying kons
on the bit as boolean
and the seed value, whose initial value
is given by knil. Returns the last result of kons.
(bitwisefold cons '() #b10110111) ⇒ (#t #f #t #t #f #t #t #t)
[R7RS bitwise]
{scheme.bitwise}
Applies proc to the bit as boolean in n, from LSB to
the (integerlength n)
bit. The result is discarded.
[R7RS bitwise]
{scheme.bitwise}
Generates a nonnegative integer bit by bit, from LSB to MSB.
The seed gives the initial state value.
For each iteration, p is applied to the current state value,
and if it returns a true value, the iteration ends and bitwiseunfold
returns the accumulated bits as an integer.
Otherwise, f is applied to the current state value, and
its result, coerced to a boolean value, determines the bit value.
Then g is applied to the current state value to produce
the next state value of the next iteration.
The following expression produces a bitfield of width 100, where nth bit indicates whether n is prime or not:
(use math.prime) (bitwiseunfold (cut = 100 <>) smallprime? (cut + 1 <>) 0)
[R7RS bitwise] {scheme.bitwise} Returns a generator that generates boolean values corresponding to the bits in n, LSBfirst. The returned generator is infinite.
This is similar to bits>generator
in gauche.generator
,
except that the generator created by it stops at the integer
length of n (see gauche.generator
 Generators).
Next: scheme.flonum
 R7RS flonum, Previous: scheme.bitwise
 R7RS bitwise operations, Up: R7RS large [Contents][Index]
scheme.fixnum
 R7RS fixnumsThis module provides a set of fixnumspecific operations. Originally defined as SRFI143.
A fixnum is a small exact integer that can be handled very efficiently. In Gauche, fixnum is 62bit wide on 64bit platforms, and 30bit wide on 32bit platforms.
Note that these procedures are defined only to work on fixnums, but it is not enforced. If you pass nonfixnum arguments, or the result falls out of range of fixnums, what happens is up to the implementation. Consider these procedures as the way to tell your intentions to the compiler for potential optimizations.
In the current Gauche architecture, generic numeric operators are just as efficient, so most procedures provided in this module are aliases to corresponding operators. However, we might employ some optimizations in future versions.
The procedure fixnum?
is builtin, and
not explained here. See Numerical predicates.
[R7RS fixnum]
{scheme.fixnum}
A variable bound to an exact positive integer w, where w
is the greatest number such that exact integers between
2^(w1)  1
and 2^(w1)
are all fixnums.
This value is the same as the builtin procedure fixnumwidth
returns (see Arithmetics).
In Gauche, it is usually 30
for 32bit platforms, and 62
for
64bit platforms.
[R7RS fixnum]
{scheme.fixnum}
Variables bound to the greatest fixnum and the least fixnum.
They are the same as the builtin procedures
greatestfixnum
and leastfixnum
return, respectively
(see Arithmetics).
The following table shows the typical values on Gauche:
Platform  fxgreatest  fxleast 

32bit  536,870,911  536,870,912 
64bit  2,305,843,009,213,693,951  2,305,843,009,213,693,952 
[R7RS fixnum]
{scheme.fixnum}
These are equivalent to builtin =
, <
, <=
,
>
and >=
, except that you should use these only for fixnums.
[R7RS fixnum]
{scheme.fixnum}
These are equivalent to builtin zero?
, positive?
,
negative?
, odd?
and even?
,
except that you should use these only for fixnums.
[R7RS fixnum]
{scheme.fixnum}
These are equivalent to builtin max
and min
,
except that you should use these only for fixnums.
[R7RS fixnum]
{scheme.fixnum}
These are equivalent to builtin +
, 
and *
,
except that these take exactly two arguments, and
you should use these only for fixnums and
when the result fits within fixnum range.
[R7RS fixnum]
{scheme.fixnum}
This is equivalent to singleargument 
,
except that you should use this only for fixnums and
when the result fits within fixnum range.
[R7RS fixnum]
{scheme.fixnum}
These are equivalent to builtin quotient
, remainder
,
abs
and square
,
except that you should use these only for fixnums and
when the result fits within fixnum range.
[R7RS fixnum]
{scheme.fixnum}
This is equivalent to exactintegersqrt
(not sqrt
),
except that you should use it only for fixnums.
See Arithmetics.
[R7RS fixnum]
{scheme.fixnum}
These calculates (+ i j k)
, ( i j k)
and (+ (* i j) k)
,
respectively, then split the result to the remainder value R
in the fixnum range, and spilled value Q
, and return those values.
That is,
(+ (* Q (expt 2 fxwidth)) R)
is the result of above calculations.
Both Q
and R
fits in the fixnum range, and
 2^(w1) <= R < 2^(w1)
, where w
is fxwidth
.
(fx*/carry 1845917459 19475917581 4735374)
⇒ 942551854601421179 and 8
(+ (* 8 (expt 2 fxwidth)) 942551854601421179)
⇒ 35950936292817682053
(+ (* 1845917459 19475917581) 4735374)
⇒ 35950936292817682053
These are primitives to implement extendedprecision integer arithmetic on top of fixnum operations. In Gauche, however, you can just use builtin bignums. We provide these for the compatibility.
[R7RS fixnum]
{scheme.fixnum}
These are equivalent to lognot
, logand
,
logior
, logxor
, ash
, integerlength
,
logcount
,
copybit
, logbit?
, bitfield
,
and twosexponentfactor
respectively,
except that you should use these only for fixnums.
See Basic bitwise operations.
[R7RS fixnum]
{scheme.fixnum}
These are equivalent to SRFI60’s
bitwiseif
, rotatebitfield
and
reversebitfield
,
except that you should use these only for fixnums.
See srfi.60
 Integers as bits.
Next: scheme.bytevector
 R7RS bytevectors, Previous: scheme.fixnum
 R7RS fixnums, Up: R7RS large [Contents][Index]
scheme.flonum
 R7RS flonumThis module provides a set of flonumspecific operations. Originally defined as SRFI144.
In Gauche, a flonum is IEEE 754 doubleprecision floating point numbers.
Note that these procedures are defined only to work on flonums, but it is not enforced. If you pass nonflonum arguments, the result is undefined. Consider these procedures as the way to tell your intentions to the compiler for potential optimizations.
In the current Gauche architecture, generic numeric operators are just as efficient, so most procedures provided in this module are aliases to corresponding operators. However, we might employ some optimizations in future versions.
The procedure flonum?
is builtin, and
not explained here. See Numerical predicates.
We also have a few constants in math.const
module
(see math.const
 Mathematical constants).
[R7RS flonum] {scheme.flonum} The base of natural logarithm e.
Gauche also has a constant e
in math.const
(see math.const
 Mathematical constants).
[R7RS flonum]
{scheme.flonum}
(/ e)
.
[R7RS flonum]
{scheme.flonum}
(square e)
.
[R7RS flonum]
{scheme.flonum}
(expt e (/ pi 4))
.
[R7RS flonum]
{scheme.flonum}
(log2 e)
. (Same as (/ (log 2))
).
[R7RS flonum]
{scheme.flonum}
(log10 e)
. (Same as (/ (log 10))
).
[R7RS flonum]
{scheme.flonum}
(log 2)
.
[R7RS flonum]
{scheme.flonum}
(/ (log 2))
. (Same as (log2 e)
).
[R7RS flonum]
{scheme.flonum}
(log 3)
.
[R7RS flonum]
{scheme.flonum}
(log pi)
.
[R7RS flonum]
{scheme.flonum}
(log 10)
.
[R7RS flonum]
{scheme.flonum}
(/ (log 10))
. (Same as (log10 e)
).
[R7RS flonum]
{scheme.flonum}
pi
.
[R7RS flonum]
{scheme.flonum}
(/ pi)
.
[R7RS flonum]
{scheme.flonum}
(* 2 pi)
.
[R7RS flonum]
{scheme.flonum}
(/ pi 2)
.
[R7RS flonum]
{scheme.flonum}
(/ pi 4)
.
[R7RS flonum]
{scheme.flonum}
(square pi)
.
[R7RS flonum]
{scheme.flonum}
(/ pi 180)
.
[R7RS flonum]
{scheme.flonum}
(/ 2 pi)
.
[R7RS flonum]
{scheme.flonum}
(/ 2 (sqrt pi))
.
(sqrt 2)
.
[R7RS flonum]
{scheme.flonum}
(sqrt 3)
.
[R7RS flonum]
{scheme.flonum}
(sqrt 5)
.
[R7RS flonum]
{scheme.flonum}
(sqrt 10)
.
[R7RS flonum]
{scheme.flonum}
(/ (sqrt 2))
.
[R7RS flonum]
{scheme.flonum}
(expt 2 1/3)
.
[R7RS flonum]
{scheme.flonum}
(expt 3 1/3)
.
[R7RS flonum]
{scheme.flonum}
(expt 2 1/4)
.
[R7RS flonum]
{scheme.flonum}
(/ (+ 1 (sqrt 5)) 2)
.
[R7RS flonum]
{scheme.flonum}
(log flphi)
.
[R7RS flonum]
{scheme.flonum}
(/ (log flphi))
.
[R7RS flonum] {scheme.flonum} Euler’s constant.
[R7RS flonum]
{scheme.flonum}
(exp fleuler)
[R7RS flonum]
{scheme.flonum}
(sin 1)
[R7RS flonum]
{scheme.flonum}
(cos 1)
[R7RS flonum]
{scheme.flonum}
(gamma 1/2)
[R7RS flonum]
{scheme.flonum}
(gamma 1/3)
[R7RS flonum]
{scheme.flonum}
(gamma 2/3)
[R7RS flonum]
{scheme.flonum}
(gamma 1/3)
[R7RS flonum] {scheme.flonum} Bound to the largest/smallest positive finite flonum.
The latter is the same value as retured from
(flonummindenormalized)
in Gauche
(see Numerical comparison).
[R7RS flonum]
{scheme.flonum}
The same as (flonumepsilon)
in Gauche
(see Numerical comparison).
[R7RS flonum]
{scheme.flonum}
If this is #t
, (fl+* x y z)
executes as fast as,
or faster than, (fl+ (fl* x y) z)
. If not, #f
.
[R7RS flonum]
{scheme.flonum}
These are exact integer values returned in special occasion
from flintegerexponent
. The values themselves don’t mean
much; they’re to be compared with the result of flintegerexponent
.
If its argument is 0, flintegerexponent
returns
flintegerexponentzero
. If its argument is +nan.0
,
flintegerexponent
returns flintegerexponentnan
.
[R7RS flonum] {scheme.flonum} Returns a flonum that’s equal to or (if there’s no equivalent flnoum) the closest to number.
If number is not a real number,
+nan.0
is returned. (Note: SRFI144 recommends it, but
a conformant implementation may signal an error in such case.
Portable code shouldn’t rely on this behavior.)
[R7RS flonum] {scheme.flonum} Returns a flonum adjacent to x in the direction of y. If x = y, x is returned.
(fladjacent 1.0 2.0) ⇒ 1.0000000000000002 (fladjacent 1.0 0.0) ⇒ 0.9999999999999999
[R7RS flonum]
{scheme.flonum}
Returns a flonum whose absolute value is (abs x)
and whose
sign is the sign of y.
[R7RS flonum]
{scheme.flonum}
Returns a flonum (* x (expt 2 n))
. It is the same
as ldexp
(see Numerical conversions).
[R7RS flonum]
{scheme.flonum}
Returns two flnoums, the integral part of x and the fractional
part of x. Same as modf
(see Numerical conversions).
If x is +inf.0
, +inf.0
and 0.0
is returned.
If x is inf.0
, inf.0
and 0.0
is returned.
If x is +nan.0
, +nan.0
and +nan.0
is returned.
(These corner cases are not explicit in SRFI144, but follows
the POSIX specification of modf
.)
(flintegerfraction flpi)
⇒ 3.0 and 0.14159265358979312
[R7RS flonum] {scheme.flonum} Returns the exponent part of x as a flnoum. If x is a nonzero finite value, the result is an integer.
If x is zero, inf.0
is returned.
If x is +inf.0 or inf.0
, +inf.0
is returned.
(flexponent 1.0) ⇒ 0.0 (flexponent 1024.0) ⇒ 10.0 (flexponent 0.01) ⇒ 7.0 (flexponent flleast) ⇒ 1074.0
[R7RS flonum]
{scheme.flonum}
Returns the same as flexponent
but as an exact integer.
If x is zero, the value of flintegerexponentzero
is
returned.
If x is +inf.0 or inf.0
, a large
implementationdependent exact integer (usually it’s so large that
(ldexp 1 (flintegerexponent +inf.0))
becomes +inf.0
)
is returned.
If x is +nan.0
, the value of
flintegerexponentnan
is returned.
[R7RS flonum]
{scheme.flonum}
Returns two values, a normalized mantissa of x with the same sign
as x as a flonum, and an exact integer exponent of x. If it returns
a value y and n, x = (* y (expt 2 n))
and
x = (ldexp y n)
.
This is the same as frexp
(see Numerical conversions).
If x is nonzero finite value, the first value
falls between 0.5 (inclusive) and 1.0 (exclusive).
The corner cases are not explicit in SRFI144, but Gauche follows
frexp
: If x is (minus) zero, it returns
(minus) zero and 0; if x is infinity, it returns
infinity (of the same sign) and 0; if x is +nan.0
,
it returns +nan.0
and 0.
(flnormalizedfractionexponent 12345.6789)
⇒ 0.7535204406738282 and 14
(makeflonum 0.7535204406738282 14)
⇒ 12345.6789
[R7RS flonum]
{scheme.flonum}
Returns 0 if x is positive or 0.0,
and 1 if it is negative (including 0.0
).
(flsignbit +nan.0)
is implementationdependent.
There’s also flsgn
, if you need sign instead of a bit value.
(Note: flonum?
is builtin; see Numerical predicates).
[R7RS flonum]
{scheme.flonum}
Flonum specific version of numerical comparison predicates
=
, <
, >
, <=
and >=
, respectively.
Currently these are just an alias of the generic numerical comparison predicates; hence they don’t reject when you pass nonflonum arguments, but doing so is not portable. These are to give compilers hints that you are passing flonums so that it can optimize.
Note that 0.0
and 0.0
are the same in terms of
these predicates, e.g. (fl<? 0.0 0.0)
is #f
.
If a +nan.0
is passed to any of the arguments, these predicates returns
#f
.
[R7RS flonum]
{scheme.flonum}
Returns #t
iff at least one of x or y is
a +nan.0
.
[R7RS flonum]
{scheme.flonum}
Returns #t
if x is an integral flonum,
#f
otherwise.
[R7RS flonum]
{scheme.flonum}
Flonumspecific version of zero?
, positive?
and negative?
.
Note that (flnegative? 0.0)
is #f
.
You need flsignbit
or flsgn
to
distinguish negative zero from zero.
[R7RS flonum]
{scheme.flonum}
Flonumspecific version of odd?
and even?
. An error is thrown
if x is not an integer.
[R7RS flonum]
{scheme.flonum}
Flonumspecific version of finite?
, infinite?
and
nan?
(see Numerical predicates).
[R7RS flonum]
{scheme.flonum}
Returns #t
iff x is a normalized/denormalized flonum,
respectively.
[R7RS flonum]
{scheme.flonum}
Flonumspecific version of min
and max
, except that
these can take no arguments, in which case inf.0
and +inf.0
are returned, respectively.
Note that we don’t check whether the arguments are flonums or not, but passing nonflonums are not portable.
[R7RS flonum]
{scheme.flonum}
Flonumspecific version of +.
and *.
(see Arithmetics).
Note that we don’t check whether the arguments are flonums or not, but passing nonflonums is not portable.
[R7RS flonum]
{scheme.flonum}
Returns (+ (* x y) z)
, but (potentially) faster, and more accurately.
It calls C99 fma
function internally. “More accurately” means
that calculation is done in a single step, with rounding once at the end.
Note: As of release of 0.9.8, MinGW implementation of fma
seems
to produce slightly off value occasionally, as if it is calculated
with the two steps (rounding after multiplication).
[R7RS flonum]
{scheme.flonum}
Flonumspecific version of .
and /.
(see Arithmetics).
Note that we don’t check whether the arguments are flonums or not, but passing nonflonums is not portable.
[R7RS flonum]
{scheme.flonum}
Flonumspecific version of abs
(see Arithmetics).
Note that we don’t check whether the argument is a flonum or not, but passing nonflonum is not portable.
[R7RS flonum]
{scheme.flonum}
Returns (abs ( x y))
.
Note that we don’t check whether the arguments are flonums or not, but passing nonflonum is not portable.
[R7RS flonum]
{scheme.flonum}
Returns (max ( x y) 0)
.
Note that we don’t check whether the arguments are flonums or not, but passing nonflonum is not portable.
[R7RS flonum]
{scheme.flonum}
Returns 1.0
if x’s sign bit is 0 (zero or positive),
1.0
if it’s 1 (negative). Same as (flcopysign 1.0 x)
,
or (if (zero? (flsignbit x)) 1.0 1.0)
.
Note that (flsgn 0.0)
is 1.0
, while
(flsgn 0.0)
is 1.0
. The result of
passing +nan.0
is implementationdependent, reflecting
the sign bit of underlying representation; it returns either 1.0
or
1.0
but you can’t count on which.
To extract the sign bit, instead of obtaining a signed flonum,
you can use flsignbit
.
[R7RS flonum]
{scheme.flonum}
Flonumspecific version of numerator
and denominator
(see Arithmetics).
For infinity and zero, denominator is 1.0.
Note that we don’t check whether the arguments are flonums or not, but passing nonflonum is not portable.
[R7RS flonum]
{scheme.flonum}
Flonumspecific version of floor
, ceiling
,
round
and truncate
(see Arithmetics).
Note that we don’t check whether the arguments are flonums or not, but passing nonflonum is not portable.
[R7RS flonum]
{scheme.flonum}
Flonumspecific version of exp
(see Arithmetics).
Returns (expt fle x)
.
[R7RS flonum]
{scheme.flonum}
Returns (expt 2 x)
[R7RS flonum]
{scheme.flonum}
Returns ( 1 (expt fle x))
, but is much more accurate
when x is small. We call C’s expm1
internally.
[R7RS flonum]
{scheme.flonum}
Returns (*. x x)
[R7RS flonum]
{scheme.flonum}
Flonumspecific version of sqrt
.
[R7RS flonum] {scheme.flonum} Returns cubic root of a flonum x.
[R7RS flonum]
{scheme.flonum}
Calculates (sqrt (* x x) (* y y))
, with avoiding
overflow or underflow during the intermediate steps.
[R7RS flonum]
{scheme.flonum}
Flonumspecific version of expt
(see Arithmetics).
[R7RS flonum]
{scheme.flonum}
Flonumspecific version of log
(see Arithmetics).
[R7RS flonum]
{scheme.flonum}
Returns (log (+ x 1))
, but is more accurate than log
when x is near zero.
[R7RS flonum] {scheme.flonum} Returns base2 and base10 logarithm of a flonum x, respectively.
[R7RS flonum] {scheme.flonum} Returns a procedure that calculates basex logarithm. An error is signalled if x isn’t a real number greater than 1.0.
(define log5 (makefllogbase 5.0)) (log5 25.0) ⇒ 5.0
[R7RS flonum]
{scheme.flonum}
Flonumspecific version of sin
, cos
, tan
,
asin
, acos
, sinh
, cosh
, tanh
,
asinh
, acosh
, and atanh
, respectively
(see Arithmetics).
Note that flatan
can take one or two arguments; if two arguments
are passed, it calculates (atan (/ y x)
.
[R7RS flonum]
{scheme.flonum}
Returns (fltruncate (fl/ x y))
.
The result is always integer flonum, but x and y doesn’t need to be integers.
(flquotient 14.0 4.0) ⇒ 3.0 (flquotient 14.0 4.0) ⇒ 3.0 (flquotient 14.0 2.5) ⇒ 5.0 (flquotient 14.2 2.8) ⇒ 5.0
[R7RS flonum]
{scheme.flonum}
Returns ( x (* y (flquotient x y)))
.
(flquotient 14.0 4.0) ⇒ 2.0 (flquotient 14.0 4.0) ⇒ 2.0 (flquotient 14.0 2.5) ⇒ 1.5 (flquotient 14.2 2.8) ⇒ 0.1999999999999993 ; inexact calculation
[R7RS flonum] {scheme.flonum} Returns two values:
(flremainder x y)
, but we calculate it in different
routines so the result may differ in a few ulp.
This corresponds to C99’s remquo
.
This function is useful to reduce the input for the periodic functions with symmetries.
[R7RS flonum] {scheme.flonum} Computes the value of gamma function for a flonum x. When x is integer, it is the same as the factorial of x1.
This is same as Gauche’s builtin gamma
(see Arithmetics).
[R7RS flonum]
{scheme.flonum}
Returns two values, (log (abs (flgamma x)))
and the sign of
(flgamma x)
as 1.0 if it is positive and 1.0 if it is negative.
The first value is calculated by Gauche’s builtin lgamma
(see Arithmetics). It’s more accurate than using gamma
then
calling log
. The second value is +nan.0
when
x is inf.0
or +nan.0
.
[R7RS flonum] {scheme.flonum} Returns the nth order Bessel function of the first kind.
[R7RS flonum] {scheme.flonum} Returns the nth order Bessel function of the second kind.
[R7RS flonum] {scheme.flonum} Returns the error function erf(x).
[R7RS flonum] {scheme.flonum} Returns the complementary error function, 1  erf(x).
Next: scheme.show
 R7RS combinator formatting, Previous: scheme.flonum
 R7RS flonum, Up: R7RS large [Contents][Index]
scheme.bytevector
 R7RS bytevectorsThis module is taken from R6RS ((rnrs bytevectors)
(note
that R7RS uses singular form).
The bytevector in this module is u8vector in Gauche.
The following procedures are the same as in gauche.uvector
.
See Bytevector compatibility, for the explanations.
bytevector? makebytevector bytevectorlength bytevector=? bytevectorfill! bytevectorcopy bytevectoru8ref bytevectoru8set! bytevectors8ref bytevectors8set! bytevector>u8list u8list>bytevector
The following procedures are the same as in gauche.unicode
.
See gauche.unicode
 Unicode utilities, for the explanations.
string>utf8 string>utf16 string>utf32 utf8>string utf16>string utf32>string
This module exports bytevectorcopy!
, which takes arguments
in different order from
R7RS base’s (and gauche.uvector
’s) bytevectorcopy!
.
It is the same as bytevectorcopy!r6
in gauche.uvector
(see Bytevector compatibility).
[R7RS bytevector] If symbol is a valid endianness symbol, returns it. Otherwise, raise an error at macroexpansion time. Useful to catch an error early, and explicitly indicates you mean endianness.
Valid symbols are listed in Endianness. Only big
and
little
are portable.
[R7RS bytevector]
Returns a symbol representing the native endianness.
Same as Gauche’s builtin nativeendian
(see Endianness).
[R7RS bytevector]
Read size octets from u8vector bv, starting from posth
octet, as an unsigned or signed integer, respectively.
Similar to binary.io
’s getuint
and getsint
,
with different argument order.
They accept all valid endianness symbols in Gauche, but
the portable code should only use big
and little
for
endian argument.
[R7RS bytevector]
Store an unsigned or signed integer val into an u8vector
bv starting from posth octet, for size octets,
respectively.
Similar to binary.io
’s putuint!
and putsint!
,
with different argument order.
They accept all valid endianness symbols in Gauche, but
the portable code should only use big
and little for
endian argument.
[R7RS bytevector] Convert the u8vector bv to a list of unsigned or signed integer, each of which is represented by sizeoctets. The length of bv must be a multiple of size; otherwise an error is signaled.
They accept all valid endianness symbols in Gauche, but
the portable code should only use big
and little for
endian argument.
[R7RS bytevector]
Lis must be a list of unsigned or signed integers, respectively.
Creates a u8vector of length (* size (length lis))
, and
stores each integer into the u8vector using size octets,
and returns the u8vector.
They accept all valid endianness symbols in Gauche, but
the portable code should only use big
and little for
endian argument.
[R7RS bytevector]
Retrieve a numerical value from a u8vector bv starting at
index k, using endian. These are the same as
getu16
, … in binary.io
, except that
all arguments are mandatory. (Note that
ieeesingle
and ieeedouble
corresponds to f32
and
f64
)). See binary.io
 Binary I/O, for the details.
They accept all valid endianness symbols in Gauche, but
the portable code should only use big
and little for
endian argument.
[R7RS bytevector]
Like bytevectoru16ref
etc., but uses native endianness.
[R7RS bytevector]
Store a numerical value into a u8vector bv starting at
index k, using endian. These are the same as
putu16!
, … in binary.io
, except that
all arguments are mandatory. (Note that
ieeesingle
and ieeedouble
corresponds to f32
and
f64
). See binary.io
 Binary I/O), for the details.
They accept all valid endianness symbols in Gauche, but
the portable code should only use big
and little for
endian argument.
[R7RS bytevector]
Like bytevectoru16set!
etc., but uses native endianness.
Previous: scheme.bytevector
 R7RS bytevectors, Up: R7RS large [Contents][Index]
scheme.show
 R7RS combinator formattingExports bindings of R7RS (scheme show)
library.
From R7RS programs, those bindings are available by
(import (scheme show))
.
scheme.show is a combination of submodules scheme.show.base, scheme.show.color, scheme.show.columnar and scheme.show.unicode.
Exports bindings of R7RS (scheme show base)
library.
From R7RS programs, those bindings are available by
(import (scheme show base))
.
This contains most combinator formatting procedures.
Exports bindings of R7RS (scheme show color)
library.
From R7RS programs, those bindings are available by
(import (scheme show color))
.
This contains formatters to color text using ANSI escape codes.
Exports bindings of R7RS (scheme show columnar)
library.
From R7RS programs, those bindings are available by
(import (scheme show columnar))
.
This contains formatters to help format in columns.
Exports bindings of R7RS (scheme show unicode)
library.
From R7RS programs, those bindings are available by
(import (scheme show unicode))
.
Combinator formatting provides a functionality similar to
format
from SRFI28. But instead of writing a template string,
you can use Sexpressions, which are called “formatters”. It’s also
extensible.
The two main concepts in combinator formatting are formatters and
states. Formatters are procedures that specify how or what you want to
output. Formatters can be composed to produce complex format. Normal
types are also accepted where a procedure takes a formatter, they are
formatted with displayed
.
Format states let us customize control formatting, for example how
many precision digits, what character for padding …. Format
states can be changed locally with with
or with!
.
The entry point to combinator formatting is show
, which takes a
sequence of formatters and outputs to a port or returns a string.
[R7RS show base]
{scheme.show.base}
This is the main entry for combinator formatting. All formatters are
processed to produce a string to outputdest if it’s a port. If
outputdest is #t
, the current output port is used. If
outputdest is #f
, the output string is returned.
show
return value is otherwise undefined. Nonformatters are
also accepted and will be wrapped in displayed
formatter.
(show #f "π = " (with ((precision 2)) (acos 1)) nl) ⇒ "π = 3.14\n"
[R7RS show base]
{scheme.show.base}
The formatter that formats the object obj the
same as display
. This is the default formatter when you pass an
object to show
.
[R7RS show base]
{scheme.show.base}
The formatter that formats the object obj the same as
write
. Formatting settings numeric
and precision
are respected for relevant number types as long as the result can
still be passed to read
.
[R7RS show base]
{scheme.show.base}
Similar to written
but does not handle shared structures.
[R7RS show base] {scheme.show.base} Pretty prints an object.
[R7RS show base]
{scheme.show.base}
Similar to pretty
but does not handle shared structures.
[R7RS show base]
{scheme.show.base}
Prints a string, adding escch (#\\
by default) in front
of all quotech (#\"
by default).
If escch is #f
, escape all quotech by doubling
it.
If renamer is specified, it’s a procedure that takes one
character and returns another character or #f
. It serves two
purposes: to allow quoting more than one character and to replace them
with something else. If the procedure returns #f
, the character
in question is not escaped. Otherwise the character is escaped and
replaced with a new one.
escch could also be a string, but this is Gauche specific behavior.
(show #t (escaped "hello \"world\"")) ⇒ hello \"world\" (show #t (escaped "hello \"world\"" #\l)) ⇒ he\l\lo "world" (show #t (escaped "hello \"world\"" #\l #\x)) ⇒ hexlxlo "worxld" (show #t (escaped "hello \"world\"" #\e #f (lambda (x) (if (char=? x #\o) #\O #f)))) ⇒ heelleO "weOrld"
[R7RS show base]
{scheme.show.base}
Determines if str needs to be escaped or not. If true, the
string is wrapped with quotech. The original string is escaped
with escaped
.
The string needs to be escaped if any quotech or escch
is present, or any character that makes pred return #t
.
(show #t (maybeescaped "helloworld" charwhitespace?)) ⇒ helloworld (show #t (maybeescaped "hello world" charwhitespace?)) ⇒ "hello world" (show #t (maybeescaped "hello \"world\"" charwhitespace? #\")) ⇒ "hello \"world\""
[R7RS show base] {scheme.show.base} Formats a number. The default values are from state variables below.
(show #f (numeric 1000)) ⇒ "1000" (show #f (numeric 1000 8)) ⇒ "1750" (show #f (numeric 1000 8 2)) ⇒ "1750.00" (show #f (numeric 1000 8 2 #t)) ⇒ "+1750.00" (show #f (numeric 1000 8 2 (cons "(" ")"))) ⇒ "(1750.00)" (show #f (numeric 1000 8 2 #t 2)) ⇒ "+17,50.00" (show #f (numeric 1000 8 2 #t 2 #\')) ⇒ "+17'50.00" (show #f (numeric 1000 8 2 #t 2 #\' #\:)) ⇒ "+17'50:00"
[R7RS show base]
{scheme.show.base}
Formats a number with default commarule 3. See numeric
for details.
(show #f (numeric/comma 1000)) ⇒ "1,000" (show #f (with ((commasep #\.)) (numeric/comma 1000))) ⇒ "1.000"
[R7RS show base] {scheme.show.base} Formats a numeric with SI suffix. The default base is 1024 and uses suffix names like Ki, Mi, Gi…. Other bases (e.g. 1000) use suffixes k, M, G…. If separator is specified, it’s inserted between the number and suffix.
(show #f (numeric/si 1024)) ⇒ "1Ki" (show #f (numeric/si 200000 1000)) ⇒ "200k" (show #f (numeric/si 1024 1024 #\/)) ⇒ "1/Ki"
[R7RS show base]
{scheme.show.base}
Like numeric
but if the result does not fit in width
characters with current precision, outputs a string of hashes instead
of the truncated and incorrect number.
(show #f (with ((precision 2)) (numeric/fitted 4 1.25))) ⇒ "1.25" (show #f (with ((precision 2)) (numeric/fitted 4 12.345))) ⇒ "#.##"
Outputs a newline.
(show #f nl) ⇒ "\n"
Short for “fresh line”, make sures the following output is at the beginning of the line.
(show #f fl) ⇒ "" (show #f "aaa" fl) ⇒ "aaa\n"
Outputs nothing. This is useful in combinators as default noop in conditionals.
[R7RS show base] {scheme.show.base} Appends padchar to reach the given column.
(show #f "abcdef" (spaceto 3) "a") ⇒ " a" (show #f "abcdef" (spaceto 3) "a") ⇒ "abcdefa"
[R7RS show base] {scheme.show.base} Outputs padchar to reach the next tab stop.
[R7RS show base] {scheme.show.base}
[R7RS show base] {scheme.show.base}
[R7RS show base] {scheme.show.base} Formats each element in list with mapper and inserts sep in between. sep by default is an empty string, but it could be any string or formatter.
(show #f (joined displayed (list "a" "b") " ")) ⇒ "a b" (show #f (joined displayed (list "a" "b") nl)) ⇒ "a\nb"
[R7RS show base]
{scheme.show.base}
Similar to joined
except the separator is inserted before
every element.
(show #f (joined/prefix displayed '(usr local bin) "/")) ⇒ "/usr/local/bin"
[R7RS show base]
{scheme.show.base}
Similar to joined
except the separator is inserted after every
element.
(show #f (joined/suffix displayed '(1 2 3) nl)) ⇒ "1\n2\n3\n"
[R7RS show base]
{scheme.show.base}
Similar to joined
but lastmapper is used on the last
element of list instead.
(show #f (joined/last displayed (lambda (last) (each "and " last)) '(lions tigers bears) ", ")) ⇒ "lions, tigers, and bears"
[R7RS show base]
{scheme.show.base}
Similar to joined
but if list is a dotted list, then
formats the dotted value with dotmapper instead.
[R7RS show base] {scheme.show.base}
[R7RS show base] {scheme.show.base} Pads the output of fmt… on the left side with padchar if it’s shorter than width characters.
(show #f (padded 10 "abc")) ⇒ " abc" (show #f (with ((padchar #\)) (padded 10 "abc"))) ⇒ "abc"
[R7RS show base]
{scheme.show.base}
Similar to padded
but except padding is on the right side instead.
[R7RS show base]
{scheme.show.base}
Similar to padded
but except padding is on both sides, keeping
the fmt output at the center.
[R7RS show base] {scheme.show.base} Trims the output of fmt… on the left so that the length is width characters or less. If ellipsis state variable is defined, it will be put on the left to denote trimming.
(show #f (trimmed 5 "hello world")) ⇒ "world" (show #f (with ((ellipsis "..")) (trimmed 5 "hello world"))) ⇒ "..rld"
[R7RS show base]
{scheme.show.base}
Similar to trimmed
but the trimming is on the right.
[R7RS show base]
{scheme.show.base}
Similar to trimmed
but the trimming is on both sides, keeping
the center of the output.
[R7RS show base]
{scheme.show.base}
A variant of trimmed
which generates each fmt
in left to
right order, and truncates and terminates immediately if more than
width
characters are generated. Thus this is safe to use with
an infinite amount of output, e.g. from writtensimply
on an
infinite list.
[R7RS show base]
{scheme.show.base}
A combination of padded
and trimmed
, ensures the output
width is exactly width, truncating if it goes over and padding
if it goes under.
[R7RS show base]
{scheme.show.base}
A combination of padded/right
and trimmed/right
, ensures
the output width is exactly width, truncating if it goes over
and padding if it goes under.
[R7RS show base]
{scheme.show.base}
A combination of padded/both
and trimmed/both
, ensures
the output width is exactly width, truncating if it goes over
and padding if it goes under.
[R7RS show columnar] {scheme.show.columnar}
[R7RS show columnar] {scheme.show.columnar}
[R7RS show columnar] {scheme.show.columnar}
[R7RS show columnar] {scheme.show.columnar}
[R7RS show columnar] {scheme.show.columnar}
[R7RS show columnar] {scheme.show.columnar}
[R7RS show columnar] {scheme.show.columnar}
[R7RS show columnar] {scheme.show.columnar}
[R7RS show color] {scheme.show.color} Outputs the ANSI escape code to make all fmt… a given color or style.
[R7RS show unicode] {scheme.show.unicode}
[R7RS show unicode] {scheme.show.unicode}
[R7RS show base]
{scheme.show.base}
This is short for “function” and the analog to lambda
. It
returns a formatter which on application evaluates each expr and
fmt in lefttoright order, in a lexical environment extended
with each identifier id bound to the current value of the state
variable named by the symbol statevar. The result of the
fmt is then applied as a formatter.
As a convenience, any (id statevar)
list may be abbreviated as
simply id
, indicating id is bound to the state variable
of the same (symbol) name.
[R7RS show base]
{scheme.show.base}
This is the analog of let
. It temporarily binds specified state
variables with new values for fmt ….
[R7RS show base]
{scheme.show.base}
Similar to with
but the value updates persist even after
with!
.
[R7RS show base] {scheme.show.base} Calls fmt1 on (a conceptual copy of) the current state, then fmt2 on the same original state as though fmt1 had not been called (i.e. any potential state mutation by fmt1 does not affect fmt2).
[R7RS show base]
{scheme.show.base}
A utility, calls formatter on a copy of the current state (as with
forked
), accumulating the results into a string. Then calls the
formatter resulting from (mapper resultstring)
on the original
state.
The current port output is written into, could be overriden to capture intermediate output.
The current row of the output.
The current column of the output.
The current line width, used for wrapping, pretty printing and columnar formatting.
The underlying standard formatter for writing a single string.
The default value outputs the string while tracking the current row and col. This can be overridden both to capture intermediate output and perform transformations on strings before outputting, but should generally wrap the existing output to preserve expected behavior.
The mapper for automatic formatting of nonstring/char values in toplevel show, each and other formatters. Default value is implementationdefined.
A function of a single string. It returns the length in columns of that string, used by the default output.
The character used for by padding formatters, #\space
by default
The string used when truncating as described in trimmed
.
The radix for numeric output, 10 by default. Valid values are from 2 to 36.
The number of digits written after the decimal point for numeric output. The value is rounded if the numeric value written out requires more digits than requested precision. See the SRFI for exact rounding behavior.
If #t
, always output the plus sign +
for positive
numbers. If signrule is a par of two strings, negative numbers
are printed with the strings wrapped around (and no preceding negative
sign 
).
The number of digits between commans, specified by commasep.
The character used as comma for numeric formatting, #\,
by
default.
The character to use for decimals in numeric formatting. The default
depends on commasep, if it’s #\.
, then the decimal
separator is #\,
, otherwise it’s #\.
Previous: R7RS small language, Up: Library modules  R7RS standard libraries [Contents][Index]