1 @node Guile Scheme concepts
2 @chapter Guile Scheme concepts
4 Most Scheme implementations go beyond what is specified in the R4RS
5 document @footnote{Remember? R4RS is the Revised^4 report on the
6 Algorithmic Language Scheme}, mostly because R4RS does not give
7 specifications (or even recommendations) regarding some issues that are
8 quite important in practical programming.
10 Here is a list of how Guile implements some of these much-needed Scheme
11 extensions; other Scheme implementations do so quite similarly.
15 * Read-eval-print loops::
17 * Miscellaneous features::
24 Even if you read some of the nice books on Scheme, or the R4RS report,
25 you might not find some of the terms frequently used by Scheme hackers,
26 both in the manual and in the @url{news:comp.lang.scheme} newsgroup.
28 Here is a glossary of some of the terms that make Scheme beginners and
29 intermediate users say ``huh?''
34 A Scheme procedure that takes no arguments. In this example,
35 @code{thunk} and @code{another-thunk} are both thunks:
38 (display "Dude, I'm a thunk!")
48 A closure is a procedure. However, the term emphasizes the fact that a
49 Scheme procedure remembers (or @dfn{closes over}) the variables that
50 were visible when the @code{lambda} expression was
53 In the example below, we might refer to @code{q} as a closure, because
54 it has closed over the value of @code{x}:
66 However, strictly speaking, every Scheme procedure is really a closure,
67 since it closes over the top-level environment.
70 @itemx association list
78 @node Read-eval-print loops
79 @section Read-eval-print loops
80 @cindex Read-eval-print loop
83 To explicitly mention the Scheme read-eval-print loop (REPL) seems weird
84 because we are all accustomed to firing up an interpreter and having it
85 read and execute commands.
87 But the REPL is not specified in R4RS; rather, it is proposed by the
88 Scheme Bible @cite{Structure and Interpretation of Computer Programs}
89 (also known as @emph{SICP}), and implemented in some form in all Scheme
91 @cindex Structure and Interpretation of Computer Programs
94 [FIXME: Someone needs to tell me what needs to be said about Guile's
97 @node Extra data types
98 @section Extra data types
100 The fundamental Scheme data types specified in R4RS are @emph{numbers}
101 (both exact and inexact), @emph{characters}, @emph{strings},
102 @emph{symbols}, @emph{vectors}, @emph{pairs} and @emph{lists} [FIXME: is
105 Many Scheme interpreters offer more types, and Guile is no exception.
106 Guile is based on Aubrey Jaffer's SCM interpreter, and thus inherits
107 @emph{uniform arrays}, [FIXME: any others? How about records?].
109 On top of that, Guile allows you to add extra types, but that is covered
110 in @ref{Adding types to Guile}. Here I will simply document all the
111 extra Scheme types shipped with Guile.
114 * Conventional arrays::
120 @node Conventional arrays
121 @subsection Conventional arrays
124 @subsection Uniform arrays
125 @cindex arrays - uniform
127 The motivation for uniform arrays in Scheme is performance. A vector
128 provides a performance increase over lists when you want a fixed-size
129 indexable list. But the elements in a vector can be of different types,
130 and this makes for larger storage requirements and slightly lower
133 A uniform array is similar to a vector, but all elements have to be of
136 arrays, uniform arrays, bit vectors:
138 @deffn procedure array-fill ra fill
140 @deffn procedure serial-array-copy! src dst
142 @deffn procedure serial-array-map ra0 proc [lra]
144 @deffn procedure array-map ra0 proc [lra]
146 @deffn procedure array-for-each proc ra0 [lra]
148 @deffn procedure array-index-map! ra proc
150 @deffn procedure array-copy! src dst
152 @deffn procedure array-copy! src dst
154 @deffn procedure array-copy! src dst
156 @deffn procedure array-copy! src dst
158 @deffn procedure array-copy! src dst
160 @deffn procedure array? ra [prot]
162 @deffn procedure array-rank ra
164 @deffn procedure array-dimensions ra
166 @deffn procedure dimensions->uniform-array dims prot fill ...
168 @deffn procedure make-shared-array ra mapfunc dims ...
170 @deffn procedure transpose-array arg ...
172 @deffn procedure enclose-array axes ...
174 @deffn procedure array-in-bounds? arg ...
176 @deffn procedure array-ref ra arg ..
178 @deffn procedure uniform-vector-ref vec pos
180 @deffn procedure array-set! ra obj arg ...
182 @deffn procedure uniform-array-set1! ua obj arg
184 @deffn procedure array-contents ra [strict]
186 @deffn procedure uniform-array-read! ra [port-or-fd] [start] [end]
188 @deffn procedure uniform-array-write! ra [port-or-fd] [start] [end]
190 @deffn procedure bit-count item seq
192 @deffn procedure bit-position item v k
194 @deffn procedure bit-set! v kv obj
196 @deffn procedure bit-count* v kv obj
198 @deffn procedure bit-invert v
200 @deffn procedure array->list ra
202 @deffn procedure list->uniform-array ndim prot list
204 @deffn procedure array-prototype ra
207 Unform arrays can be written and read, but @code{read} won't recognize
208 them unless the optional @code{read-sharp} parameter is supplied,
211 (read port #t read-sharp)
214 where @code{read-sharp} is the default procedure for parsing extended
217 Reading an array is not very efficient at present, since it's implemented
218 by reading a list and converting the list to an array.
220 @c FIXME: must use @deftp, but its generation of TeX code is buggy.
221 @c Must fix it when TeXinfo gets fixed.
222 @deftp {Scheme type} {uniform array}
227 @subsection Bit vectors
229 @node Complex numbers
230 @subsection Complex numbers
232 @c FIXME: must use @deftp, but its generation of TeX code is buggy.
233 @c Must fix it when TeXinfo gets fixed.
234 @deftp {Scheme type} complex
235 Standard complex numbers.
238 @node Miscellaneous features
239 @section Miscellaneous features
241 @defun defined? symbol
242 Returns @code{#t} if a symbol is bound to a value, @code{#f} otherwise.
243 This kind of procedure is not specified in R4RS because @c FIXME: finish
247 @defun object-properties OBJ