intro.texi 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. @c -*-texinfo-*-
  2. @c This is part of the GNU Guile Reference Manual.
  3. @c Copyright (C) 1996-1997,2000-2004,2006,2008-2011,2013,2019
  4. @c Free Software Foundation, Inc.
  5. @c See the file guile.texi for copying conditions.
  6. @node Introduction
  7. @chapter Introduction
  8. Guile is an implementation of the Scheme programming language. Scheme
  9. (@url{http://schemers.org/}) is an elegant and conceptually simple
  10. dialect of Lisp, originated by Guy Steele and Gerald Sussman, and since
  11. evolved by the series of reports known as RnRS (the
  12. @tex
  13. Revised$^n$
  14. @end tex
  15. @ifnottex
  16. Revised^n
  17. @end ifnottex
  18. Reports on Scheme).
  19. Unlike, for example, Python or Perl, Scheme has no benevolent
  20. dictator. There are many Scheme implementations, with different
  21. characteristics and with communities and academic activities around
  22. them, and the language develops as a result of the interplay between
  23. these. Guile's particular characteristics are that
  24. @itemize
  25. @item
  26. it is easy to combine with other code written in C
  27. @item
  28. it has a historical and continuing connection with the GNU Project
  29. @item
  30. it emphasizes interactive and incremental programming
  31. @item
  32. it actually supports several languages, not just Scheme.
  33. @end itemize
  34. @noindent
  35. The next few sections explain what we mean by these points. The sections after
  36. that cover how you can obtain and install Guile, and the typographical
  37. conventions that we use in this manual.
  38. @menu
  39. * Guile and Scheme::
  40. * Combining with C::
  41. * Guile and the GNU Project::
  42. * Interactive Programming::
  43. * Supporting Multiple Languages::
  44. * Obtaining and Installing Guile::
  45. * Organisation of this Manual::
  46. * Typographical Conventions::
  47. @end menu
  48. @node Guile and Scheme
  49. @section Guile and Scheme
  50. Guile implements Scheme as described in the
  51. @tex
  52. Revised$^5$
  53. @end tex
  54. @ifnottex
  55. Revised^5
  56. @end ifnottex
  57. Report on the Algorithmic Language Scheme (usually known as
  58. @acronym{R5RS}), providing clean and general data and control
  59. structures. Guile goes beyond the rather austere language presented
  60. in @acronym{R5RS}, extending it with a module system, full access to
  61. @acronym{POSIX} system calls, networking support, multiple threads,
  62. dynamic linking, a foreign function call interface, powerful string
  63. processing, and many other features needed for programming in the real
  64. world.
  65. In 2007, the Scheme community agreed upon and published R6RS, a
  66. significant installment in the RnRS series. R6RS expands the core
  67. Scheme language, and standardises many non-core functions that
  68. implementations---including Guile---have previously done in different
  69. ways. Over time, Guile has been updated to incorporate almost all of
  70. the features of R6RS, and to adjust some existing features to conform to
  71. the R6RS specification. @xref{R6RS Support}, for full details.
  72. In parallel to official standardization efforts, the SRFI process
  73. (@url{http://srfi.schemers.org/}) standardises interfaces for many
  74. practical needs, such as multithreaded programming and multidimensional
  75. arrays. Guile supports many SRFIs, as documented in detail in @ref{SRFI
  76. Support}.
  77. The process that led to the R6RS standard brought a split in the Scheme
  78. community to the surface. The implementors that wrote R6RS considered
  79. that it was impossible to write useful, portable programs in R5RS, and
  80. that only an ambitious standard could solve this problem. However, part
  81. of the Scheme world saw the R6RS effort as too broad, and as having
  82. included some components that would never be adopted by more
  83. minimalistic Scheme implementations. This second group succeeded in
  84. taking control of the official Scheme standardization track and in 2013
  85. released a more limited R7RS, essentially consisting of R5RS, plus a
  86. module system. Guile supports R7RS also. @xref{R7RS Support}.
  87. With R6RS and R7RS, the unified Scheme standardization process appears
  88. to have more or less run its course. There will continue to be more
  89. code written in terms of both systems, and modules defined using the
  90. SRFI process, and Guile will support both. However for future
  91. directions, Guile takes inspiration from other related language
  92. communities: Racket, Clojure, Concurrent ML, and so on.
  93. In summary, Guile supports writing and running code written to the R5RS,
  94. R6RS, and R7RS Scheme standards, and also supports a number of SRFI
  95. modules. However for most users, until a need for cross-implementation
  96. portability has been identified, we recommend using the parts of Guile
  97. that are useful in solving the problem at hand, regardless of whether
  98. they proceed from a standard or whether they are Guile-specific.
  99. @node Combining with C
  100. @section Combining with C Code
  101. Like a shell, Guile can run interactively---reading expressions from the user,
  102. evaluating them, and displaying the results---or as a script interpreter,
  103. reading and executing Scheme code from a file. Guile also provides an object
  104. library, @dfn{libguile}, that allows other applications to easily incorporate a
  105. complete Scheme interpreter. An application can then use Guile as an extension
  106. language, a clean and powerful configuration language, or as multi-purpose
  107. ``glue'', connecting primitives provided by the application. It is easy to call
  108. Scheme code from C code and vice versa, giving the application designer full
  109. control of how and when to invoke the interpreter. Applications can add new
  110. functions, data types, control structures, and even syntax to Guile, creating a
  111. domain-specific language tailored to the task at hand, but based on a robust
  112. language design.
  113. This kind of combination is helped by four aspects of Guile's design
  114. and history. First is that Guile has always been targeted as an
  115. extension language. Hence its C API has always been of great
  116. importance, and has been developed accordingly. Second and third are
  117. rather technical points---that Guile uses conservative garbage
  118. collection, and that it implements the Scheme concept of continuations
  119. by copying and reinstating the C stack---but whose practical
  120. consequence is that most existing C code can be glued into Guile as
  121. is, without needing modifications to cope with strange Scheme
  122. execution flows. Last is the module system, which helps extensions to
  123. coexist without stepping on each others' toes.
  124. Guile's module system allows one to break up a large program into
  125. manageable sections with well-defined interfaces between them.
  126. Modules may contain a mixture of interpreted and compiled code; Guile
  127. can use either static or dynamic linking to incorporate compiled code.
  128. Modules also encourage developers to package up useful collections of
  129. routines for general distribution; as of this writing, one can find
  130. Emacs interfaces, database access routines, compilers, @acronym{GUI}
  131. toolkit interfaces, and @acronym{HTTP} client functions, among others.
  132. @node Guile and the GNU Project
  133. @section Guile and the GNU Project
  134. Guile was conceived by the GNU Project following the fantastic success
  135. of Emacs Lisp as an extension language within Emacs. Just as Emacs
  136. Lisp allowed complete and unanticipated applications to be written
  137. within the Emacs environment, the idea was that Guile should do the
  138. same for other GNU Project applications. This remains true today.
  139. The idea of extensibility is closely related to the GNU project's
  140. primary goal, that of promoting software freedom. Software freedom
  141. means that people receiving a software package can modify or enhance
  142. it to their own desires, including in ways that may not have occurred
  143. at all to the software's original developers. For programs written in
  144. a compiled language like C, this freedom covers modifying and
  145. rebuilding the C code; but if the program also provides an extension
  146. language, that is usually a much friendlier and lower-barrier-of-entry
  147. way for the user to start making their own changes.
  148. Guile is now used by GNU project applications such as AutoGen, Lilypond, Denemo,
  149. Mailutils, TeXmacs and Gnucash, and we hope that there will be many more in
  150. future.
  151. @node Interactive Programming
  152. @section Interactive Programming
  153. Non-free software has no interest in its users being able to see how it works.
  154. They are supposed to just accept it, or to report problems and hope that the
  155. source code owners will choose to work on them.
  156. Free software aims to work reliably just as much as non-free software does, but
  157. it should also empower its users by making its workings available. This is
  158. useful for many reasons, including education, auditing and enhancements, as well
  159. as for debugging problems.
  160. The ideal free software system achieves this by making it easy for interested
  161. users to see the source code for a feature that they are using, and to follow
  162. through that source code step-by-step, as it runs. In Emacs, good examples of
  163. this are the source code hyperlinks in the help system, and @code{edebug}.
  164. Then, for bonus points and maximising the ability for the user to experiment
  165. quickly with code changes, the system should allow parts of the source code to
  166. be modified and reloaded into the running program, to take immediate effect.
  167. Guile is designed for this kind of interactive programming, and this
  168. distinguishes it from many Scheme implementations that instead prioritise
  169. running a fixed Scheme program as fast as possible---because there are
  170. tradeoffs between performance and the ability to modify parts of an already
  171. running program. There are faster Schemes than Guile, but Guile is a GNU
  172. project and so prioritises the GNU vision of programming freedom and
  173. experimentation.
  174. @node Supporting Multiple Languages
  175. @section Supporting Multiple Languages
  176. Since the 2.0 release, Guile's architecture supports compiling any language to
  177. its core virtual machine bytecode, and Scheme is just one of the supported
  178. languages. Other supported languages are Emacs Lisp, ECMAScript (commonly known
  179. as Javascript) and Brainfuck, and work is under discussion for Lua, Ruby and
  180. Python.
  181. This means that users can program applications which use Guile in the language
  182. of their choice, rather than having the tastes of the application's author
  183. imposed on them.
  184. @node Obtaining and Installing Guile
  185. @section Obtaining and Installing Guile
  186. Guile can be obtained from the main GNU archive site
  187. @url{ftp://ftp.gnu.org} or any of its mirrors. The file will be named
  188. guile-@var{version}.tar.gz. The current version is @value{VERSION}, so the
  189. file you should grab is:
  190. @url{ftp://ftp.gnu.org/gnu/guile/guile-@value{VERSION}.tar.gz}
  191. To unbundle Guile use the instruction
  192. @example
  193. zcat guile-@value{VERSION}.tar.gz | tar xvf -
  194. @end example
  195. @noindent
  196. which will create a directory called @file{guile-@value{VERSION}} with
  197. all the sources. You can look at the file @file{INSTALL} for detailed
  198. instructions on how to build and install Guile, but you should be able
  199. to just do
  200. @example
  201. cd guile-@value{VERSION}
  202. ./configure
  203. make
  204. make install
  205. @end example
  206. This will install the Guile executable @file{guile}, the Guile library
  207. @file{libguile} and various associated header files and support libraries. It
  208. will also install the Guile reference manual.
  209. @c [[include instructions for getting R5RS]]
  210. Since this manual frequently refers to the Scheme ``standard'', also
  211. known as R5RS, or the
  212. @tex
  213. ``Revised$^5$ Report on the Algorithmic Language Scheme'',
  214. @end tex
  215. @ifnottex
  216. ``Revised^5 Report on the Algorithmic Language Scheme'',
  217. @end ifnottex
  218. we have included the report in the Guile distribution; see
  219. @ref{Top, , Introduction, r5rs, Revised(5) Report on the Algorithmic
  220. Language Scheme}.
  221. This will also be installed in your info directory.
  222. @node Organisation of this Manual
  223. @section Organisation of this Manual
  224. The rest of this manual is organised into the following chapters.
  225. @table @strong
  226. @item Chapter 2: Hello Guile!
  227. A whirlwind tour shows how Guile can be used interactively and as
  228. a script interpreter, how to link Guile into your own applications,
  229. and how to write modules of interpreted and compiled code for use with
  230. Guile. Everything introduced here is documented again and in full by
  231. the later parts of the manual.
  232. @item Chapter 3: Hello Scheme!
  233. For readers new to Scheme, this chapter provides an introduction to the basic
  234. ideas of the Scheme language. This material would apply to any Scheme
  235. implementation and so does not make reference to anything Guile-specific.
  236. @item Chapter 4: Programming in Scheme
  237. Provides an overview of programming in Scheme with Guile. It covers how to
  238. invoke the @code{guile} program from the command-line and how to write scripts
  239. in Scheme. It also introduces the extensions that Guile offers beyond standard
  240. Scheme.
  241. @item Chapter 5: Programming in C
  242. Provides an overview of how to use Guile in a C program. It
  243. discusses the fundamental concepts that you need to understand to
  244. access the features of Guile, such as dynamic types and the garbage
  245. collector. It explains in a tutorial like manner how to define new
  246. data types and functions for the use by Scheme programs.
  247. @item Chapter 6: Guile API Reference
  248. This part of the manual documents the Guile @acronym{API} in
  249. functionality-based groups with the Scheme and C interfaces presented
  250. side by side.
  251. @item Chapter 7: Guile Modules
  252. Describes some important modules, distributed as part of the Guile
  253. distribution, that extend the functionality provided by the Guile
  254. Scheme core.
  255. @item Chapter 8: GOOPS
  256. Describes GOOPS, an object oriented extension to Guile that provides
  257. classes, multiple inheritance and generic functions.
  258. @end table
  259. @node Typographical Conventions
  260. @section Typographical Conventions
  261. In examples and procedure descriptions and all other places where the
  262. evaluation of Scheme expression is shown, we use some notation for
  263. denoting the output and evaluation results of expressions.
  264. The symbol @samp{@result{}} is used to tell which value is returned by
  265. an evaluation:
  266. @lisp
  267. (+ 1 2)
  268. @result{} 3
  269. @end lisp
  270. Some procedures produce some output besides returning a value. This
  271. is denoted by the symbol @samp{@print{}}.
  272. @lisp
  273. (begin (display 1) (newline) 'hooray)
  274. @print{} 1
  275. @result{} hooray
  276. @end lisp
  277. As you can see, this code prints @samp{1} (denoted by
  278. @samp{@print{}}), and returns @code{hooray} (denoted by
  279. @samp{@result{}}).
  280. @c Local Variables:
  281. @c TeX-master: "guile.texi"
  282. @c End: