guile.texi 14 KB

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