guile.texi 14 KB

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