123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405 |
- c This is part of the GNU Guile Reference Manual.
- c Free Software Foundation, Inc.
- raisesections
- section Hello Guile!
- This chapter presents a quick tour of all the ways that Guile can be
- used. There are additional examples in the
- code{/usr/local/}.
- end menu
- subsection Running Guile Interactively
- In its simplest form, Guile acts as an interactive interpreter for the
- Scheme programming language, reading and evaluating Scheme expressions
- the user enters from the terminal. Here is a sample interaction between
- Guile and a user; the user's input appears after the
- code{scheme(guile-user)>} prompts:
- kbd{C-d}
- $
- node Running Guile Scripts
- xref{Guile Scripting}, for more details.
- end example
- subsection Linking Guile into Programs
- The Guile interpreter is available as an object library, to be linked
- into applications using Scheme as a configuration or extension
- language.
- Here is
- code{my-hostname}.
- {
- char *s = getenv ("HOSTNAME");
- if (s == NULL)
- return SCM_BOOL_F;
- else
- return scm_from_locale_string (s);
- {
- scm_c_define_gsubr ("my-hostname", 0, 0, 0, my_hostname);
- scm_shell (argc, argv);
- {
- scm_boot_guile (argc, argv, inner_main, 0);
- return 0;
- end example
- When Guile is correctly installed on your system, the above program
- can be compiled and linked like this:
- value{EFFECTIVE-VERSION}`
- code{guile} program except
- that you can also call the new
- example
- $ ./simple-guile
- scheme(guile-user)> (+ 1 2 3)
- $1 = 6
- scheme(guile-user)> (my-hostname)
- "burns"
- node Writing Guile Extensions
- dfn{extension}, but it
- really just is an ordinary object library.
- The following example shows how to write a simple extension for Guile
- that makes the
- smallexample
- #include <math.h>
- #include <libguile.h>
- SCM
- j0_wrapper (SCM x)
- }
- void
- init_bessel ()
- }
- smallexample
- gcc `pkg-config --cflags guile-
- end smallexample
- For creating shared libraries portably, we recommend the use of GNU
- Libtool (
- code{load-extension}. The
- smallexample
- $ guile
- scheme(guile-user)> (load-extension "./libguile-bessel" "init_bessel")
- scheme(guile-user)> (j0 2)
- $1 = 0.223890779141236
- pxref{Installing Site
- Packages}.
- subsection Using the Guile Module System
- Guile has support for dividing a program into
- xref{Modules}.
- end menu
- subsubsection Using Modules
- Guile comes with a lot of useful modules, for example for string
- processing or command line parsing. Additionally, there exist many
- Guile modules written by other Guile hackers, but which have to be
- installed manually.
- Here is a sample interactive session that shows how to use the
- code{(ice-9
- rdelim)} module that provides the function
- smallexample
- $ guile
- scheme(guile-user)> (use-modules (ice-9 popen))
- scheme(guile-user)> (use-modules (ice-9 rdelim))
- scheme(guile-user)> (define p (open-input-pipe "ls -l"))
- scheme(guile-user)> (read-line p)
- $1 = "total 30"
- scheme(guile-user)> (read-line p)
- $2 = "drwxr-sr-x 2 mgrabmue mgrabmue 1024 Mar 29 19:57 CVS"
- node Writing new Modules
- code{define-module}. All definitions following this form until the
- next
- smallexample
- $ cat /usr/local/share/guile/site/foo/bar.scm
- (define-module (foo bar)
- #:export (frob))
- (define (frob x) (* 2 x))
- $ guile
- scheme(guile-user)> (use-modules (foo bar))
- scheme(guile-user)> (frob 12)
- $1 = 24
- pxref{Installing Site
- Packages}.
- subsubsection Putting Extensions into Modules
- In addition to Scheme code you can also put things that are defined in
- C into a module.
- You do this by writing a small Scheme file that defines the module and
- call
- smallexample
- $ cat /usr/local/share/guile/site/math/bessel.scm
- (define-module (math bessel)
- #:export (j0))
- (load-extension "libguile-bessel" "init_bessel")
- $ file /usr/local/lib/guile/
- dots{} ELF 32-bit LSB shared object
- end smallexample
- lowersections
- section Reporting Bugs
- Any problems with the installation should be reported to
- itemize
- item
- Whenever documentation and actual behavior differ, you have certainly
- found a bug, either in the documentation or in the program.
- item
- When Guile hangs or takes forever to complete a task, it is a bug.
- item
- When Guile signals an error for valid Scheme programs, it is a bug.
- item
- When some part of the documentation is not clear and does not make sense
- to you even after re-reading the section, it is a bug.
- file{.guile} file, set any variables that
- may affect the functioning of Guile. Also, see whether the problem
- happens in a freshly started Guile without loading your
- code{-q} switch to prevent loading the init
- file). If the problem does
- itemize
- item
- The version number of Guile. You can get this information from invoking
- code{(version)} from
- within Guile.
- code{config.guess} shell
- script. If you have a Guile checkout, this file is located in
- uref{http:
- end example
- code{rpm -qa | grep guile}. On systems
- that use DPKG,
- item
- If you built Guile yourself, the build configuration that you used:
- end example
- item
- A description of the incorrect behavior. For example, "The Guile
- process gets a fatal signal," or, "The resulting output is as follows,
- which I think is wrong."
- If the manifestation of the bug is a Guile error message, it is
- important to report the precise text of the error message, and a
- backtrace showing how the Scheme program arrived at the error. This can
- be done using the
- end itemize
- If your bug causes Guile to crash, additional information from a
- low-level debugger such as GDB might be helpful. If you have built Guile
- yourself, you can run Guile under GDB via the
- code{run} to start the process,
- then
- c Local Variables:
- c End:
|