guile.texi 14 KB

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