old-intro.texi 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. @node Introduction
  2. @chapter Introduction
  3. Guile is an interpreter for Scheme, a clean, economical programming
  4. language in the Lisp family. You can invoke Guile from the shell to
  5. evaluate Scheme expressions interactively, or use it as an interpreter
  6. for script files. However, Guile is also packaged as a library, to be
  7. embedded as an extension language into other applications. The
  8. application can supplement the base language with special-purpose
  9. functions and datatypes, allowing the user to customize and extend it by
  10. writing Scheme code.
  11. In its simplest form, Guile is an ordinary interpreter. The
  12. @code{guile} program can read and evaluate Scheme expressions entered
  13. from the terminal. Here is a sample interaction between Guile and a
  14. user; the user's input appears after the @code{$} and @code{guile>}
  15. prompts:
  16. @example
  17. $ guile
  18. guile> (+ 1 2 3) ; add some numbers
  19. 6
  20. guile> (define (factorial n) ; define a function
  21. (if (zero? n) 1 (* n (factorial (- n 1)))))
  22. guile> (factorial 20)
  23. 2432902008176640000
  24. guile> (getpwnam "jimb") ; find my entry in /etc/passwd
  25. #("jimb" ".0krIpK2VqNbU" 4008 10 "Jim Blandy" "/u/jimb"
  26. "/usr/local/bin/bash")
  27. guile> @kbd{C-d}
  28. $
  29. @end example
  30. Guile can also interpret script files. For example, here is a Guile script
  31. containing a script which displays the
  32. application can
  33. supplement the base language with its own functions, datatypes and
  34. syntax, allowing the user to extend and
  35. Guile interpret
  36. . An
  37. application the Guile interpreter to allow
  38. , allowing
  39. applications to incorporate the Scheme interpreter for customization
  40. [[interactive]]
  41. [[script interpreter]]
  42. [[embedded]]
  43. [[other languages]]
  44. The concept of an extension language library does not originate with
  45. Guile. However, Guile is the first to offer users a choice of languages
  46. to program in.
  47. Guile currently supports Scheme and Ctax , and we expect to support Emacs Lisp in the near future.
  48. Scheme is powerful enough that other languages can be
  49. conveniently translated into it,
  50. However, unlike other extension packages, Guile gives users a choice of
  51. languages to program in. Guile can
  52. In this sense, Guile resembles the Tcl and Python packages, providing
  53. both an ordinary interpreter and an extension language library.
  54. However, unlike those packages, Guile supports more than one programming
  55. language.
  56. ; users can
  57. write Scheme code to control and customize applications which
  58. incorporate Guile
  59. , adding their own functions,
  60. datatypes, and syntax, to allow the user to programm
  61. link it into your own programs to make them
  62. Guile is a library containing an interpreter for Scheme, a complete but
  63. economical programming language, which the developer can customize to
  64. suit the application at hand by adding new functions, data types, and
  65. control structures. These may be implemented in C, and then
  66. ``exported'' for use by the interpreted code. Because Guile already
  67. provides a full-featured interpreter, the developer need not neglect the
  68. language's design in order to concentrate on code relevant to the task.
  69. In this way, Guile provides a framework for the construction of
  70. domain-specific languages.
  71. Guile provides first-class functions, a rich set of data types,
  72. exception handling, a module system, and a powerful macro facility.
  73. Guile also supports dynamic linking and direct access to Unix system
  74. calls. Releases in the near future will support a source-level
  75. debugger and bindings for the Tk user interface toolkit.
  76. Guile is a framework for writing applications controlled by specialized
  77. languages. In its simplest form, Guile is an interpreter for Scheme, a
  78. clean, economical programming language in the Lisp family. However,
  79. Guile is packaged as a library, allowing applications to link against it
  80. and use Scheme as their extension language. The application can add
  81. primitive functions to the language, implement new data types, and even
  82. adjust the language's syntax.
  83. [the introduction is probably not what Jim has in mind; I just took the
  84. one I had in earlier, since the file had the same name intro.texi]
  85. Guile is an implementation of the Scheme programming language, but, like
  86. other modern implementations of Scheme, it adds many features that the
  87. community of Scheme programmers considers necessary for an ``industrial
  88. strength'' language.
  89. Examples of extensions to Scheme are the module system
  90. (@pxref{Modules}), the Unix system programming tools (@pxref{POSIX
  91. system calls and networking} and @pxref{The Scheme shell (scsh)}), an
  92. interface to @emph{libtool} to make it easier to add C libraries as
  93. primitives (@pxref{Linking Guile with your code}), and (FIXME add more).
  94. On top of these extensions, which many other Scheme implementations
  95. provide, Guile also offers the possibility of writing routines in other
  96. languages and running them simultaneously with Scheme. The desire to
  97. implement other languages (in particular Emacs Lisp) on top of Scheme is
  98. responsible for Guile's only deviation from the R4RS @footnote{R4RS is
  99. the Revised^4 Report on the Algorithmic Language Scheme, the closest
  100. thing to a standard Scheme specification today} Scheme standard
  101. (@cite{r4rs}): Guile is case sensitive, whereas ``standard'' Scheme is
  102. not.
  103. But even more fundamentally, Guile is meant to be an @emph{embeddable}
  104. Scheme interpreter. This means that a lot of work has gone into
  105. packaging the interpreter as a C library (@pxref{A Portable C to Scheme Interface} and @pxref{Scheme data representation}).
  106. This reference manual is mainly driven by the need to document all the
  107. features that go beyond standard Scheme.
  108. @menu
  109. * Getting started::
  110. * Guile feature list::
  111. * What you need to use Guile::
  112. * Roadmap to the Manual::
  113. * Motivation for Guile::
  114. * History of Guile::
  115. @end menu
  116. @node Getting started
  117. @section Getting started
  118. We assume that you know how to program in Scheme, although we do not
  119. assume advanced knowledge. If you don't know Scheme, there are many
  120. good books on Scheme at all levels, and the Guile Tutorial might give
  121. you a good enough feel for the language. We also assume that you know
  122. how to program in C, since there will be many examples of how to program
  123. in C using Guile as a library.
  124. Many diverse topics from the world of Unix hacking will be covered here,
  125. such as shared libraries, socket programming, garbage collection, and so
  126. forth. If at any time you feel you don't have enough background on a
  127. given topic, just go up a level or two in the manual, and you will find
  128. that the chapter begins with a few paragraphs that introduce the topic.
  129. If you are still lost, read through the Guile tutorial and then come
  130. back to this reference manual.
  131. To run the core Guile interpreter and extension library you need no more
  132. than a basically configured GNU/Unix system and the Guile sources. You
  133. should download and install the Guile sources (@pxref{Obtaining and
  134. Installing Guile}).
  135. @node Guile feature list
  136. @section Guile feature list
  137. In a reductionist view, Guile could be regarded as:
  138. @itemize @bullet
  139. @item
  140. An R4RS-compliant Scheme interpreter.
  141. @item
  142. Some Scheme features that go beyond the R4RS standard, notably a module
  143. system, exception handling primitives and an interface to Aubrey
  144. Jaffer's SLIB.
  145. @item
  146. A symbolic debugger for Scheme, and gdb extensions to facilitate
  147. debugging libguile programs.
  148. @item
  149. An embeddable version of the same interpreter, called @emph{libguile}.
  150. @item
  151. A portable high level API on top of libguile (the @code{gh_} interface).
  152. @item
  153. A collection of bundled C libraries with a Guile API. As we write, this
  154. list includes:
  155. @table @strong
  156. @item Rx
  157. a regular expression library.
  158. @item Unix
  159. a low-level interface to the POSIX system calls, socket library
  160. and other Unix system services.
  161. @item Tk
  162. an interface to John Ousterhout's Tk toolkit.
  163. @end table
  164. @item
  165. A set of tools for implementing other languages @emph{on top of Scheme},
  166. and an example implementation of a language called @emph{Ctax}.
  167. @end itemize
  168. @node What you need to use Guile
  169. @section What you need to use Guile
  170. @node Roadmap to the Manual
  171. @section Roadmap to the Manual
  172. @node Motivation for Guile
  173. @section Motivation for Guile
  174. @node History of Guile
  175. @section History of Guile
  176. @page
  177. @node Using Guile
  178. @chapter Using Guile
  179. [I think that this might go in the appendix in Jim's view of the manual]
  180. @page
  181. @node Invoking Guile
  182. @appendix Invoking Guile
  183. --- mentions read-eval-print loops
  184. --- both the SCSH and GAWK manuals relegate invocation details
  185. to an appendix. We can give examples in the introduction.
  186. @table @samp
  187. @item -h
  188. @itemx --help
  189. Display a helpful message.
  190. @item -v
  191. @item --version
  192. Display the current version.
  193. @item --emacs
  194. To be used for emacs editing support.
  195. @item -s @var{file}
  196. Process @var{file} as a script then quit. This is a terminating option:
  197. any further command line arguments can be accessed by the script using
  198. the @code{(program-arguments)} procedure.
  199. An executable script can start with the following:
  200. @smallexample
  201. #!/usr/bin/guile -s
  202. !#
  203. @end smallexample
  204. Note the @code{!#} token on the second line. It is very important
  205. to include this token when writing Guile scripts. Guile and SCSH,
  206. the Scheme shell, share the convention that @code{#!} and
  207. @code{!#} may be used to mark block comments (@pxref{Block
  208. comments and interpreter triggers}). If the closing @code{!#}
  209. token is not included, then Guile will consider the block comment
  210. to be unclosed, and the script will probably not compile
  211. correctly.
  212. It is also important to include the @samp{-s} option at the
  213. beginning of the Guile script, so that Guile knows not to behave
  214. in an interactive fashion.
  215. @end table