intro.texi 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. @c -*-texinfo-*-
  2. @c This is part of the GNU Guile Reference Manual.
  3. @c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2006, 2010
  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{schemers.org}) is an elegant and conceptually simple dialect of
  10. Lisp, originated by Guy Steele and Gerald Sussman, and since evolved
  11. 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. The Scheme community has recently agreed and published R6RS, the
  66. latest installment in the RnRS series. R6RS significantly expands the
  67. core Scheme language, and standardises many non-core functions that
  68. implementations---including Guile---have previously done in
  69. different ways. Guile has been updated to incorporate some of the
  70. features of R6RS, and to adjust some existing features to conform to
  71. the R6RS specification, but it is by no means a complete R6RS
  72. implementation. @xref{R6RS Support}.
  73. Between R5RS and R6RS, the SRFI process (@url{http://srfi.schemers.org/})
  74. standardised interfaces for many practical needs, such as multithreaded
  75. programming and multidimensional arrays. Guile supports many SRFIs, as
  76. documented in detail in @ref{SRFI Support}.
  77. In summary, so far as relationship to the Scheme standards is
  78. concerned, Guile is an R5RS implementation with many extensions, some
  79. of which conform to SRFIs or to the relevant parts of R6RS.
  80. @node Combining with C
  81. @section Combining with C Code
  82. Like a shell, Guile can run interactively---reading expressions from the user,
  83. evaluating them, and displaying the results---or as a script interpreter,
  84. reading and executing Scheme code from a file. Guile also provides an object
  85. library, @dfn{libguile}, that allows other applications to easily incorporate a
  86. complete Scheme interpreter. An application can then use Guile as an extension
  87. language, a clean and powerful configuration language, or as multi-purpose
  88. ``glue'', connecting primitives provided by the application. It is easy to call
  89. Scheme code from C code and vice versa, giving the application designer full
  90. control of how and when to invoke the interpreter. Applications can add new
  91. functions, data types, control structures, and even syntax to Guile, creating a
  92. domain-specific language tailored to the task at hand, but based on a robust
  93. language design.
  94. This kind of combination is helped by four aspects of Guile's design
  95. and history. First is that Guile has always been targeted as an
  96. extension language. Hence its C API has always been of great
  97. importance, and has been developed accordingly. Second and third are
  98. rather technical points---that Guile uses conservative garbage
  99. collection, and that it implements the Scheme concept of continuations
  100. by copying and reinstating the C stack---but whose practical
  101. consequence is that most existing C code can be glued into Guile as
  102. is, without needing modifications to cope with strange Scheme
  103. execution flows. Last is the module system, which helps extensions to
  104. coexist without stepping on each others' toes.
  105. Guile's module system allows one to break up a large program into
  106. manageable sections with well-defined interfaces between them.
  107. Modules may contain a mixture of interpreted and compiled code; Guile
  108. can use either static or dynamic linking to incorporate compiled code.
  109. Modules also encourage developers to package up useful collections of
  110. routines for general distribution; as of this writing, one can find
  111. Emacs interfaces, database access routines, compilers, @acronym{GUI}
  112. toolkit interfaces, and @acronym{HTTP} client functions, among others.
  113. @node Guile and the GNU Project
  114. @section Guile and the GNU Project
  115. Guile was conceived by the GNU Project following the fantastic success
  116. of Emacs Lisp as an extension language within Emacs. Just as Emacs
  117. Lisp allowed complete and unanticipated applications to be written
  118. within the Emacs environment, the idea was that Guile should do the
  119. same for other GNU Project applications. This remains true today.
  120. The idea of extensibility is closely related to the GNU project's
  121. primary goal, that of promoting software freedom. Software freedom
  122. means that people receiving a software package can modify or enhance
  123. it to their own desires, including in ways that may not have occurred
  124. at all to the software's original developers. For programs written in
  125. a compiled language like C, this freedom covers modifying and
  126. rebuilding the C code; but if the program also provides an extension
  127. language, that is usually a much friendlier and lower-barrier-of-entry
  128. way for the user to start making their own changes.
  129. Guile is now used by GNU project applications such as AutoGen, Lilypond, Denemo,
  130. Mailutils, TeXmacs and Gnucash, and we hope that there will be many more in
  131. future.
  132. @node Interactive Programming
  133. @section Interactive Programming
  134. Non-free software has no interest in its users being able to see how it works.
  135. They are supposed to just accept it, or to report problems and hope that the
  136. source code owners will choose to work on them.
  137. Free software aims to work reliably just as much as non-free software does, but
  138. it should also empower its users by making its workings available. This is
  139. useful for many reasons, including education, auditing and enhancements, as well
  140. as for debugging problems.
  141. The ideal free software system achieves this by making it easy for interested
  142. users to see the source code for a feature that they are using, and to follow
  143. through that source code step-by-step, as it runs. In Emacs, good examples of
  144. this are the source code hyperlinks in the help system, and @code{edebug}.
  145. Then, for bonus points and maximising the ability for the user to experiment
  146. quickly with code changes, the system should allow parts of the source code to
  147. be modified and reloaded into the running program, to take immediate effect.
  148. Guile is designed for this kind of interactive programming, and this
  149. distinguishes it from many Scheme implementations that instead prioritise
  150. running a fixed Scheme program as fast as possible---because there are
  151. tradeoffs between performance and the ability to modify parts of an already
  152. running program. There are faster Schemes than Guile, but Guile is a GNU
  153. project and so prioritises the GNU vision of programming freedom and
  154. experimentation.
  155. @node Supporting Multiple Languages
  156. @section Supporting Multiple Languages
  157. Since the 2.0 release, Guile's architecture supports compiling any language to
  158. its core virtual machine bytecode, and Scheme is just one of the supported
  159. languages. Other supported languages are Emacs Lisp, ECMAScript (commonly known
  160. as Javascript) and Brainfuck, and work is under discussion for Lua, Ruby and
  161. Python.
  162. This means that users can program applications which use Guile in the language
  163. of their choice, rather than having the tastes of the application's author
  164. imposed on them.
  165. @node Obtaining and Installing Guile
  166. @section Obtaining and Installing Guile
  167. Guile can be obtained from the main GNU archive site
  168. @url{ftp://ftp.gnu.org} or any of its mirrors. The file will be named
  169. guile-@var{version}.tar.gz. The current version is @value{VERSION}, so the
  170. file you should grab is:
  171. @url{ftp://ftp.gnu.org/gnu/guile/guile-@value{VERSION}.tar.gz}
  172. To unbundle Guile use the instruction
  173. @example
  174. zcat guile-@value{VERSION}.tar.gz | tar xvf -
  175. @end example
  176. @noindent
  177. which will create a directory called @file{guile-@value{VERSION}} with
  178. all the sources. You can look at the file @file{INSTALL} for detailed
  179. instructions on how to build and install Guile, but you should be able
  180. to just do
  181. @example
  182. cd guile-@value{VERSION}
  183. ./configure
  184. make
  185. make install
  186. @end example
  187. This will install the Guile executable @file{guile}, the Guile library
  188. @file{libguile} and various associated header files and support libraries. It
  189. will also install the Guile reference manual.
  190. @c [[include instructions for getting R5RS]]
  191. Since this manual frequently refers to the Scheme ``standard'', also
  192. known as R5RS, or the
  193. @tex
  194. ``Revised$^5$ Report on the Algorithmic Language Scheme'',
  195. @end tex
  196. @ifnottex
  197. ``Revised^5 Report on the Algorithmic Language Scheme'',
  198. @end ifnottex
  199. we have included the report in the Guile distribution; see
  200. @ref{Top, , Introduction, r5rs, Revised(5) Report on the Algorithmic
  201. Language Scheme}.
  202. This will also be installed in your info directory.
  203. @node Organisation of this Manual
  204. @section Organisation of this Manual
  205. The rest of this manual is organised into the following chapters.
  206. @table @strong
  207. @item Chapter 2: Hello Guile!
  208. A whirlwind tour shows how Guile can be used interactively and as
  209. a script interpreter, how to link Guile into your own applications,
  210. and how to write modules of interpreted and compiled code for use with
  211. Guile. Everything introduced here is documented again and in full by
  212. the later parts of the manual.
  213. @item Chapter 3: Hello Scheme!
  214. For readers new to Scheme, this chapter provides an introduction to the basic
  215. ideas of the Scheme language. This material would apply to any Scheme
  216. implementation and so does not make reference to anything Guile-specific.
  217. @item Chapter 4: Programming in Scheme
  218. Provides an overview of programming in Scheme with Guile. It covers how to
  219. invoke the @code{guile} program from the command-line and how to write scripts
  220. in Scheme. It also introduces the extensions that Guile offers beyond standard
  221. Scheme.
  222. @item Chapter 5: Programming in C
  223. Provides an overview of how to use Guile in a C program. It
  224. discusses the fundamental concepts that you need to understand to
  225. access the features of Guile, such as dynamic types and the garbage
  226. collector. It explains in a tutorial like manner how to define new
  227. data types and functions for the use by Scheme programs.
  228. @item Chapter 6: Guile API Reference
  229. This part of the manual documents the Guile @acronym{API} in
  230. functionality-based groups with the Scheme and C interfaces presented
  231. side by side.
  232. @item Chapter 7: Guile Modules
  233. Describes some important modules, distributed as part of the Guile
  234. distribution, that extend the functionality provided by the Guile
  235. Scheme core.
  236. @item Chapter 8: GOOPS
  237. Describes GOOPS, an object oriented extension to Guile that provides
  238. classes, multiple inheritance and generic functions.
  239. @end table
  240. @node Typographical Conventions
  241. @section Typographical Conventions
  242. We use some conventions in this manual.
  243. @itemize @bullet
  244. @item
  245. For some procedures, notably type predicates, we use ``iff'' to mean
  246. ``if and only if''. The construct is usually something like: `Return
  247. @var{val} iff @var{condition}', where @var{val} is usually
  248. ``@nicode{#t}'' or ``non-@nicode{#f}''. This typically means that
  249. @var{val} is returned if @var{condition} holds, and that @samp{#f} is
  250. returned otherwise. To clarify: @var{val} will @strong{only} be
  251. returned when @var{condition} is true.
  252. @cindex iff
  253. @item
  254. In examples and procedure descriptions and all other places where the
  255. evaluation of Scheme expression is shown, we use some notation for
  256. denoting the output and evaluation results of expressions.
  257. The symbol @samp{@result{}} is used to tell which value is returned by
  258. an evaluation:
  259. @lisp
  260. (+ 1 2)
  261. @result{} 3
  262. @end lisp
  263. Some procedures produce some output besides returning a value. This
  264. is denoted by the symbol @samp{@print{}}.
  265. @lisp
  266. (begin (display 1) (newline) 'hooray)
  267. @print{} 1
  268. @result{} hooray
  269. @end lisp
  270. As you can see, this code prints @samp{1} (denoted by
  271. @samp{@print{}}), and returns @code{hooray} (denoted by
  272. @samp{@result{}}).
  273. @c Add other conventions here.
  274. @end itemize
  275. @c Local Variables:
  276. @c TeX-master: "guile.texi"
  277. @c End: