elisp @@ macro
[bpt/guile.git] / doc / ref / scheme-using.texi
CommitLineData
46f7666d
NJ
1@c -*-texinfo-*-
2@c This is part of the GNU Guile Reference Manual.
36c210d1 3@c Copyright (C) 2006, 2010, 2011, 2012, 2013
46f7666d
NJ
4@c Free Software Foundation, Inc.
5@c See the file guile.texi for copying conditions.
6
7@node Using Guile Interactively
8@section Using Guile Interactively
9
10When you start up Guile by typing just @code{guile}, without a
11@code{-c} argument or the name of a script to execute, you get an
12interactive interpreter where you can enter Scheme expressions, and
13Guile will evaluate them and print the results for you. Here are some
14simple examples.
15
16@lisp
749c2532 17scheme@@(guile-user)> (+ 3 4 5)
dc3b2661 18$1 = 12
749c2532 19scheme@@(guile-user)> (display "Hello world!\n")
46f7666d 20Hello world!
749c2532 21scheme@@(guile-user)> (values 'a 'b)
dc3b2661
AW
22$2 = a
23$3 = b
46f7666d
NJ
24@end lisp
25
26@noindent
27This mode of use is called a @dfn{REPL}, which is short for
28``Read-Eval-Print Loop'', because the Guile interpreter first reads the
29expression that you have typed, then evaluates it, and then prints the
30result.
31
749c2532
AW
32The prompt shows you what language and module you are in. In this case, the
33current language is @code{scheme}, and the current module is
34@code{(guile-user)}. @xref{Other Languages}, for more information on Guile's
35support for languages other than Scheme.
36
46f7666d 37@menu
2460274d 38* Init File::
3c0b7725 39* Readline::
ca290a89 40* Value History::
3c0b7725
AW
41* REPL Commands::
42* Error Handling::
43* Interactive Debugging::
46f7666d
NJ
44@end menu
45
46
2460274d
AW
47@node Init File
48@subsection The Init File, @file{~/.guile}
49
50@cindex .guile
51When run interactively, Guile will load a local initialization file from
52@file{~/.guile}. This file should contain Scheme expressions for
53evaluation.
54
55This facility lets the user customize their interactive Guile
56environment, pulling in extra modules or parameterizing the REPL
57implementation.
58
59To run Guile without loading the init file, use the @code{-q}
60command-line option.
61
62
46f7666d
NJ
63@node Readline
64@subsection Readline
65
66To make it easier for you to repeat and vary previously entered
67expressions, or to edit the expression that you're typing in, Guile
68can use the GNU Readline library. This is not enabled by default
69because of licensing reasons, but all you need to activate Readline is
70the following pair of lines.
71
72@lisp
749c2532
AW
73scheme@@(guile-user)> (use-modules (ice-9 readline))
74scheme@@(guile-user)> (activate-readline)
46f7666d
NJ
75@end lisp
76
ced9917e 77It's a good idea to put these two lines (without the
2460274d
AW
78@code{scheme@@(guile-user)>} prompts) in your @file{.guile} file.
79@xref{Init File}, for more on @file{.guile}.
46f7666d
NJ
80
81
ca290a89 82@node Value History
46f7666d
NJ
83@subsection Value History
84
85Just as Readline helps you to reuse a previous input line, @dfn{value
ced9917e
AW
86history} allows you to use the @emph{result} of a previous evaluation in
87a new expression. When value history is enabled, each evaluation result
88is automatically assigned to the next in the sequence of variables
89@code{$1}, @code{$2}, @dots{}. You can then use these variables in
90subsequent expressions.
46f7666d
NJ
91
92@lisp
749c2532 93scheme@@(guile-user)> (iota 10)
46f7666d 94$1 = (0 1 2 3 4 5 6 7 8 9)
749c2532 95scheme@@(guile-user)> (apply * (cdr $1))
46f7666d 96$2 = 362880
749c2532 97scheme@@(guile-user)> (sqrt $2)
46f7666d 98$3 = 602.3952191045344
749c2532 99scheme@@(guile-user)> (cons $2 $1)
46f7666d
NJ
100$4 = (362880 0 1 2 3 4 5 6 7 8 9)
101@end lisp
102
dc3b2661
AW
103Value history is enabled by default, because Guile's REPL imports the
104@code{(ice-9 history)} module. Value history may be turned off or on within the
105repl, using the options interface:
106
107@lisp
108scheme@@(guile-user)> ,option value-history #f
109scheme@@(guile-user)> 'foo
110foo
111scheme@@(guile-user)> ,option value-history #t
112scheme@@(guile-user)> 'bar
113$5 = bar
114@end lisp
115
116Note that previously recorded values are still accessible, even if value history
117is off. In rare cases, these references to past computations can cause Guile to
118use too much memory. One may clear these values, possibly enabling garbage
119collection, via the @code{clear-value-history!} procedure, described below.
120
121The programmatic interface to value history is in a module:
122
123@lisp
124(use-modules (ice-9 history))
125@end lisp
126
127@deffn {Scheme Procedure} value-history-enabled?
a4b4fbbd 128Return true if value history is enabled, or false otherwise.
dc3b2661
AW
129@end deffn
130
131@deffn {Scheme Procedure} enable-value-history!
132Turn on value history, if it was off.
133@end deffn
134
135@deffn {Scheme Procedure} disable-value-history!
136Turn off value history, if it was on.
137@end deffn
138
139@deffn {Scheme Procedure} clear-value-history!
140Clear the value history. If the stored values are not captured by some other
141data structure or closure, they may then be reclaimed by the garbage collector.
142@end deffn
46f7666d
NJ
143
144
3c0b7725
AW
145@node REPL Commands
146@subsection REPL Commands
46f7666d 147
3c0b7725
AW
148@cindex commands
149The REPL exists to read expressions, evaluate them, and then print their
150results. But sometimes one wants to tell the REPL to evaluate an
151expression in a different way, or to do something else altogether. A
152user can affect the way the REPL works with a @dfn{REPL command}.
46f7666d 153
3c0b7725
AW
154The previous section had an example of a command, in the form of
155@code{,option}.
46f7666d
NJ
156
157@lisp
3c0b7725 158scheme@@(guile-user)> ,option value-history #t
46f7666d
NJ
159@end lisp
160
161@noindent
3c0b7725
AW
162Commands are distinguished from expressions by their initial comma
163(@samp{,}). Since a comma cannot begin an expression in most languages,
164it is an effective indicator to the REPL that the following text forms a
165command, not an expression.
46f7666d 166
3c0b7725
AW
167REPL commands are convenient because they are always there. Even if the
168current module doesn't have a binding for @code{pretty-print}, one can
169always @code{,pretty-print}.
46f7666d 170
3c0b7725
AW
171The following sections document the various commands, grouped together
172by functionality. Many of the commands have abbreviations; see the
173online help (@code{,help}) for more information.
46f7666d 174
3c0b7725
AW
175@menu
176* Help Commands::
177* Module Commands::
178* Language Commands::
179* Compile Commands::
180* Profile Commands::
181* Debug Commands::
182* Inspect Commands::
183* System Commands::
184@end menu
46f7666d 185
3c0b7725
AW
186@node Help Commands
187@subsubsection Help Commands
46f7666d 188
3c0b7725
AW
189When Guile starts interactively, it notifies the user that help can be
190had by typing @samp{,help}. Indeed, @code{help} is a command, and a
191particularly useful one, as it allows the user to discover the rest of
192the commands.
46f7666d 193
ced9917e 194@deffn {REPL Command} help [@code{all} | group | @code{[-c]} command]
3c0b7725 195Show help.
46f7666d 196
3c0b7725
AW
197With one argument, tries to look up the argument as a group name, giving
198help on that group if successful. Otherwise tries to look up the
199argument as a command, giving help on the command.
46f7666d 200
3c0b7725
AW
201If there is a command whose name is also a group name, use the @samp{-c
202@var{command}} form to give help on the command instead of the group.
46f7666d 203
3c0b7725
AW
204Without any argument, a list of help commands and command groups
205are displayed.
206@end deffn
46f7666d 207
3c0b7725
AW
208@deffn {REPL Command} show [topic]
209Gives information about Guile.
46f7666d 210
3c0b7725
AW
211With one argument, tries to show a particular piece of information;
212currently supported topics are `warranty' (or `w'), `copying' (or `c'),
213and `version' (or `v').
46f7666d 214
3c0b7725
AW
215Without any argument, a list of topics is displayed.
216@end deffn
46f7666d 217
3c0b7725
AW
218@deffn {REPL Command} apropos regexp
219Find bindings/modules/packages.
220@end deffn
46f7666d 221
3c0b7725
AW
222@deffn {REPL Command} describe obj
223Show description/documentation.
224@end deffn
46f7666d 225
3c0b7725
AW
226@node Module Commands
227@subsubsection Module Commands
ee6be719 228
3c0b7725
AW
229@deffn {REPL Command} module [module]
230Change modules / Show current module.
ee6be719
NJ
231@end deffn
232
df0a1002 233@deffn {REPL Command} import module @dots{}
3c0b7725
AW
234Import modules / List those imported.
235@end deffn
46f7666d 236
3c0b7725
AW
237@deffn {REPL Command} load file
238Load a file in the current module.
239@end deffn
46f7666d 240
cdab9fc6
AW
241@deffn {REPL Command} reload [module]
242Reload the given module, or the current module if none was given.
243@end deffn
244
3c0b7725
AW
245@deffn {REPL Command} binding
246List current bindings.
247@end deffn
46f7666d 248
8fdd85f8 249@deffn {REPL Command} in module expression
df0a1002 250@deffnx {REPL Command} in module command arg @dots{}
8fdd85f8
AR
251Evaluate an expression, or alternatively, execute another meta-command
252in the context of a module. For example, @samp{,in (foo bar) ,binding}
253will show the bindings in the module @code{(foo bar)}.
254@end deffn
255
3c0b7725
AW
256@node Language Commands
257@subsubsection Language Commands
46f7666d 258
3c0b7725
AW
259@deffn {REPL Command} language language
260Change languages.
46f7666d
NJ
261@end deffn
262
3c0b7725
AW
263@node Compile Commands
264@subsubsection Compile Commands
46f7666d 265
3c0b7725
AW
266@deffn {REPL Command} compile exp
267Generate compiled code.
268@end deffn
46f7666d 269
3c0b7725
AW
270@deffn {REPL Command} compile-file file
271Compile a file.
272@end deffn
46f7666d 273
d62dd766
AW
274@deffn {REPL Command} expand exp
275Expand any macros in a form.
276@end deffn
277
278@deffn {REPL Command} optimize exp
279Run the optimizer on a piece of code and print the result.
280@end deffn
281
3c0b7725
AW
282@deffn {REPL Command} disassemble exp
283Disassemble a compiled procedure.
284@end deffn
46f7666d 285
3c0b7725
AW
286@deffn {REPL Command} disassemble-file file
287Disassemble a file.
288@end deffn
46f7666d 289
3c0b7725
AW
290@node Profile Commands
291@subsubsection Profile Commands
46f7666d 292
3c0b7725
AW
293@deffn {REPL Command} time exp
294Time execution.
46f7666d
NJ
295@end deffn
296
3c0b7725
AW
297@deffn {REPL Command} profile exp
298Profile execution.
46f7666d
NJ
299@end deffn
300
36c210d1 301@deffn {REPL Command} trace exp [#:width w] [#:max-indent i]
3c0b7725 302Trace execution.
36c210d1
AW
303
304By default, the trace will limit its width to the width of your
305terminal, or @var{width} if specified. Nested procedure invocations
306will be printed farther to the right, though if the width of the
307indentation passes the @var{max-indent}, the indentation is abbreviated.
46f7666d
NJ
308@end deffn
309
3c0b7725
AW
310@node Debug Commands
311@subsubsection Debug Commands
46f7666d 312
3c0b7725
AW
313These debugging commands are only available within a recursive REPL;
314they do not work at the top level.
46f7666d 315
3c0b7725
AW
316@deffn {REPL Command} backtrace [count] [#:width w] [#:full? f]
317Print a backtrace.
46f7666d 318
64de6db5 319Print a backtrace of all stack frames, or innermost @var{count} frames.
3c0b7725 320If @var{count} is negative, the last @var{count} frames will be shown.
46f7666d
NJ
321@end deffn
322
3c0b7725
AW
323@deffn {REPL Command} up [count]
324Select a calling stack frame.
325
326Select and print stack frames that called this one.
327An argument says how many frames up to go.
46f7666d
NJ
328@end deffn
329
3c0b7725
AW
330@deffn {REPL Command} down [count]
331Select a called stack frame.
332
333Select and print stack frames called by this one.
334An argument says how many frames down to go.
46f7666d
NJ
335@end deffn
336
3c0b7725
AW
337@deffn {REPL Command} frame [idx]
338Show a frame.
339
340Show the selected frame. With an argument, select a frame by index,
341then show it.
342@end deffn
46f7666d 343
3c0b7725
AW
344@deffn {REPL Command} procedure
345Print the procedure for the selected frame.
346@end deffn
46f7666d 347
3c0b7725
AW
348@deffn {REPL Command} locals
349Show local variables.
46f7666d 350
3c0b7725 351Show locally-bound variables in the selected frame.
46f7666d
NJ
352@end deffn
353
54d9a994
JOR
354@deffn {REPL Command} error-message
355@deffnx {REPL Command} error
356Show error message.
357
358Display the message associated with the error that started the current
359debugging REPL.
360@end deffn
361
1ecf39a6
AW
362@deffn {REPL Command} registers
363Show the VM registers associated with the current frame.
364
365@xref{Stack Layout}, for more information on VM stack frames.
366@end deffn
367
47b86dbf
MG
368@deffn {REPL Command} width [cols]
369Sets the number of display columns in the output of @code{,backtrace}
370and @code{,locals} to @var{cols}. If @var{cols} is not given, the width
371of the terminal is used.
372@end deffn
373
1ecf39a6
AW
374The next 3 commands work at any REPL.
375
376@deffn {REPL Command} break proc
377Set a breakpoint at @var{proc}.
378@end deffn
379
380@deffn {REPL Command} break-at-source file line
381Set a breakpoint at the given source location.
382@end deffn
383
384@deffn {REPL Command} tracepoint proc
385Set a tracepoint on the given procedure. This will cause all calls to
386the procedure to print out a tracing message. @xref{Tracing Traps}, for
387more information.
388@end deffn
389
390The rest of the commands in this subsection all apply only when the
391stack is @dfn{continuable} --- in other words when it makes sense for
392the program that the stack comes from to continue running. Usually this
393means that the program stopped because of a trap or a breakpoint.
394
395@deffn {REPL Command} step
396Tell the debugged program to step to the next source location.
397@end deffn
398
399@deffn {REPL Command} next
400Tell the debugged program to step to the next source location in the
401same frame. (See @ref{Traps} for the details of how this works.)
402@end deffn
403
404@deffn {REPL Command} finish
405Tell the program being debugged to continue running until the completion
406of the current stack frame, and at that time to print the result and
407reenter the REPL.
408@end deffn
409
3c0b7725
AW
410
411@node Inspect Commands
412@subsubsection Inspect Commands
413
64de6db5 414@deffn {REPL Command} inspect exp
3c0b7725
AW
415Inspect the result(s) of evaluating @var{exp}.
416@end deffn
46f7666d 417
64de6db5 418@deffn {REPL Command} pretty-print exp
3c0b7725
AW
419Pretty-print the result(s) of evaluating @var{exp}.
420@end deffn
46f7666d 421
3c0b7725
AW
422@node System Commands
423@subsubsection System Commands
46f7666d 424
3c0b7725
AW
425@deffn {REPL Command} gc
426Garbage collection.
46f7666d
NJ
427@end deffn
428
3c0b7725
AW
429@deffn {REPL Command} statistics
430Display statistics.
46f7666d
NJ
431@end deffn
432
8d48877d
AW
433@deffn {REPL Command} option [name] [exp]
434With no arguments, lists all options. With one argument, shows the
435current value of the @var{name} option. With two arguments, sets the
436@var{name} option to the result of evaluating the Scheme expression
437@var{exp}.
46f7666d
NJ
438@end deffn
439
3c0b7725
AW
440@deffn {REPL Command} quit
441Quit this session.
46f7666d
NJ
442@end deffn
443
2460274d
AW
444Current REPL options include:
445
446@table @code
447@item compile-options
448The options used when compiling expressions entered at the REPL.
449@xref{Compilation}, for more on compilation options.
450@item interp
451Whether to interpret or compile expressions given at the REPL, if such a
452choice is available. Off by default (indicating compilation).
453@item prompt
454A customized REPL prompt. @code{#f} by default, indicating the default
455prompt.
afdf5467
DH
456@item print
457A procedure of two arguments used to print the result of evaluating each
458expression. The arguments are the current REPL and the value to print.
459By default, @code{#f}, to use the default procedure.
2460274d
AW
460@item value-history
461Whether value history is on or not. @xref{Value History}.
462@item on-error
463What to do when an error happens. By default, @code{debug}, meaning to
464enter the debugger. Other values include @code{backtrace}, to show a
465backtrace without entering the debugger, or @code{report}, to simply
466show a short error printout.
467@end table
468
469Default values for REPL options may be set using
470@code{repl-default-option-set!} from @code{(system repl common)}:
471
ead2496f 472@deffn {Scheme Procedure} repl-default-option-set! key value
2460274d
AW
473Set the default value of a REPL option. This function is particularly
474useful in a user's init file. @xref{Init File}.
475@end deffn
476
46f7666d 477
3c0b7725
AW
478@node Error Handling
479@subsection Error Handling
480
481When code being evaluated from the REPL hits an error, Guile enters a
482new prompt, allowing you to inspect the context of the error.
483
484@lisp
485scheme@@(guile-user)> (map string-append '("a" "b") '("c" #\d))
486ERROR: In procedure string-append:
487ERROR: Wrong type (expecting string): #\d
488Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.
489scheme@@(guile-user) [1]>
490@end lisp
491
492The new prompt runs inside the old one, in the dynamic context of the
493error. It is a recursive REPL, augmented with a reified representation
494of the stack, ready for debugging.
495
496@code{,backtrace} (abbreviated @code{,bt}) displays the Scheme call
497stack at the point where the error occurred:
498
499@lisp
500scheme@@(guile-user) [1]> ,bt
501 1 (map #<procedure string-append _> ("a" "b") ("c" #\d))
502 0 (string-append "b" #\d)
503@end lisp
504
505In the above example, the backtrace doesn't have much source
506information, as @code{map} and @code{string-append} are both
507primitives. But in the general case, the space on the left of the
508backtrace indicates the line and column in which a given procedure calls
509another.
510
511You can exit a recursive REPL in the same way that you exit any REPL:
512via @samp{(quit)}, @samp{,quit} (abbreviated @samp{,q}), or
513@kbd{C-d}, among other options.
514
515
516@node Interactive Debugging
517@subsection Interactive Debugging
518
519A recursive debugging REPL exposes a number of other meta-commands that
520inspect the state of the computation at the time of the error. These
521commands allow you to
522
523@itemize @bullet
524@item
525display the Scheme call stack at the point where the error occurred;
526
527@item
528move up and down the call stack, to see in detail the expression being
529evaluated, or the procedure being applied, in each @dfn{frame}; and
530
531@item
532examine the values of variables and expressions in the context of each
533frame.
534@end itemize
535
536@noindent
537@xref{Debug Commands}, for documentation of the individual
538commands. This section aims to give more of a walkthrough of a typical
539debugging session.
540
541First, we're going to need a good error. Let's try to macroexpand the
542expression @code{(unquote foo)}, outside of a @code{quasiquote} form,
543and see how the macroexpander reports this error.
544
545@lisp
546scheme@@(guile-user)> (macroexpand '(unquote foo))
547ERROR: In procedure macroexpand:
548ERROR: unquote: expression not valid outside of quasiquote in (unquote foo)
549Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.
550scheme@@(guile-user) [1]>
551@end lisp
552
553The @code{backtrace} command, which can also be invoked as @code{bt},
554displays the call stack (aka backtrace) at the point where the debugger
555was entered:
556
557@lisp
558scheme@@(guile-user) [1]> ,bt
559In ice-9/psyntax.scm:
560 1130:21 3 (chi-top (unquote foo) () ((top)) e (eval) (hygiene #))
561 1071:30 2 (syntax-type (unquote foo) () ((top)) #f #f (# #) #f)
562 1368:28 1 (chi-macro #<procedure de9360 at ice-9/psyntax.scm...> ...)
563In unknown file:
564 0 (scm-error syntax-error macroexpand "~a: ~a in ~a" # #f)
565@end lisp
566
567A call stack consists of a sequence of stack @dfn{frames}, with each
568frame describing one procedure which is waiting to do something with the
569values returned by another. Here we see that there are four frames on
570the stack.
571
572Note that @code{macroexpand} is not on the stack -- it must have made a
573tail call to @code{chi-top}, as indeed we would find if we searched
574@code{ice-9/psyntax.scm} for its definition.
575
576When you enter the debugger, the innermost frame is selected, which
577means that the commands for getting information about the ``current''
578frame, or for evaluating expressions in the context of the current
579frame, will do so by default with respect to the innermost frame. To
580select a different frame, so that these operations will apply to it
581instead, use the @code{up}, @code{down} and @code{frame} commands like
582this:
583
584@lisp
585scheme@@(guile-user) [1]> ,up
586In ice-9/psyntax.scm:
587 1368:28 1 (chi-macro #<procedure de9360 at ice-9/psyntax.scm...> ...)
588scheme@@(guile-user) [1]> ,frame 3
589In ice-9/psyntax.scm:
590 1130:21 3 (chi-top (unquote foo) () ((top)) e (eval) (hygiene #))
591scheme@@(guile-user) [1]> ,down
592In ice-9/psyntax.scm:
593 1071:30 2 (syntax-type (unquote foo) () ((top)) #f #f (# #) #f)
594@end lisp
595
596Perhaps we're interested in what's going on in frame 2, so we take a
597look at its local variables:
598
599@lisp
600scheme@@(guile-user) [1]> ,locals
601 Local variables:
602 $1 = e = (unquote foo)
603 $2 = r = ()
604 $3 = w = ((top))
605 $4 = s = #f
606 $5 = rib = #f
607 $6 = mod = (hygiene guile-user)
608 $7 = for-car? = #f
609 $8 = first = unquote
610 $9 = ftype = macro
611 $10 = fval = #<procedure de9360 at ice-9/psyntax.scm:2817:2 (x)>
612 $11 = fe = unquote
613 $12 = fw = ((top))
614 $13 = fs = #f
615 $14 = fmod = (hygiene guile-user)
616@end lisp
617
618All of the values are accessible by their value-history names
619(@code{$@var{n}}):
620
621@lisp
622scheme@@(guile-user) [1]> $10
623$15 = #<procedure de9360 at ice-9/psyntax.scm:2817:2 (x)>
624@end lisp
625
626We can even invoke the procedure at the REPL directly:
627
628@lisp
629scheme@@(guile-user) [1]> ($10 'not-going-to-work)
630ERROR: In procedure macroexpand:
631ERROR: source expression failed to match any pattern in not-going-to-work
632Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.
633@end lisp
634
635Well at this point we've caused an error within an error. Let's just
636quit back to the top level:
637
638@lisp
639scheme@@(guile-user) [2]> ,q
640scheme@@(guile-user) [1]> ,q
641scheme@@(guile-user)>
642@end lisp
643
644Finally, as a word to the wise: hackers close their REPL prompts with
645@kbd{C-d}.
646
647
46f7666d
NJ
648@node Using Guile in Emacs
649@section Using Guile in Emacs
650
b20ef3a6 651@cindex Emacs
767dbb1a
AW
652Any text editor can edit Scheme, but some are better than others. Emacs
653is the best, of course, and not just because it is a fine text editor.
654Emacs has good support for Scheme out of the box, with sensible
655indentation rules, parenthesis-matching, syntax highlighting, and even a
656set of keybindings for structural editing, allowing navigation,
657cut-and-paste, and transposition operations that work on balanced
658S-expressions.
659
660As good as it is, though, two things will vastly improve your experience
661with Emacs and Guile.
662
663@cindex Paredit
664The first is Taylor Campbell's
665@uref{http://www.emacswiki.org/emacs/ParEdit, Paredit}. You should not
666code in any dialect of Lisp without Paredit. (They say that
667unopinionated writing is boring---hence this tone---but it's the
668truth, regardless.) Paredit is the bee's knees.
669
670@cindex Geiser
917b2bf6
NJ
671The second is
672@iftex
673Jos@'e
674@end iftex
675@ifnottex
676José
677@end ifnottex
678Antonio Ortega Ruiz's
767dbb1a
AW
679@uref{http://www.nongnu.org/geiser/, Geiser}. Geiser complements Emacs'
680@code{scheme-mode} with tight integration to running Guile processes via
681a @code{comint-mode} REPL buffer.
682
683Of course there are keybindings to switch to the REPL, and a good REPL
684environment, but Geiser goes beyond that, providing:
01d2ee15 685
767dbb1a 686@itemize @bullet
46f7666d 687@item
767dbb1a 688Form evaluation in the context of the current file's module.
46f7666d 689@item
767dbb1a 690Macro expansion.
46f7666d 691@item
767dbb1a 692File/module loading and/or compilation.
46f7666d 693@item
767dbb1a
AW
694Namespace-aware identifier completion (including local bindings, names
695visible in the current module, and module names).
46f7666d 696@item
767dbb1a
AW
697Autodoc: the echo area shows information about the signature of the
698procedure/macro around point automatically.
46f7666d 699@item
767dbb1a 700Jump to definition of identifier at point.
46f7666d 701@item
767dbb1a
AW
702Access to documentation (including docstrings when the implementation
703provides it).
46f7666d 704@item
767dbb1a 705Listings of identifiers exported by a given module.
62ae9557 706@item
767dbb1a 707Listings of callers/callees of procedures.
94a2c24a 708@item
767dbb1a 709Rudimentary support for debugging and error navigation.
62ae9557 710@item
767dbb1a 711Support for multiple, simultaneous REPLs.
62ae9557
NJ
712@end itemize
713
767dbb1a
AW
714See Geiser's web page at @uref{http://www.nongnu.org/geiser/}, for more
715information.
62ae9557
NJ
716
717
715146aa
AW
718@node Using Guile Tools
719@section Using Guile Tools
720
721@cindex guild
722@cindex guile-tools
723@cindex wizards
724Guile also comes with a growing number of command-line utilities: a
725compiler, a disassembler, some module inspectors, and in the future, a
726system to install Guile packages from the internet. These tools may be
8698e810 727invoked using the @code{guild} program.
715146aa
AW
728
729@example
730$ guild compile -o foo.go foo.scm
731wrote `foo.go'
732@end example
733
8698e810
LC
734This program used to be called @code{guile-tools} up to
735Guile version 2.0.1, and for backward
715146aa
AW
736compatibility it still may be called as such. However we changed the
737name to @code{guild}, not only because it is pleasantly shorter and
738easier to read, but also because this tool will serve to bind Guile
739wizards together, by allowing hackers to share code with each other
740using a CPAN-like system.
741
742@xref{Compilation}, for more on @code{guild compile}.
743
744A complete list of guild scripts can be had by invoking @code{guild
745list}, or simply @code{guild}.
746
24cc7832
AW
747
748@node Installing Site Packages
749@section Installing Site Packages
750
751@cindex site
752@cindex site path
753@cindex load path
754@findex %site-dir
988ca6b2 755@findex %site-ccache-dir
24cc7832
AW
756
757At some point, you will probably want to share your code with other
758people. To do so effectively, it is important to follow a set of common
759conventions, to make it easy for the user to install and use your
760package.
761
762The first thing to do is to install your Scheme files where Guile can
763find them. When Guile goes to find a Scheme file, it will search a
764@dfn{load path} to find the file: first in Guile's own path, then in
765paths for @dfn{site packages}. A site package is any Scheme code that
925172cf
AW
766is installed and not part of Guile itself. @xref{Load Paths}, for more
767on load paths.
24cc7832
AW
768
769There are several site paths, for historical reasons, but the one that
770should generally be used can be obtained by invoking the
771@code{%site-dir} procedure. @xref{Build Config}. If Guile
772@value{EFFECTIVE-VERSION} is installed on your system in @code{/usr/},
773then @code{(%site-dir)} will be
774@code{/usr/share/guile/site/@value{EFFECTIVE-VERSION}}. Scheme files
775should be installed there.
776
777If you do not install compiled @code{.go} files, Guile will compile your
778modules and programs when they are first used, and cache them in the
779user's home directory. @xref{Compilation}, for more on
780auto-compilation. However, it is better to compile the files before
781they are installed, and to just copy the files to a place that Guile can
782find them.
783
784As with Scheme files, Guile searches a path to find compiled @code{.go}
785files, the @code{%load-compiled-path}. By default, this path has two
786entries: a path for Guile's files, and a path for site packages. You
988ca6b2
JE
787should install your @code{.go} files into the latter directory, whose
788value is returned by invoking the @code{%site-ccache-dir} procedure. As
789in the previous example, if Guile @value{EFFECTIVE-VERSION} is installed
790on your system in @code{/usr/}, then @code{(%site-ccache-dir)} site
791packages will be
24cc7832
AW
792@code{/usr/lib/guile/@value{EFFECTIVE-VERSION}/site-ccache}.
793
794Note that a @code{.go} file will only be loaded in preference to a
795@code{.scm} file if it is newer. For that reason, you should install
0740cb49
AW
796your Scheme files first, and your compiled files second. @code{Load
797Paths}, for more on the loading process.
24cc7832
AW
798
799Finally, although this section is only about Scheme, sometimes you need
800to install C extensions too. Shared libraries should be installed in
801the @dfn{extensions dir}. This value can be had from the build config
802(@pxref{Build Config}). Again, if Guile @value{EFFECTIVE-VERSION} is
803installed on your system in @code{/usr/}, then the extensions dir will
804be @code{/usr/lib/guile/@value{EFFECTIVE-VERSION}/extensions}.
805
806
46f7666d
NJ
807@c Local Variables:
808@c TeX-master: "guile.texi"
809@c End: