Merge commit '3d51e57cfb0404db568a6adfde2a346d3fd9907e'
[bpt/guile.git] / doc / ref / guile.texi
1 \input texinfo
2 @c -*-texinfo-*-
3 @c %**start of header
4 @setfilename guile.info
5 @documentencoding UTF-8
6 @settitle Guile Reference Manual
7 @set guile
8 @set MANUAL-REVISION 1
9 @c %**end of header
10 @include version.texi
11 @include effective-version.texi
12
13 @copying
14 This manual documents Guile version @value{VERSION}.
15
16 Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2005, 2009,
17 2010, 2011 Free Software Foundation.
18
19 Permission is granted to copy, distribute and/or modify this document
20 under the terms of the GNU Free Documentation License, Version 1.3 or
21 any later version published by the Free Software Foundation; with no
22 Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
23 copy of the license is included in the section entitled ``GNU Free
24 Documentation License.''
25 @end copying
26
27
28 @c Notes
29 @c
30 @c We no longer use the category "primitive" to distinguish C-defined
31 @c Scheme procedures from those defined in Scheme. Instead, the
32 @c reference manual now includes a C declaration as well as a Scheme
33 @c declaration for each procedure that is available in both Scheme and
34 @c C.
35 @c
36 @c When adding a new reference entry to the Guile manual, please
37 @c document it with @deffn using one of the following categories:
38 @c
39 @c {Scheme Procedure}
40 @c {Scheme Syntax}
41 @c {C Function}
42 @c {C Macro}
43 @c
44 @c If the entry is for a new primitive, it should have both a @deffn
45 @c {Scheme Procedure} line and a @deffnx {C Function} line; see the
46 @c manual source for plenty of existing examples of this.
47 @c
48 @c For {C Function} entries where the return type and all parameter
49 @c types are SCM, we omit the SCMs. This is easier to read and also
50 @c gets round the problem that Texinfo doesn't allow a @deftypefnx
51 @c inside a @deffn.
52 @c
53 @c For a list of Guile primitives that are not yet incorporated into the
54 @c reference manual, see the file `new-docstrings.texi', which holds all
55 @c the docstrings snarfed from the libguile C sources for primitives
56 @c that are not in the reference manual. If you have worked with some
57 @c of these concepts, implemented them, or just happen to know what they
58 @c do, please write up a little explanation -- it would be a big help.
59 @c Alternatively, if you know of any reason why some of these should
60 @c *not* go in the manual, please let the mailing list
61 @c <guile-devel@gnu.org> know.
62
63 @c Define indices that are used in the Guile Scheme part of the
64 @c reference manual to group stuff according to whether it is R5RS or a
65 @c Guile extension.
66 @defcodeindex rn
67
68 @c vnew - For (some) new items, indicates the Guile version in which
69 @c item first appeared. In future, this could be made to expand to
70 @c something like a "New in Guile 45!" banner.
71 @macro vnew{VERSION}
72 @end macro
73
74
75 @c The following, @le{} and @ge{}, are standard tex directives, given
76 @c definitions for use in non-tex.
77 @c
78 @ifnottex
79 @macro ge
80 >=
81 @end macro
82 @macro le
83 <=
84 @end macro
85 @end ifnottex
86
87 @c @cross{} is a \times symbol in tex, or an "x" in info. In tex it works
88 @c inside or outside $ $.
89 @tex
90 \gdef\cross{\ifmmode\times\else$\times$\fi}
91 @end tex
92 @ifnottex
93 @macro cross
94 x
95 @end macro
96 @end ifnottex
97
98 @c @m{T,N} is $T$ in tex or @math{N} otherwise. This is an easy way to give
99 @c different forms for math in tex and info.
100 @iftex
101 @macro m {T,N}
102 @tex$\T\$@end tex
103 @end macro
104 @end iftex
105 @ifnottex
106 @macro m {T,N}
107 @math{\N\}
108 @end macro
109 @end ifnottex
110
111 @c @nicode{S} is plain S in info, or @code{S} elsewhere. This can be used
112 @c when the quotes that @code{} gives in info aren't wanted, but the
113 @c fontification in tex or html is wanted. @alias is used rather
114 @c than @macro because backslashes don't work properly in an @macro.
115 @ifinfo
116 @alias nicode=asis
117 @end ifinfo
118 @ifnotinfo
119 @alias nicode=code
120 @end ifnotinfo
121
122
123 @c @iftex
124 @c @cropmarks
125 @c @end iftex
126
127 @dircategory The Algorithmic Language Scheme
128 @direntry
129 * Guile Reference: (guile). The Guile reference manual.
130 @end direntry
131
132 @setchapternewpage odd
133
134 @titlepage
135 @sp 10
136 @comment The title is printed in a large font.
137 @title Guile Reference Manual
138 @subtitle Edition @value{EDITION}, revision @value{MANUAL-REVISION}, for use with Guile @value{VERSION}
139 @c @subtitle $Id: guile.texi,v 1.49 2008-03-19 22:51:23 ossau Exp $
140
141 @c See preface.texi for the list of authors
142 @author The Guile Developers
143
144 @c The following two commands start the copyright page.
145 @page
146 @vskip 0pt plus 1filll
147 @vskip 0pt plus 1filll
148 @insertcopying
149 @end titlepage
150
151 @c @smallbook
152 @finalout
153 @headings double
154
155 @c Where to find Guile examples.
156 @set example-dir doc/examples
157
158 @ifnottex
159 @node Top, Preface, (dir), (dir)
160 @top The Guile Reference Manual
161
162 @insertcopying
163 @sp 1
164 @end ifnottex
165
166 @menu
167
168 * Preface::
169 * Introduction::
170
171 * Hello Guile!::
172 * Hello Scheme!::
173
174 * Programming in Scheme::
175 * Programming in C::
176
177 * API Reference::
178
179 * Guile Modules::
180 * Standard Library::
181
182 * GOOPS::
183
184 * Guile Implementation::
185
186 Appendices
187
188 * GNU Free Documentation License:: The license of this manual.
189
190 Indices
191
192 * Concept Index::
193 * Procedure Index::
194 * Variable Index::
195 * Type Index::
196 * R5RS Index::
197
198 @end menu
199
200 @contents
201
202 @include preface.texi
203
204 @include intro.texi
205
206 @include tour.texi
207
208 @include scheme-ideas.texi
209 @include scheme-reading.texi
210
211 @node Programming in Scheme
212 @chapter Programming in Scheme
213
214 Guile's core language is Scheme, and a lot can be achieved simply by using Guile
215 to write and run Scheme programs --- as opposed to having to dive into C code.
216 In this part of the manual, we explain how to use Guile in this mode, and
217 describe the tools that Guile provides to help you with script writing,
218 debugging, and packaging your programs for distribution.
219
220 For detailed reference information on the variables, functions, and so
221 on that make up Guile's application programming interface (API), see
222 @ref{API Reference}.
223
224 @menu
225 * Guile Scheme:: Guile's implementation of Scheme.
226 * Invoking Guile:: Selecting optional features when starting Guile.
227 * Guile Scripting:: How to write Guile scripts.
228 * Using Guile Interactively:: Guile's REPL features.
229 * Using Guile in Emacs:: Guile and Emacs.
230 * Using Guile Tools:: A guild of scheming wizards.
231 * Installing Site Packages:: Installing Scheme code.
232 @end menu
233
234 @include scheme-intro.texi
235 @include guile-invoke.texi
236 @include scheme-scripts.texi
237 @include scheme-using.texi
238
239 @node Programming in C
240 @chapter Programming in C
241
242 This part of the manual explains the general concepts that you need to
243 understand when interfacing to Guile from C. You will learn about how
244 the latent typing of Scheme is embedded into the static typing of C, how
245 the garbage collection of Guile is made available to C code, and how
246 continuations influence the control flow in a C program.
247
248 This knowledge should make it straightforward to add new functions to
249 Guile that can be called from Scheme. Adding new data types is also
250 possible and is done by defining @dfn{smobs}.
251
252 The @ref{Programming Overview} section of this part contains general
253 musings and guidelines about programming with Guile. It explores
254 different ways to design a program around Guile, or how to embed Guile
255 into existing programs.
256
257 For a pedagogical yet detailed explanation of how the data representation of
258 Guile is implemented, @xref{Data Representation}. You don't need to know the
259 details given there to use Guile from C, but they are useful when you want to
260 modify Guile itself or when you are just curious about how it is all done.
261
262 For detailed reference information on the variables, functions
263 etc. that make up Guile's application programming interface (API),
264 @xref{API Reference}.
265
266 @menu
267 * Parallel Installations:: Finding the right Guile.
268 * Linking Programs With Guile:: More precisely, with the libguile library.
269 * Linking Guile with Libraries:: To extend Guile itself.
270 * General Libguile Concepts:: General concepts for using libguile.
271 * Defining New Types (Smobs):: Adding new types to Guile.
272 * Function Snarfing:: A way to define new functions.
273 * Programming Overview:: An overview of Guile programming.
274 * Autoconf Support:: Putting m4 to good use.
275 @end menu
276
277 @include libguile-parallel.texi
278 @include libguile-linking.texi
279 @include libguile-extensions.texi
280 @include libguile-concepts.texi
281 @include libguile-smobs.texi
282 @include libguile-snarf.texi
283 @include libguile-program.texi
284 @include libguile-autoconf.texi
285
286
287 @node API Reference
288 @chapter API Reference
289
290 Guile provides an application programming interface (@dfn{API}) to
291 developers in two core languages: Scheme and C. This part of the manual
292 contains reference documentation for all of the functionality that is
293 available through both Scheme and C interfaces.
294
295 @menu
296 * API Overview:: Overview of the Guile API.
297 * Deprecation:: Obsolete back-compatible APIs.
298 * The SCM Type:: The fundamental data type for C code.
299 * Initialization:: Initializing Guile.
300 * Snarfing Macros:: Macros for snarfing initialization actions.
301 * Simple Data Types:: Numbers, strings, booleans and so on.
302 * Compound Data Types:: Data types for holding other data.
303 * Smobs:: Defining new data types in C.
304 * Procedures:: Procedures.
305 * Macros:: Extending the syntax of Scheme.
306 * Utility Functions:: General utility functions.
307 * Binding Constructs:: Definitions and variable bindings.
308 * Control Mechanisms:: Controlling the flow of program execution.
309 * Input and Output:: Ports, reading and writing.
310 * Regular Expressions:: Pattern matching and substitution.
311 * LALR(1) Parsing:: Generating LALR(1) parsers.
312 * Read/Load/Eval/Compile:: Reading and evaluating Scheme code.
313 * Memory Management:: Memory management and garbage collection.
314 * Modules:: Designing reusable code libraries.
315 * Foreign Function Interface:: Interacting with C procedures and data.
316 * Scheduling:: Threads, mutexes, asyncs and dynamic roots.
317 * Options and Config:: Configuration, features and runtime options.
318 * Other Languages:: Emacs Lisp, ECMAScript, and more.
319 * Internationalization:: Support for gettext, etc.
320 * Debugging:: Debugging infrastructure and Scheme interface.
321 * Code Coverage:: Gathering code coverage data.
322 @end menu
323
324 @include api-overview.texi
325 @include api-deprecated.texi
326 @include api-scm.texi
327 @include api-init.texi
328 @include api-snarf.texi
329 @include api-data.texi
330 @include api-compound.texi
331 @include api-smobs.texi
332 @include api-procedures.texi
333 @include api-macros.texi
334 @include api-utility.texi
335 @include api-binding.texi
336 @include api-control.texi
337 @include api-io.texi
338 @include api-regex.texi
339 @include api-lalr.texi
340 @include api-evaluation.texi
341 @include api-memory.texi
342 @include api-modules.texi
343 @include api-foreign.texi
344 @include api-scheduling.texi
345 @c object orientation support here
346 @include api-options.texi
347 @include api-languages.texi
348 @include api-i18n.texi
349 @include api-debug.texi
350 @include api-coverage.texi
351
352 @node Guile Modules
353 @chapter Guile Modules
354
355 @menu
356 * SLIB:: Using the SLIB Scheme library.
357 * POSIX:: POSIX system calls and networking.
358 * Web:: HTTP, the web, and all that.
359 * getopt-long:: Command line handling.
360 * SRFI Support:: Support for various SRFIs.
361 * R6RS Support:: Modules defined by the R6RS.
362 * Pattern Matching:: Generic pattern matching constructs.
363 * Readline Support:: Module for using the readline library.
364 * Pretty Printing:: Nicely formatting Scheme objects for output.
365 * Formatted Output:: The @code{format} procedure.
366 * File Tree Walk:: Traversing the file system.
367 * Queues:: First-in first-out queuing.
368 * Streams:: Sequences of values.
369 * Buffered Input:: Ports made from a reader function.
370 * Expect:: Controlling interactive programs with Guile.
371 * sxml-match:: Pattern matching of SXML.
372 * The Scheme shell (scsh):: Using scsh interfaces in Guile.
373 @end menu
374
375 @include slib.texi
376 @include posix.texi
377 @include web.texi
378 @include mod-getopt-long.texi
379 @include srfi-modules.texi
380 @include r6rs.texi
381 @include match.texi
382 @include repl-modules.texi
383 @include misc-modules.texi
384 @include expect.texi
385
386 @c XXX: Would be nicer if it were close to the (sxml simple) documentation.
387 @include sxml-match.texi
388
389 @include scsh.texi
390
391 @node Standard Library
392 @chapter Standard Library
393
394 @lowersections
395 @include standard-library.texi
396 @raisesections
397
398 @include goops.texi
399
400 @node Guile Implementation
401 @chapter Guile Implementation
402
403 At some point, after one has been programming in Scheme for some time,
404 another level of Scheme comes into view: its implementation. Knowledge
405 of how Scheme can be implemented turns out to be necessary to become
406 an expert hacker. As Peter Norvig notes in his retrospective on
407 PAIP@footnote{PAIP is the common abbreviation for @cite{Paradigms of
408 Artificial Intelligence Programming}, an old but still useful text on
409 Lisp. Norvig's retrospective sums up the lessons of PAIP, and can be
410 found at @uref{http://norvig.com/Lisp-retro.html}.}, ``The expert Lisp
411 programmer eventually develops a good `efficiency model'.''
412
413 By this Norvig means that over time, the Lisp hacker eventually
414 develops an understanding of how much her code ``costs'' in terms of
415 space and time.
416
417 This chapter describes Guile as an implementation of Scheme: its
418 history, how it represents and evaluates its data, and its compiler.
419 This knowledge can help you to make that step from being one who is
420 merely familiar with Scheme to being a real hacker.
421
422 @menu
423 * History:: A brief history of Guile.
424 * Data Representation:: How Guile represents Scheme data.
425 * A Virtual Machine for Guile:: How compiled procedures work.
426 * Compiling to the Virtual Machine:: Not as hard as you might think.
427 @end menu
428
429 @include history.texi
430 @include data-rep.texi
431 @include vm.texi
432 @include compiler.texi
433
434 @node GNU Free Documentation License
435 @appendix GNU Free Documentation License
436
437 @include fdl.texi
438
439 @include indices.texi
440 @include scheme-indices.texi
441
442 @bye