3 @chapter What is Guile?
5 Guile is an interpreter for the Scheme programming language, packaged
6 for use in a wide variety of environments. Guile implements Scheme as
14 Report on the Algorithmic Language Scheme (usually known as @acronym{R5RS}),
15 providing clean and general data and control structures. Guile goes
16 beyond the rather austere language presented in @acronym{R5RS}, extending it with
17 a module system, full access to @acronym{POSIX} system calls, networking support,
18 multiple threads, dynamic linking, a foreign function call interface,
19 powerful string processing, and many other features needed for
20 programming in the real world.
22 Like a shell, Guile can run interactively, reading expressions from the
23 user, evaluating them, and displaying the results, or as a script
24 interpreter, reading and executing Scheme code from a file. However,
25 Guile is also packaged as an object library, allowing other applications
26 to easily incorporate a complete Scheme interpreter. An application can
27 then use Guile as an extension language, a clean and powerful configuration
28 language, or as multi-purpose ``glue'', connecting primitives provided
29 by the application. It is easy to call Scheme code from C code and vice
30 versa, giving the application designer full control of how and when to
31 invoke the interpreter. Applications can add new functions, data types,
32 control structures, and even syntax to Guile, creating a domain-specific
33 language tailored to the task at hand, but based on a robust language
36 Guile's module system allows one to break up a large program into
37 manageable sections with well-defined interfaces between them.
38 Modules may contain a mixture of interpreted and compiled code; Guile
39 can use either static or dynamic linking to incorporate compiled code.
40 Modules also encourage developers to package up useful collections of
41 routines for general distribution; as of this writing, one can find
42 Emacs interfaces, database access routines, compilers, @acronym{GUI}
43 toolkit interfaces, and @acronym{HTTP} client functions, among others.
45 In the future, we hope to expand Guile to support other languages like
46 Tcl and Perl by translating them to Scheme code. This means that users
47 can program applications which use Guile in the language of their
48 choice, rather than having the tastes of the application's author
54 @chapter A Whirlwind Tour
56 This chapter presents a quick tour of all the ways that Guile can be
57 used. There are additional examples in the @file{examples/}
58 directory in the Guile source distribution.
61 * Running Guile Interactively::
63 * Linking Programs With Guile::
64 * Writing Extensions for Guile::
69 @node Running Guile Interactively
70 @section Running Guile Interactively
72 In its simplest form, Guile acts as an interactive interpreter for the
73 Scheme programming language, reading and evaluating Scheme expressions
74 the user enters from the terminal. Here is a sample interaction between
75 Guile and a user; the user's input appears after the @code{$} and
76 @code{guile>} prompts:
80 guile> (+ 1 2 3) ; add some numbers
82 guile> (define (factorial n) ; define a function
83 (if (zero? n) 1 (* n (factorial (- n 1)))))
86 guile> (getpwnam "jimb") ; find my entry in /etc/passwd
87 #("jimb" ".0krIpK2VqNbU" 4008 10 "Jim Blandy" "/u/jimb"
88 "/usr/local/bin/bash")
93 @c [[When we get a fancier read-eval-print loop, with features for bouncing
94 @c around among modules, referring to the value of the last expression,
95 @c etc. then this section will get longer.]]
99 @section Guile Scripts
101 Like AWK, Perl, or any shell, Guile can interpret script files. A Guile
102 script is simply a file of Scheme code with some extra information at
103 the beginning which tells the operating system how to invoke Guile, and
104 then tells Guile how to handle the Scheme code.
106 Before we present the details, here is a trivial Guile script:
109 #!/usr/local/bin/guile -s
111 (display "Hello, world!")
116 * The Top of a Script File:: How to start a Guile script.
117 * Scripting Examples:: Simple Guile scripts, explained.
121 @node The Top of a Script File
122 @subsection The Top of a Script File
124 The first line of a Guile script must tell the operating system to use
125 Guile to evaluate the script, and then tell Guile how to go about doing
126 that. Here is the simplest case:
131 The first two characters of the file must be @samp{#!}.
133 The operating system interprets this to mean that the rest of the line
134 is the name of an executable that can interpret the script. Guile,
135 however, interprets these characters as the beginning of a multi-line
136 comment, terminated by the characters @samp{!#} on a line by themselves.
137 (This is an extension to the syntax described in R5RS, added to support
141 Immediately after those two characters must come the full pathname to
142 the Guile interpreter. On most systems, this would be
143 @samp{/usr/local/bin/guile}.
146 Then must come a space, followed by a command-line argument to pass to
147 Guile; this should be @samp{-s}. This switch tells Guile to run a
148 script, instead of soliciting the user for input from the terminal.
149 There are more elaborate things one can do here; see @ref{The Meta
153 Follow this with a newline.
156 The second line of the script should contain only the characters
157 @samp{!#} --- just like the top of the file, but reversed. The
158 operating system never reads this far, but Guile treats this as the end
159 of the comment begun on the first line by the @samp{#!} characters.
162 The rest of the file should be a Scheme program.
166 Guile reads the program, evaluating expressions in the order that they
167 appear. Upon reaching the end of the file, Guile exits.
169 The function @code{command-line} returns the name of the script file and
170 any command-line arguments passed by the user, as a list of strings.
172 For example, consider the following script file:
174 #!/usr/local/bin/guile -s
176 (write (command-line))
180 If you put that text in a file called @file{foo} in the current
181 directory, then you could make it executable and try it out like this:
187 ("./foo" "bar" "baz")
191 As another example, here is a simple replacement for the POSIX
194 #!/usr/local/bin/guile -s
196 (for-each (lambda (s) (display s) (display " "))
197 (cdr (command-line)))
201 @deffn {Scheme Procedure} command-line
202 @deffnx {Scheme Procedure} program-arguments
203 Return a list of the command-line arguments passed to the currently
204 running program. If the program invoked Guile with the @samp{-s},
205 @samp{-c} or @samp{--} switches, these procedures ignore everything up
206 to and including those switches.
210 @node Scripting Examples
211 @subsection Scripting Examples
213 To start with, here are some examples of invoking Guile directly:
218 Run Guile interactively; @code{(command-line)} will return @*
219 @code{("/usr/local/bin/guile" "a" "b" "c")}.
221 @item guile -s /u/jimb/ex2 a b c
222 Load the file @file{/u/jimb/ex2}; @code{(command-line)} will return @*
223 @code{("/u/jimb/ex2" "a" "b" "c")}.
225 @item guile -c '(write %load-path) (newline)'
226 Write the value of the variable @code{%load-path}, print a newline,
229 @item guile -e main -s /u/jimb/ex4 foo
230 Load the file @file{/u/jimb/ex4}, and then call the function
231 @code{main}, passing it the list @code{("/u/jimb/ex4" "foo")}.
233 @item guile -l first -ds -l last -s script
234 Load the files @file{first}, @file{script}, and @file{last}, in that
235 order. The @code{-ds} switch says when to process the @code{-s}
236 switch. For a more motivated example, see the scripts below.
241 Here is a very simple Guile script:
243 #!/usr/local/bin/guile -s
245 (display "Hello, world!")
248 The first line marks the file as a Guile script. When the user invokes
249 it, the system runs @file{/usr/local/bin/guile} to interpret the script,
250 passing @code{-s}, the script's filename, and any arguments given to the
251 script as command-line arguments. When Guile sees @code{-s
252 @var{script}}, it loads @var{script}. Thus, running this program
258 Here is a script which prints the factorial of its argument:
260 #!/usr/local/bin/guile -s
264 (* n (fact (- n 1)))))
266 (display (fact (string->number (cadr (command-line)))))
276 However, suppose we want to use the definition of @code{fact} in this
277 file from another script. We can't simply @code{load} the script file,
278 and then use @code{fact}'s definition, because the script will try to
279 compute and display a factorial when we load it. To avoid this problem,
280 we might write the script this way:
283 #!/usr/local/bin/guile \
288 (* n (fact (- n 1)))))
291 (display (fact (string->number (cadr args))))
294 This version packages the actions the script should perform in a
295 function, @code{main}. This allows us to load the file purely for its
296 definitions, without any extraneous computation taking place. Then we
297 used the meta switch @code{\} and the entry point switch @code{-e} to
298 tell Guile to call @code{main} after loading the script.
301 30414093201713378043612608166064768844377641568960512000000000000
304 Suppose that we now want to write a script which computes the
305 @code{choose} function: given a set of @var{m} distinct objects,
306 @code{(choose @var{n} @var{m})} is the number of distinct subsets
307 containing @var{n} objects each. It's easy to write @code{choose} given
308 @code{fact}, so we might write the script this way:
310 #!/usr/local/bin/guile \
314 (/ (fact m) (* (fact (- m n)) (fact n))))
317 (let ((n (string->number (cadr args)))
318 (m (string->number (caddr args))))
319 (display (choose n m))
323 The command-line arguments here tell Guile to first load the file
324 @file{fact}, and then run the script, with @code{main} as the entry
325 point. In other words, the @code{choose} script can use definitions
326 made in the @code{fact} script. Here are some sample runs:
339 100891344545564193334812497256
343 @node Linking Programs With Guile
344 @section Linking Programs With Guile
346 The Guile interpreter is available as an object library, to be linked
347 into applications using Scheme as a configuration or extension
348 language. This chapter covers the mechanics of linking your program
349 with Guile on a typical POSIX system.
351 Parts III and IV of this manual describe the C functions Guile provides.
352 Furthermore, any Scheme function described in this manual as a
353 ``Primitive'' is also callable from C; see @ref{Primitives}.
355 The header file @code{<libguile.h>} provides declarations for all of
356 Guile's functions and constants. You should @code{#include} it at the
357 head of any C source file that uses identifiers described in this
358 manual. Once you've compiled your source files, you need to link them
359 against the Guile object code library, @code{libguile}.
361 On most systems, you should not need to tell the compiler and linker
362 explicitly where they can find @file{libguile.h} and @file{libguile}.
363 When Guile has been installed in a peculiar way, or when you are on a
364 peculiar system, things might not be so easy and you might need to pass
365 additional @code{-I} or @code{-L} options to the compiler. Guile
366 provides the utility program @code{guile-config} to help you find the
367 right values for these options. You would typically run
368 @code{guile-config} during the configuration phase of your program and
369 use the obtained information in the Makefile.
372 * Guile Initialization Functions:: What to call first.
373 * A Sample Guile Main Program:: Sources and makefiles.
377 @node Guile Initialization Functions
378 @subsection Guile Initialization Functions
380 To initialize Guile, you can use one of two functions. The first,
381 @code{scm_boot_guile}, is the most portable way to initialize Guile. It
382 should be used whenever you have control over the main function of your
383 program because it never returns. The second function,
384 @code{scm_init_guile}, does return and can thus be used in more
385 situations. However, @code{scm_init_guile} is not as widely available
386 as @code{scm_boot_guile} because it needs to rely on non-portable code
387 to find the stack bounds. When Guile does not know how to find these
388 bounds on your system, it will not provide @code{scm_init_guile}.
390 When you can tolerate the limits of @code{scm_boot_guile}, you should
391 use it in favor of @code{scm_init_guile} since that will make your
392 program more portable.
394 @deftypefun void scm_boot_guile (int @var{argc}, char **@var{argv}, void (*@var{main_func}) (), void *@var{closure})
395 Initialize the Guile Scheme interpreter. Then call @var{main_func},
396 passing it @var{closure}, @var{argc}, and @var{argv}. @var{main_func}
397 should do all the work of the program (initializing other packages,
398 defining application-specific functions, reading user input, and so on)
399 before returning. When @var{main_func} returns, call @code{exit (0)};
400 @code{scm_boot_guile} never returns. If you want some other exit value,
401 have @var{main_func} call exit itself.
403 @code{scm_boot_guile} arranges for the Scheme @code{command-line}
404 function to return the strings given by @var{argc} and @var{argv}. If
405 @var{main_func} modifies @var{argc} or @var{argv}, it should call
406 @code{scm_set_program_arguments} with the final list, so Scheme code
407 will know which arguments have been processed.
409 Why must the caller do all the real work from @var{main_func}? Guile's
410 garbage collector scans the stack to find all local variables that
411 reference Scheme objects. To do this, it needs to know the bounds of
412 the stack that might contain such references. Because there is no
413 portable way in C to find the base of the stack, @code{scm_boot_guile}
414 assumes that all references are above its own stack frame. If you try
415 to manipulate Scheme objects after this function returns, it's the luck
416 of the draw whether Guile's storage manager will be able to find the
417 objects you allocate. So, @code{scm_boot_guile} function exits, rather
418 than returning, to discourage you from making that mistake.
420 See @code{scm_init_guile}, below, for a function that can find the real
421 base of the stack, but not in a portable way.
424 @deftypefun void scm_init_guile ()
425 Initialize the Guile Scheme interpreter.
427 In contrast to @code{scm_boot_guile}, this function knows how to find
428 the true base of the stack and thus does not need to usurp the control
429 flow of your program. However, since finding the stack base can not be
430 done portably, this function might not be available in all installations
431 of Guile. If you can, you should use @code{scm_boot_guile} instead.
433 Note that @code{scm_init_guile} does not inform Guile about the command
434 line arguments that should be returned by the Scheme function
435 @code{command-line}. You can use @code{scm_set_program_arguments} to do
439 One common way to use Guile is to write a set of C functions which
440 perform some useful task, make them callable from Scheme, and then link
441 the program with Guile. This yields a Scheme interpreter just like
442 @code{guile}, but augmented with extra functions for some specific
443 application --- a special-purpose scripting language.
445 In this situation, the application should probably process its
446 command-line arguments in the same manner as the stock Guile
447 interpreter. To make that straightforward, Guile provides this
450 @deftypefun void scm_shell (int @var{argc}, char **@var{argv})
451 Process command-line arguments in the manner of the @code{guile}
452 executable. This includes loading the normal Guile initialization
453 files, interacting with the user or running any scripts or expressions
454 specified by @code{-s} or @code{-e} options, and then exiting.
455 @xref{Invoking Guile}, for more details.
457 Since this function does not return, you must do all
458 application-specific initialization before calling this function.
462 @node A Sample Guile Main Program
463 @subsection A Sample Guile Main Program
465 Here is @file{simple-guile.c}, source code for a @code{main} and an
466 @code{inner_main} function that will produce a complete Guile
470 /* simple-guile.c --- how to start up the Guile
471 interpreter from C code. */
473 /* Get declarations for all the scm_ functions. */
474 #include <libguile.h>
477 inner_main (void *closure, int argc, char **argv)
479 /* module initializations would go here */
480 scm_shell (argc, argv);
484 main (int argc, char **argv)
486 scm_boot_guile (argc, argv, inner_main, 0);
487 return 0; /* never reached */
491 The @code{main} function calls @code{scm_boot_guile} to initialize
492 Guile, passing it @code{inner_main}. Once @code{scm_boot_guile} is
493 ready, it invokes @code{inner_main}, which calls @code{scm_shell} to
494 process the command-line arguments in the usual way.
496 Here is a Makefile which you can use to compile the above program. It
497 uses @code{guile-config} to learn about the necessary compiler and
500 # Use GCC, if you have it installed.
503 # Tell the C compiler where to find <libguile.h>
504 CFLAGS=`guile-config compile`
506 # Tell the linker what libraries to use and where to find them.
507 LIBS=`guile-config link`
509 simple-guile: simple-guile.o
510 $@{CC@} simple-guile.o $@{LIBS@} -o simple-guile
512 simple-guile.o: simple-guile.c
513 $@{CC@} -c $@{CFLAGS@} simple-guile.c
516 If you are using the GNU Autoconf package to make your application more
517 portable, Autoconf will settle many of the details in the Makefile above
518 automatically, making it much simpler and more portable; we recommend
519 using Autoconf with Guile. Guile also provides the @code{GUILE_FLAGS}
520 macro for autoconf that performs all necessary checks. Here is a
521 @file{configure.in} file for @code{simple-guile} that uses this macro.
522 Autoconf can use as this file as template to generate a @code{configure}
523 script. In order for Autoconf to find the @code{GUILE_FLAGS} macro, you
524 will need to run @code{aclocal} first. This is not really Guile
525 specific, so you should refer to the Autoconf documentation REFFIXME
528 AC_INIT(simple-guile.c)
536 # Generate a Makefile, based on the results.
540 Here is a @code{Makefile.in} template, from which the @code{configure}
541 script produces a Makefile customized for the host system:
543 # The configure script fills in these values.
545 CFLAGS=@@GUILE_CFLAGS@@
546 LIBS=@@GUILE_LDFLAGS@@
548 simple-guile: simple-guile.o
549 $@{CC@} simple-guile.o $@{LIBS@} -o simple-guile
550 simple-guile.o: simple-guile.c
551 $@{CC@} -c $@{CFLAGS@} simple-guile.c
554 The developer should use Autoconf to generate the @file{configure}
555 script from the @file{configure.in} template, and distribute
556 @file{configure} with the application. Here's how a user might go about
557 building the application:
561 Makefile.in configure* configure.in simple-guile.c
563 creating cache ./config.cache
564 checking for gcc... (cached) gcc
565 checking whether the C compiler (gcc ) works... yes
566 checking whether the C compiler (gcc ) is a cross-compiler... no
567 checking whether we are using GNU C... (cached) yes
568 checking whether gcc accepts -g... (cached) yes
569 checking for Guile... yes
570 creating ./config.status
573 gcc -c -I/usr/local/include simple-guile.c
574 gcc simple-guile.o -L/usr/local/lib -lguile -lqthreads -lpthread -lm -o simple-guile
578 guile> (getpwnam "jimb")
579 #("jimb" "83Z7d75W2tyJQ" 4008 10 "Jim Blandy" "/u/jimb"
580 "/usr/local/bin/bash")
586 @node Writing Extensions for Guile
587 @section Writing Extensions for Guile
589 The previous sections have briefly explained how to write programs that
590 make use of an embedded Guile interpreter. But sometimes, all you want
591 to do is make new primitive procedures and data types available to the
592 Scheme programmer. Writing a new version of @code{guile} is
593 inconvenient in this case and it would in fact make the life of the
594 users of your new features needlessly hard.
596 @c [[ the following is probably a bit long-winded ]]
598 For example, suppose that there is a program @code{guile-db} that is a
599 version of Guile with additional features for accessing a database.
600 People who want to write Scheme programs that use these features would
601 have to use @code{guile-db} instead of the usual @code{guile} program.
602 Now suppose that there is also a program @code{guile-gtk} that extends
603 Guile with access to the popular Gtk+ toolkit for graphical user
604 interfaces. People who want to write GUIs in Scheme would have to use
605 @code{guile-gtk}. Now, what happens when you want to write a Scheme
606 application that uses a GUI to let the user access a database? You
607 would have to write a @emph{third} program that incorporates both the
608 database stuff and the GUI stuff. This might not be easy (because
609 @code{guile-gtk} might be a quite obscure program, say) and taking this
610 example further makes it easy to see that this approach can not work in
613 It would have been much better if both the database features and the GUI
614 feature had been provided as libraries that can just be linked with
615 @code{guile}. Guile makes it easy to do just this, and we encourage you
616 to make your extensions to Guile available as libraries whenever
619 You write the new primitive procedures and data types in the normal
620 fashion, and link them into a shared library instead of into a
621 stand-alone program. The shared library can then be loaded dynamically
625 * A Sample Guile Extension::
629 @node A Sample Guile Extension
630 @subsection A Sample Guile Extension
632 This section explains how to make the Bessel functions of the C library
633 available to Scheme. First we need to write the appropriate glue code
634 to convert the arguments and return values of the functions from Scheme
635 to C and back. Additionally, we need a function that will add them to
636 the set of Guile primitives. Because this is just an example, we will
637 only implement this for the @code{j0} function.
639 Consider the following file @file{bessel.c}.
643 #include <libguile.h>
648 return scm_make_real (j0 (scm_num2dbl (x, "j0")));
654 scm_c_define_gsubr ("j0", 1, 0, 0, j0_wrapper);
658 This C source file needs to be compiled into a shared library. Here is
659 how to do it on GNU/Linux:
662 gcc -shared -o libguile-bessel.so -fPIC bessel.c
665 For creating shared libraries portably, we recommend the use of
668 A shared library can be loaded into a running Guile process with the
669 function @code{load-extension}. In addition to the name of the
670 library to load, this function also expects the name of function from
671 that library that will be called to initialize it. For our example,
672 we are going to call the function @code{init_bessel} which will make
673 @code{j0_wrapper} available to Scheme programs with the name
674 @code{j0}. Note that we do not specify a filename extension such as
675 @file{.so} when invoking @code{load-extension}. The right extension for
676 the host platform will be provided automatically.
679 (load-extension "libguile-bessel" "init_bessel")
681 @result{} 0.223890779141236
684 For this to work, @code{load-extension} must be able to find
685 @file{libguile-bessel}, of course. It will look in the places that
686 are usual for your operating system, and it will additionally look
687 into the directories listed in the @code{LTDL_LIBRARY_PATH}
688 environment variable.
690 To see how these Guile extensions via shared libraries relate to the
691 module system, see below @xref{Intro to Modules and Extensions}.
695 @section Guile Modules
697 Guile has support for dividing a program into @dfn{modules}. By using
698 modules, you can group related code together and manage the
699 composition of complete programs from largely independent parts.
701 (Although the module system implementation is in flux, feel free to use it
702 anyway. Guile will provide reasonable backwards compatibility.)
704 Details on the module system beyond this introductory material can be found in
708 * Intro to Using Guile Modules::
709 * Intro to Writing New Modules::
710 * Intro to Modules and Extensions::
714 @node Intro to Using Guile Modules
715 @subsection Intro to Using Existing Modules
717 Guile comes with a lot of useful modules, for example for string
718 processing or command line parsing. Additionally, there exist many
719 Guile modules written by other Guile hackers, but which have to be
722 Existing modules have to be placed in places where Guile looks for them
723 by default or in colon-separated directories in the environment variable
724 @code{GUILE_LOAD_PATH}. When this variable is set, those directories
725 are searched first, then the the default. The following command
726 shows the complete list of directories searched:
729 guile -c '(write %load-path) (newline)'
732 Suppose you want to use the procedures and variables exported by the
733 module @code{(ice-9 popen)}, which provides the means for communicating
734 with other processes over pipes. Add the following line to your
735 currently running Guile REPL or the top of your script file.
738 (use-modules (ice-9 popen))
741 This will load the module and make the procedures exported by
742 @code{(ice-9 popen)} automatically available. The next step could be
743 to open a pipe to @file{ls} and read the contents of the current
744 directory, one line at a time. For the latter, we use the function
745 @code{read-line}, which can be found in the module @code{(ice-9
746 rdelim)}, so we use that module as well.
749 (use-modules (ice-9 rdelim))
750 (define p (open-input-pipe "ls -l"))
756 "drwxr-sr-x 2 mgrabmue mgrabmue 1024 Mar 29 19:57 CVS"
759 The macro @code{use-modules} can take any number of modules to use.
760 Therefore, we could have written the two @code{use-modules} statements
764 (use-modules (ice-9 popen) (ice-9 rdelim))
767 @node Intro to Writing New Modules
768 @subsection Intro to Writing New Modules
770 Of course it is possible to write modules yourself. Using modules for
771 structuring your programs makes them more readable and lets you
772 distribute them more easily. Also, explicitly defining the procedures
773 and variables which are exported from a module adds documentation to the
774 source and specifies the interface a module provides.
776 In Guile, you can create new modules and switch to existing modules in
777 order to add bindings to them using the syntactic form
778 @code{define-module}.
781 (define-module (foo bar))
786 Will create the module @code{(foo bar)}.@footnote{It is only convention
787 that the module names in this section have two elements. One or more
788 than two elements are perfectly fine, such as @code{(foo)} or @code{(foo
789 bar braz)}} All definitions following this statement will add bindings
790 to the module @code{(foo bar)}, and these bindings will not be visible
791 outside of the module. To make the bindings accessible to other
792 modules, you have to export them explicitly using one of the following
797 Export them with the @code{export} form:
803 Include them into the @code{define-module} form with the keyword
806 (define-module (foo bar)
811 Change the definition of @code{frob} to use @code{define-public}, which
812 is a combination of @code{define} and @code{export}.
814 (define-public (frob x) x)
818 After exporting, other modules can access the exported items simply by
819 using @code{use-modules} to load the module @code{(foo bar)}.
822 @node Intro to Modules and Extensions
823 @subsection Intro to Modules and Extensions
825 In addition to Scheme code you can also put things that are defined in
828 You do this by writing a small Scheme file that defines the module.
829 That Scheme file in turn invokes @code{load-extension} to make the
830 features defined in C available. This works since all definitions
831 made by @code{scm_c_define_gsubr} etc. go into the @emph{current
832 module} and @code{define-module} causes the newly defined module to be
833 current while the code that follows it is executed.
835 Suppose we want to put the Bessel function @code{j0} from the example
836 extension into a module called @code{(math bessel)}. We would have to
837 write a Scheme file with this contents
840 (define-module (math bessel))
844 (load-extension "libguile-bessel" "init_bessel")
847 This file should of course be saved in the right place for
848 autoloading, for example as
849 @file{/usr/local/share/guile/math/bessel.scm}.
851 When @code{init_bessel} is called, the new @code{(math bessel)} module
852 is the current one. Thus, the call to @code{scm_c_define_gsubr} will
853 put the new definition for @code{j0} into it, just as we want it.
855 The definitions made in the C code are not automatically exported from
856 a module. You need to explicitly list the ones you want to export in
857 @code{export} statements or with the @code{:export} option of
858 @code{define-module}.
860 There is also a way to manipulate the module system from C but only
861 Scheme files can be autoloaded. Thus, we recommend that you define
862 your modules in Scheme.
866 @node Obtaining and Installing Guile
867 @chapter Obtaining and Installing Guile
869 Here is the information you will need to get and install Guile and extra
870 packages and documentation you might need or find interesting.
873 * The Basic Guile Package::
874 * Packages not shipped with Guile::
878 @node The Basic Guile Package
879 @section The Basic Guile Package
881 Guile can be obtained from the main GNU archive site
882 @url{ftp://ftp.gnu.org} or any of its mirrors. The file
883 will be named guile-version.tar.gz. The current version is
884 @value{VERSION}, so the file you should grab is:
886 @url{ftp://ftp.gnu.org/pub/gnu/guile-@value{VERSION}.tar.gz}
888 To unbundle Guile use the instruction
891 zcat guile-@value{VERSION}.tar.gz | tar xvf -
894 which will create a directory called @file{guile-@value{VERSION}} with
895 all the sources. You can look at the file @file{INSTALL} for detailed
896 instructions on how to build and install Guile, but you should be able
900 cd guile-@value{VERSION}
906 This will install the Guile executable @file{guile}, the Guile library
907 @file{-lguile} and various associated header files and support
908 libraries. It will also install the Guile tutorial and reference
911 @c [[include instructions for getting R5RS]]
913 Since this manual frequently refers to the Scheme ``standard'', also
914 known as R5RS, or the
916 ``Revised$^5$ Report on the Algorithmic Language Scheme'',
919 ``Revised^5 Report on the Algorithmic Language Scheme'',
921 we have included the report in the Guile distribution;
922 @xref{Top, , Introduction, r5rs, Revised(5) Report on the Algorithmic
924 This will also be installed in your info directory.
927 @node Packages not shipped with Guile
928 @section Packages not shipped with Guile
930 We ship the Guile tutorial and reference manual with the Guile
931 distribution. Since the Scheme standard (R5RS) is a stable document, we
934 Here are references (usually World Wide Web URLs) to some other freely
935 redistributable documents and packages which you might find useful if
940 the Scheme Shell. Gary Houston has ported SCSH to Guile. The relevant
941 chapter (@pxref{The Scheme shell (scsh)}) has references to the SCSH web
942 page with all its documentation.
945 a portable Scheme library maintained by Aubrey Jaffer. SLIB can be
946 obtained by ftp from @url{ftp://prep.ai.mit.edu/pub/gnu/jacal/}.
948 The SLIB package should be unpacked somewhere in Guile's load path. It
949 will typically be unpacked in @file{/usr/local/share/guile/site}, so
950 that it will be @file{/usr/local/share/guile/site/slib}.
952 Guile might have been installed with a different prefix, in which case
953 the load path can be checked from inside the interpreter with:
957 ("/usr/local/share/guile/site" "/usr/local/share/guile/1.3a" "/usr/local/share/guile" ".")
960 The relevant chapter (@pxref{SLIB}) has details on how to use SLIB with
964 a symbolic math package by Aubrey Jaffer. The latest version of Jacal
965 can be obtained from @url{ftp://prep.ai.mit.edu/pub/gnu/jacal/}, and
966 should be unpacked in @file{/usr/local/share/guile/site/slib} so that
967 it will be in @file{/usr/local/share/guile/site/slib/jacal}.
969 The relevant section (@pxref{JACAL}) has details on how to use Jacal.
975 @chapter Reporting Bugs
977 Any problems with the installation should be reported to
978 @email{bug-guile@@gnu.org}.
980 Whenever you have found a bug in Guile you are encouraged to report it
981 to the Guile developers, so they can fix it. They may also be able to
982 suggest workarounds when it is not possible for you to apply the bug-fix
983 or install a new version of Guile yourself.
985 Before sending in bug reports, please check with the following list that
986 you really have found a bug.
990 Whenever documentation and actual behavior differ, you have certainly
991 found a bug, either in the documentation or in the program.
994 When Guile crashes, it is a bug.
997 When Guile hangs or takes forever to complete a task, it is a bug.
1000 When calculations produce wrong results, it is a bug.
1003 When Guile signals an error for valid Scheme programs, it is a bug.
1006 When Guile does not signal an error for invalid Scheme programs, it may
1007 be a bug, unless this is explicitly documented.
1010 When some part of the documentation is not clear and does not make sense
1011 to you even after re-reading the section, it is a bug.
1014 When you write a bug report, please make sure to include as much of the
1015 information described below in the report. If you can't figure out some
1016 of the items, it is not a problem, but the more information we get, the
1017 more likely we can diagnose and fix the bug.
1021 The version number of Guile. Without this, we won't know whether there
1022 is any point in looking for the bug in the current version of Guile.
1024 You can get the version number by invoking the command
1029 Copyright (c) 1995, 1996, 1997, 2000 Free Software Foundation
1030 Guile may be distributed under the terms of the GNU General Public License;
1031 certain other uses are permitted as well. For details, see the file
1032 `COPYING', which is included in the Guile distribution.
1033 There is no warranty, to the extent permitted by law.
1037 The type of machine you are using, and the operating system name and
1038 version number. On GNU systems, you can get it with @file{uname}.
1042 Linux tortoise 2.2.17 #1 Thu Dec 21 17:29:05 CET 2000 i586 unknown
1046 The operands given to the @file{configure} command when Guile was
1047 installed. It's often useful to augment this with the output of the
1048 command @code{guile-config info}.
1051 A complete list of any modifications you have made to the Guile source.
1052 (We may not have time to investigate the bug unless it happens in an
1053 unmodified Guile. But if you've made modifications and you don't tell
1054 us, you are sending us on a wild goose chase.)
1056 Be precise about these changes. A description in English is not
1057 enough---send a context diff for them.
1059 Adding files of your own, or porting to another machine, is a
1060 modification of the source.
1063 Details of any other deviations from the standard procedure for
1067 The complete text of any source files needed to reproduce the bug.
1069 If you can tell us a way to cause the problem without loading any source
1070 files, please do so. This makes it much easier to debug. If you do
1071 need files, make sure you arrange for us to see their exact contents.
1074 The precise Guile invocation command line we need to type to reproduce
1078 A description of what behavior you observe that you believe is
1079 incorrect. For example, "The Guile process gets a fatal signal," or,
1080 "The resulting output is as follows, which I think is wrong."
1082 Of course, if the bug is that Guile gets a fatal signal, then one can't
1083 miss it. But if the bug is incorrect results, the maintainer might fail
1084 to notice what is wrong. Why leave it to chance?
1086 If the manifestation of the bug is a Guile error message, it is
1087 important to report the precise text of the error message, and a
1088 backtrace showing how the Scheme program arrived at the error.
1090 This can be done using the procedure @code{backtrace} in the REPL.
1093 Check whether any programs you have loaded into Guile, including your
1094 @file{.guile} file, set any variables that may affect the functioning of
1095 Guile. Also, see whether the problem happens in a freshly started Guile
1096 without loading your @file{.guile} file (start Guile with the @code{-q}
1097 switch to prevent loading the init file). If the problem does
1098 @emph{not} occur then, you must report the precise contents of any
1099 programs that you must load into Guile in order to cause the problem to
1103 If the problem does depend on an init file or other Scheme programs that
1104 are not part of the standard Guile distribution, then you should make
1105 sure it is not a bug in those programs by complaining to their
1106 maintainers first. After they verify that they are using Guile in a way
1107 that is supposed to work, they should report the bug.
1110 If you wish to mention something in the Guile source, show the line of
1111 code with a few lines of context. Don't just give a line number.
1113 The line numbers in the development sources might not match those in your
1114 sources. It would take extra work for the maintainers to determine what
1115 code is in your version at a given line number, and we could not be
1119 Additional information from a C debugger such as GDB might enable
1120 someone to find a problem on a machine which he does not have available.
1121 If you don't know how to use GDB, please read the GDB manual---it is not
1122 very long, and using GDB is easy. You can find the GDB distribution,
1123 including the GDB manual in online form, in most of the same places you
1124 can find the Guile distribution. To run Guile under GDB, you should
1125 switch to the @file{libguile} subdirectory in which Guile was compiled, then
1126 do @code{gdb guile} or @code{gdb .libs/guile} (if using GNU Libtool).
1128 However, you need to think when you collect the additional information
1129 if you want it to show what causes the bug.
1131 For example, many people send just a backtrace, but that is not very
1132 useful by itself. A simple backtrace with arguments often conveys
1133 little about what is happening inside Guile, because most of the
1134 arguments listed in the backtrace are pointers to Scheme objects. The
1135 numeric values of these pointers have no significance whatever; all that
1136 matters is the contents of the objects they point to (and most of the
1137 contents are themselves pointers).
1143 @c TeX-master: "guile.texi"