Commit | Line | Data |
---|---|---|
46f7666d NJ |
1 | @c -*-texinfo-*- |
2 | @c This is part of the GNU Guile Reference Manual. | |
749c2532 | 3 | @c Copyright (C) 2006, 2010 |
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 | ||
10 | When 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 | |
12 | interactive interpreter where you can enter Scheme expressions, and | |
13 | Guile will evaluate them and print the results for you. Here are some | |
14 | simple examples. | |
15 | ||
16 | @lisp | |
749c2532 | 17 | scheme@@(guile-user)> (+ 3 4 5) |
dc3b2661 | 18 | $1 = 12 |
749c2532 | 19 | scheme@@(guile-user)> (display "Hello world!\n") |
46f7666d | 20 | Hello world! |
749c2532 | 21 | scheme@@(guile-user)> (values 'a 'b) |
dc3b2661 AW |
22 | $2 = a |
23 | $3 = b | |
46f7666d NJ |
24 | @end lisp |
25 | ||
26 | @noindent | |
27 | This mode of use is called a @dfn{REPL}, which is short for | |
28 | ``Read-Eval-Print Loop'', because the Guile interpreter first reads the | |
29 | expression that you have typed, then evaluates it, and then prints the | |
30 | result. | |
31 | ||
749c2532 AW |
32 | The prompt shows you what language and module you are in. In this case, the |
33 | current language is @code{scheme}, and the current module is | |
34 | @code{(guile-user)}. @xref{Other Languages}, for more information on Guile's | |
35 | support for languages other than Scheme. | |
36 | ||
46f7666d | 37 | @menu |
3c0b7725 | 38 | * Readline:: |
ca290a89 | 39 | * Value History:: |
3c0b7725 AW |
40 | * REPL Commands:: |
41 | * Error Handling:: | |
42 | * Interactive Debugging:: | |
46f7666d NJ |
43 | @end menu |
44 | ||
45 | ||
46 | @node Readline | |
47 | @subsection Readline | |
48 | ||
49 | To make it easier for you to repeat and vary previously entered | |
50 | expressions, or to edit the expression that you're typing in, Guile | |
51 | can use the GNU Readline library. This is not enabled by default | |
52 | because of licensing reasons, but all you need to activate Readline is | |
53 | the following pair of lines. | |
54 | ||
55 | @lisp | |
749c2532 AW |
56 | scheme@@(guile-user)> (use-modules (ice-9 readline)) |
57 | scheme@@(guile-user)> (activate-readline) | |
46f7666d NJ |
58 | @end lisp |
59 | ||
ced9917e AW |
60 | It's a good idea to put these two lines (without the |
61 | @code{scheme@@(guile-user)>} prompts) in your @file{.guile} file. Guile | |
62 | reads this file when it starts up interactively, so anything in this | |
63 | file has the same effect as if you type it in by hand at the | |
64 | @code{scheme@@(guile-user)>} prompt. | |
46f7666d NJ |
65 | |
66 | ||
ca290a89 | 67 | @node Value History |
46f7666d NJ |
68 | @subsection Value History |
69 | ||
70 | Just as Readline helps you to reuse a previous input line, @dfn{value | |
ced9917e AW |
71 | history} allows you to use the @emph{result} of a previous evaluation in |
72 | a new expression. When value history is enabled, each evaluation result | |
73 | is automatically assigned to the next in the sequence of variables | |
74 | @code{$1}, @code{$2}, @dots{}. You can then use these variables in | |
75 | subsequent expressions. | |
46f7666d NJ |
76 | |
77 | @lisp | |
749c2532 | 78 | scheme@@(guile-user)> (iota 10) |
46f7666d | 79 | $1 = (0 1 2 3 4 5 6 7 8 9) |
749c2532 | 80 | scheme@@(guile-user)> (apply * (cdr $1)) |
46f7666d | 81 | $2 = 362880 |
749c2532 | 82 | scheme@@(guile-user)> (sqrt $2) |
46f7666d | 83 | $3 = 602.3952191045344 |
749c2532 | 84 | scheme@@(guile-user)> (cons $2 $1) |
46f7666d NJ |
85 | $4 = (362880 0 1 2 3 4 5 6 7 8 9) |
86 | @end lisp | |
87 | ||
dc3b2661 AW |
88 | Value history is enabled by default, because Guile's REPL imports the |
89 | @code{(ice-9 history)} module. Value history may be turned off or on within the | |
90 | repl, using the options interface: | |
91 | ||
92 | @lisp | |
93 | scheme@@(guile-user)> ,option value-history #f | |
94 | scheme@@(guile-user)> 'foo | |
95 | foo | |
96 | scheme@@(guile-user)> ,option value-history #t | |
97 | scheme@@(guile-user)> 'bar | |
98 | $5 = bar | |
99 | @end lisp | |
100 | ||
101 | Note that previously recorded values are still accessible, even if value history | |
102 | is off. In rare cases, these references to past computations can cause Guile to | |
103 | use too much memory. One may clear these values, possibly enabling garbage | |
104 | collection, via the @code{clear-value-history!} procedure, described below. | |
105 | ||
106 | The programmatic interface to value history is in a module: | |
107 | ||
108 | @lisp | |
109 | (use-modules (ice-9 history)) | |
110 | @end lisp | |
111 | ||
112 | @deffn {Scheme Procedure} value-history-enabled? | |
113 | Return true iff value history is enabled. | |
114 | @end deffn | |
115 | ||
116 | @deffn {Scheme Procedure} enable-value-history! | |
117 | Turn on value history, if it was off. | |
118 | @end deffn | |
119 | ||
120 | @deffn {Scheme Procedure} disable-value-history! | |
121 | Turn off value history, if it was on. | |
122 | @end deffn | |
123 | ||
124 | @deffn {Scheme Procedure} clear-value-history! | |
125 | Clear the value history. If the stored values are not captured by some other | |
126 | data structure or closure, they may then be reclaimed by the garbage collector. | |
127 | @end deffn | |
46f7666d NJ |
128 | |
129 | ||
3c0b7725 AW |
130 | @node REPL Commands |
131 | @subsection REPL Commands | |
46f7666d | 132 | |
3c0b7725 AW |
133 | @cindex commands |
134 | The REPL exists to read expressions, evaluate them, and then print their | |
135 | results. But sometimes one wants to tell the REPL to evaluate an | |
136 | expression in a different way, or to do something else altogether. A | |
137 | user can affect the way the REPL works with a @dfn{REPL command}. | |
46f7666d | 138 | |
3c0b7725 AW |
139 | The previous section had an example of a command, in the form of |
140 | @code{,option}. | |
46f7666d NJ |
141 | |
142 | @lisp | |
3c0b7725 | 143 | scheme@@(guile-user)> ,option value-history #t |
46f7666d NJ |
144 | @end lisp |
145 | ||
146 | @noindent | |
3c0b7725 AW |
147 | Commands are distinguished from expressions by their initial comma |
148 | (@samp{,}). Since a comma cannot begin an expression in most languages, | |
149 | it is an effective indicator to the REPL that the following text forms a | |
150 | command, not an expression. | |
46f7666d | 151 | |
3c0b7725 AW |
152 | REPL commands are convenient because they are always there. Even if the |
153 | current module doesn't have a binding for @code{pretty-print}, one can | |
154 | always @code{,pretty-print}. | |
46f7666d | 155 | |
3c0b7725 AW |
156 | The following sections document the various commands, grouped together |
157 | by functionality. Many of the commands have abbreviations; see the | |
158 | online help (@code{,help}) for more information. | |
46f7666d | 159 | |
3c0b7725 AW |
160 | @menu |
161 | * Help Commands:: | |
162 | * Module Commands:: | |
163 | * Language Commands:: | |
164 | * Compile Commands:: | |
165 | * Profile Commands:: | |
166 | * Debug Commands:: | |
167 | * Inspect Commands:: | |
168 | * System Commands:: | |
169 | @end menu | |
46f7666d | 170 | |
3c0b7725 AW |
171 | @node Help Commands |
172 | @subsubsection Help Commands | |
46f7666d | 173 | |
3c0b7725 AW |
174 | When Guile starts interactively, it notifies the user that help can be |
175 | had by typing @samp{,help}. Indeed, @code{help} is a command, and a | |
176 | particularly useful one, as it allows the user to discover the rest of | |
177 | the commands. | |
46f7666d | 178 | |
ced9917e | 179 | @deffn {REPL Command} help [@code{all} | group | @code{[-c]} command] |
3c0b7725 | 180 | Show help. |
46f7666d | 181 | |
3c0b7725 AW |
182 | With one argument, tries to look up the argument as a group name, giving |
183 | help on that group if successful. Otherwise tries to look up the | |
184 | argument as a command, giving help on the command. | |
46f7666d | 185 | |
3c0b7725 AW |
186 | If there is a command whose name is also a group name, use the @samp{-c |
187 | @var{command}} form to give help on the command instead of the group. | |
46f7666d | 188 | |
3c0b7725 AW |
189 | Without any argument, a list of help commands and command groups |
190 | are displayed. | |
191 | @end deffn | |
46f7666d | 192 | |
3c0b7725 AW |
193 | @deffn {REPL Command} show [topic] |
194 | Gives information about Guile. | |
46f7666d | 195 | |
3c0b7725 AW |
196 | With one argument, tries to show a particular piece of information; |
197 | currently supported topics are `warranty' (or `w'), `copying' (or `c'), | |
198 | and `version' (or `v'). | |
46f7666d | 199 | |
3c0b7725 AW |
200 | Without any argument, a list of topics is displayed. |
201 | @end deffn | |
46f7666d | 202 | |
3c0b7725 AW |
203 | @deffn {REPL Command} apropos regexp |
204 | Find bindings/modules/packages. | |
205 | @end deffn | |
46f7666d | 206 | |
3c0b7725 AW |
207 | @deffn {REPL Command} describe obj |
208 | Show description/documentation. | |
209 | @end deffn | |
46f7666d | 210 | |
3c0b7725 AW |
211 | @node Module Commands |
212 | @subsubsection Module Commands | |
ee6be719 | 213 | |
3c0b7725 AW |
214 | @deffn {REPL Command} module [module] |
215 | Change modules / Show current module. | |
ee6be719 NJ |
216 | @end deffn |
217 | ||
3c0b7725 AW |
218 | @deffn {REPL Command} import [module ...] |
219 | Import modules / List those imported. | |
220 | @end deffn | |
46f7666d | 221 | |
3c0b7725 AW |
222 | @deffn {REPL Command} load file |
223 | Load a file in the current module. | |
224 | @end deffn | |
46f7666d | 225 | |
3c0b7725 AW |
226 | @deffn {REPL Command} binding |
227 | List current bindings. | |
228 | @end deffn | |
46f7666d | 229 | |
8fdd85f8 AR |
230 | @deffn {REPL Command} in module expression |
231 | @deffnx {REPL Command} in module command [args ...] | |
232 | Evaluate an expression, or alternatively, execute another meta-command | |
233 | in the context of a module. For example, @samp{,in (foo bar) ,binding} | |
234 | will show the bindings in the module @code{(foo bar)}. | |
235 | @end deffn | |
236 | ||
3c0b7725 AW |
237 | @node Language Commands |
238 | @subsubsection Language Commands | |
46f7666d | 239 | |
3c0b7725 AW |
240 | @deffn {REPL Command} language language |
241 | Change languages. | |
46f7666d NJ |
242 | @end deffn |
243 | ||
3c0b7725 AW |
244 | @node Compile Commands |
245 | @subsubsection Compile Commands | |
46f7666d | 246 | |
3c0b7725 AW |
247 | @deffn {REPL Command} compile exp |
248 | Generate compiled code. | |
249 | @end deffn | |
46f7666d | 250 | |
3c0b7725 AW |
251 | @deffn {REPL Command} compile-file file |
252 | Compile a file. | |
253 | @end deffn | |
46f7666d | 254 | |
3c0b7725 AW |
255 | @deffn {REPL Command} disassemble exp |
256 | Disassemble a compiled procedure. | |
257 | @end deffn | |
46f7666d | 258 | |
3c0b7725 AW |
259 | @deffn {REPL Command} disassemble-file file |
260 | Disassemble a file. | |
261 | @end deffn | |
46f7666d | 262 | |
3c0b7725 AW |
263 | @node Profile Commands |
264 | @subsubsection Profile Commands | |
46f7666d | 265 | |
3c0b7725 AW |
266 | @deffn {REPL Command} time exp |
267 | Time execution. | |
46f7666d NJ |
268 | @end deffn |
269 | ||
3c0b7725 AW |
270 | @deffn {REPL Command} profile exp |
271 | Profile execution. | |
46f7666d NJ |
272 | @end deffn |
273 | ||
3c0b7725 AW |
274 | @deffn {REPL Command} trace exp |
275 | Trace execution. | |
46f7666d NJ |
276 | @end deffn |
277 | ||
3c0b7725 AW |
278 | @node Debug Commands |
279 | @subsubsection Debug Commands | |
46f7666d | 280 | |
3c0b7725 AW |
281 | These debugging commands are only available within a recursive REPL; |
282 | they do not work at the top level. | |
46f7666d | 283 | |
3c0b7725 AW |
284 | @deffn {REPL Command} backtrace [count] [#:width w] [#:full? f] |
285 | Print a backtrace. | |
46f7666d | 286 | |
3c0b7725 AW |
287 | Print a backtrace of all stack frames, or innermost @var{COUNT} frames. |
288 | If @var{count} is negative, the last @var{count} frames will be shown. | |
46f7666d NJ |
289 | @end deffn |
290 | ||
3c0b7725 AW |
291 | @deffn {REPL Command} up [count] |
292 | Select a calling stack frame. | |
293 | ||
294 | Select and print stack frames that called this one. | |
295 | An argument says how many frames up to go. | |
46f7666d NJ |
296 | @end deffn |
297 | ||
3c0b7725 AW |
298 | @deffn {REPL Command} down [count] |
299 | Select a called stack frame. | |
300 | ||
301 | Select and print stack frames called by this one. | |
302 | An argument says how many frames down to go. | |
46f7666d NJ |
303 | @end deffn |
304 | ||
3c0b7725 AW |
305 | @deffn {REPL Command} frame [idx] |
306 | Show a frame. | |
307 | ||
308 | Show the selected frame. With an argument, select a frame by index, | |
309 | then show it. | |
310 | @end deffn | |
46f7666d | 311 | |
3c0b7725 AW |
312 | @deffn {REPL Command} procedure |
313 | Print the procedure for the selected frame. | |
314 | @end deffn | |
46f7666d | 315 | |
3c0b7725 AW |
316 | @deffn {REPL Command} locals |
317 | Show local variables. | |
46f7666d | 318 | |
3c0b7725 | 319 | Show locally-bound variables in the selected frame. |
46f7666d NJ |
320 | @end deffn |
321 | ||
54d9a994 JOR |
322 | @deffn {REPL Command} error-message |
323 | @deffnx {REPL Command} error | |
324 | Show error message. | |
325 | ||
326 | Display the message associated with the error that started the current | |
327 | debugging REPL. | |
328 | @end deffn | |
329 | ||
1ecf39a6 AW |
330 | @deffn {REPL Command} registers |
331 | Show the VM registers associated with the current frame. | |
332 | ||
333 | @xref{Stack Layout}, for more information on VM stack frames. | |
334 | @end deffn | |
335 | ||
336 | The next 3 commands work at any REPL. | |
337 | ||
338 | @deffn {REPL Command} break proc | |
339 | Set a breakpoint at @var{proc}. | |
340 | @end deffn | |
341 | ||
342 | @deffn {REPL Command} break-at-source file line | |
343 | Set a breakpoint at the given source location. | |
344 | @end deffn | |
345 | ||
346 | @deffn {REPL Command} tracepoint proc | |
347 | Set a tracepoint on the given procedure. This will cause all calls to | |
348 | the procedure to print out a tracing message. @xref{Tracing Traps}, for | |
349 | more information. | |
350 | @end deffn | |
351 | ||
352 | The rest of the commands in this subsection all apply only when the | |
353 | stack is @dfn{continuable} --- in other words when it makes sense for | |
354 | the program that the stack comes from to continue running. Usually this | |
355 | means that the program stopped because of a trap or a breakpoint. | |
356 | ||
357 | @deffn {REPL Command} step | |
358 | Tell the debugged program to step to the next source location. | |
359 | @end deffn | |
360 | ||
361 | @deffn {REPL Command} next | |
362 | Tell the debugged program to step to the next source location in the | |
363 | same frame. (See @ref{Traps} for the details of how this works.) | |
364 | @end deffn | |
365 | ||
366 | @deffn {REPL Command} finish | |
367 | Tell the program being debugged to continue running until the completion | |
368 | of the current stack frame, and at that time to print the result and | |
369 | reenter the REPL. | |
370 | @end deffn | |
371 | ||
3c0b7725 AW |
372 | |
373 | @node Inspect Commands | |
374 | @subsubsection Inspect Commands | |
375 | ||
376 | @deffn {REPL Command} inspect EXP | |
377 | Inspect the result(s) of evaluating @var{exp}. | |
378 | @end deffn | |
46f7666d | 379 | |
3c0b7725 AW |
380 | @deffn {REPL Command} pretty-print EXP |
381 | Pretty-print the result(s) of evaluating @var{exp}. | |
382 | @end deffn | |
46f7666d | 383 | |
3c0b7725 AW |
384 | @node System Commands |
385 | @subsubsection System Commands | |
46f7666d | 386 | |
3c0b7725 AW |
387 | @deffn {REPL Command} gc |
388 | Garbage collection. | |
46f7666d NJ |
389 | @end deffn |
390 | ||
3c0b7725 AW |
391 | @deffn {REPL Command} statistics |
392 | Display statistics. | |
46f7666d NJ |
393 | @end deffn |
394 | ||
3c0b7725 AW |
395 | @deffn {REPL Command} option [key value] |
396 | List/show/set options. | |
46f7666d NJ |
397 | @end deffn |
398 | ||
3c0b7725 AW |
399 | @deffn {REPL Command} quit |
400 | Quit this session. | |
46f7666d NJ |
401 | @end deffn |
402 | ||
403 | ||
3c0b7725 AW |
404 | @node Error Handling |
405 | @subsection Error Handling | |
406 | ||
407 | When code being evaluated from the REPL hits an error, Guile enters a | |
408 | new prompt, allowing you to inspect the context of the error. | |
409 | ||
410 | @lisp | |
411 | scheme@@(guile-user)> (map string-append '("a" "b") '("c" #\d)) | |
412 | ERROR: In procedure string-append: | |
413 | ERROR: Wrong type (expecting string): #\d | |
414 | Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue. | |
415 | scheme@@(guile-user) [1]> | |
416 | @end lisp | |
417 | ||
418 | The new prompt runs inside the old one, in the dynamic context of the | |
419 | error. It is a recursive REPL, augmented with a reified representation | |
420 | of the stack, ready for debugging. | |
421 | ||
422 | @code{,backtrace} (abbreviated @code{,bt}) displays the Scheme call | |
423 | stack at the point where the error occurred: | |
424 | ||
425 | @lisp | |
426 | scheme@@(guile-user) [1]> ,bt | |
427 | 1 (map #<procedure string-append _> ("a" "b") ("c" #\d)) | |
428 | 0 (string-append "b" #\d) | |
429 | @end lisp | |
430 | ||
431 | In the above example, the backtrace doesn't have much source | |
432 | information, as @code{map} and @code{string-append} are both | |
433 | primitives. But in the general case, the space on the left of the | |
434 | backtrace indicates the line and column in which a given procedure calls | |
435 | another. | |
436 | ||
437 | You can exit a recursive REPL in the same way that you exit any REPL: | |
438 | via @samp{(quit)}, @samp{,quit} (abbreviated @samp{,q}), or | |
439 | @kbd{C-d}, among other options. | |
440 | ||
441 | ||
442 | @node Interactive Debugging | |
443 | @subsection Interactive Debugging | |
444 | ||
445 | A recursive debugging REPL exposes a number of other meta-commands that | |
446 | inspect the state of the computation at the time of the error. These | |
447 | commands allow you to | |
448 | ||
449 | @itemize @bullet | |
450 | @item | |
451 | display the Scheme call stack at the point where the error occurred; | |
452 | ||
453 | @item | |
454 | move up and down the call stack, to see in detail the expression being | |
455 | evaluated, or the procedure being applied, in each @dfn{frame}; and | |
456 | ||
457 | @item | |
458 | examine the values of variables and expressions in the context of each | |
459 | frame. | |
460 | @end itemize | |
461 | ||
462 | @noindent | |
463 | @xref{Debug Commands}, for documentation of the individual | |
464 | commands. This section aims to give more of a walkthrough of a typical | |
465 | debugging session. | |
466 | ||
467 | First, we're going to need a good error. Let's try to macroexpand the | |
468 | expression @code{(unquote foo)}, outside of a @code{quasiquote} form, | |
469 | and see how the macroexpander reports this error. | |
470 | ||
471 | @lisp | |
472 | scheme@@(guile-user)> (macroexpand '(unquote foo)) | |
473 | ERROR: In procedure macroexpand: | |
474 | ERROR: unquote: expression not valid outside of quasiquote in (unquote foo) | |
475 | Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue. | |
476 | scheme@@(guile-user) [1]> | |
477 | @end lisp | |
478 | ||
479 | The @code{backtrace} command, which can also be invoked as @code{bt}, | |
480 | displays the call stack (aka backtrace) at the point where the debugger | |
481 | was entered: | |
482 | ||
483 | @lisp | |
484 | scheme@@(guile-user) [1]> ,bt | |
485 | In ice-9/psyntax.scm: | |
486 | 1130:21 3 (chi-top (unquote foo) () ((top)) e (eval) (hygiene #)) | |
487 | 1071:30 2 (syntax-type (unquote foo) () ((top)) #f #f (# #) #f) | |
488 | 1368:28 1 (chi-macro #<procedure de9360 at ice-9/psyntax.scm...> ...) | |
489 | In unknown file: | |
490 | 0 (scm-error syntax-error macroexpand "~a: ~a in ~a" # #f) | |
491 | @end lisp | |
492 | ||
493 | A call stack consists of a sequence of stack @dfn{frames}, with each | |
494 | frame describing one procedure which is waiting to do something with the | |
495 | values returned by another. Here we see that there are four frames on | |
496 | the stack. | |
497 | ||
498 | Note that @code{macroexpand} is not on the stack -- it must have made a | |
499 | tail call to @code{chi-top}, as indeed we would find if we searched | |
500 | @code{ice-9/psyntax.scm} for its definition. | |
501 | ||
502 | When you enter the debugger, the innermost frame is selected, which | |
503 | means that the commands for getting information about the ``current'' | |
504 | frame, or for evaluating expressions in the context of the current | |
505 | frame, will do so by default with respect to the innermost frame. To | |
506 | select a different frame, so that these operations will apply to it | |
507 | instead, use the @code{up}, @code{down} and @code{frame} commands like | |
508 | this: | |
509 | ||
510 | @lisp | |
511 | scheme@@(guile-user) [1]> ,up | |
512 | In ice-9/psyntax.scm: | |
513 | 1368:28 1 (chi-macro #<procedure de9360 at ice-9/psyntax.scm...> ...) | |
514 | scheme@@(guile-user) [1]> ,frame 3 | |
515 | In ice-9/psyntax.scm: | |
516 | 1130:21 3 (chi-top (unquote foo) () ((top)) e (eval) (hygiene #)) | |
517 | scheme@@(guile-user) [1]> ,down | |
518 | In ice-9/psyntax.scm: | |
519 | 1071:30 2 (syntax-type (unquote foo) () ((top)) #f #f (# #) #f) | |
520 | @end lisp | |
521 | ||
522 | Perhaps we're interested in what's going on in frame 2, so we take a | |
523 | look at its local variables: | |
524 | ||
525 | @lisp | |
526 | scheme@@(guile-user) [1]> ,locals | |
527 | Local variables: | |
528 | $1 = e = (unquote foo) | |
529 | $2 = r = () | |
530 | $3 = w = ((top)) | |
531 | $4 = s = #f | |
532 | $5 = rib = #f | |
533 | $6 = mod = (hygiene guile-user) | |
534 | $7 = for-car? = #f | |
535 | $8 = first = unquote | |
536 | $9 = ftype = macro | |
537 | $10 = fval = #<procedure de9360 at ice-9/psyntax.scm:2817:2 (x)> | |
538 | $11 = fe = unquote | |
539 | $12 = fw = ((top)) | |
540 | $13 = fs = #f | |
541 | $14 = fmod = (hygiene guile-user) | |
542 | @end lisp | |
543 | ||
544 | All of the values are accessible by their value-history names | |
545 | (@code{$@var{n}}): | |
546 | ||
547 | @lisp | |
548 | scheme@@(guile-user) [1]> $10 | |
549 | $15 = #<procedure de9360 at ice-9/psyntax.scm:2817:2 (x)> | |
550 | @end lisp | |
551 | ||
552 | We can even invoke the procedure at the REPL directly: | |
553 | ||
554 | @lisp | |
555 | scheme@@(guile-user) [1]> ($10 'not-going-to-work) | |
556 | ERROR: In procedure macroexpand: | |
557 | ERROR: source expression failed to match any pattern in not-going-to-work | |
558 | Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue. | |
559 | @end lisp | |
560 | ||
561 | Well at this point we've caused an error within an error. Let's just | |
562 | quit back to the top level: | |
563 | ||
564 | @lisp | |
565 | scheme@@(guile-user) [2]> ,q | |
566 | scheme@@(guile-user) [1]> ,q | |
567 | scheme@@(guile-user)> | |
568 | @end lisp | |
569 | ||
570 | Finally, as a word to the wise: hackers close their REPL prompts with | |
571 | @kbd{C-d}. | |
572 | ||
573 | ||
46f7666d NJ |
574 | @node Using Guile in Emacs |
575 | @section Using Guile in Emacs | |
576 | ||
b20ef3a6 | 577 | @cindex Emacs |
767dbb1a AW |
578 | Any text editor can edit Scheme, but some are better than others. Emacs |
579 | is the best, of course, and not just because it is a fine text editor. | |
580 | Emacs has good support for Scheme out of the box, with sensible | |
581 | indentation rules, parenthesis-matching, syntax highlighting, and even a | |
582 | set of keybindings for structural editing, allowing navigation, | |
583 | cut-and-paste, and transposition operations that work on balanced | |
584 | S-expressions. | |
585 | ||
586 | As good as it is, though, two things will vastly improve your experience | |
587 | with Emacs and Guile. | |
588 | ||
589 | @cindex Paredit | |
590 | The first is Taylor Campbell's | |
591 | @uref{http://www.emacswiki.org/emacs/ParEdit, Paredit}. You should not | |
592 | code in any dialect of Lisp without Paredit. (They say that | |
593 | unopinionated writing is boring---hence this tone---but it's the | |
594 | truth, regardless.) Paredit is the bee's knees. | |
595 | ||
596 | @cindex Geiser | |
917b2bf6 NJ |
597 | The second is |
598 | @iftex | |
599 | Jos@'e | |
600 | @end iftex | |
601 | @ifnottex | |
602 | José | |
603 | @end ifnottex | |
604 | Antonio Ortega Ruiz's | |
767dbb1a AW |
605 | @uref{http://www.nongnu.org/geiser/, Geiser}. Geiser complements Emacs' |
606 | @code{scheme-mode} with tight integration to running Guile processes via | |
607 | a @code{comint-mode} REPL buffer. | |
608 | ||
609 | Of course there are keybindings to switch to the REPL, and a good REPL | |
610 | environment, but Geiser goes beyond that, providing: | |
01d2ee15 | 611 | |
767dbb1a | 612 | @itemize @bullet |
46f7666d | 613 | @item |
767dbb1a | 614 | Form evaluation in the context of the current file's module. |
46f7666d | 615 | @item |
767dbb1a | 616 | Macro expansion. |
46f7666d | 617 | @item |
767dbb1a | 618 | File/module loading and/or compilation. |
46f7666d | 619 | @item |
767dbb1a AW |
620 | Namespace-aware identifier completion (including local bindings, names |
621 | visible in the current module, and module names). | |
46f7666d | 622 | @item |
767dbb1a AW |
623 | Autodoc: the echo area shows information about the signature of the |
624 | procedure/macro around point automatically. | |
46f7666d | 625 | @item |
767dbb1a | 626 | Jump to definition of identifier at point. |
46f7666d | 627 | @item |
767dbb1a AW |
628 | Access to documentation (including docstrings when the implementation |
629 | provides it). | |
46f7666d | 630 | @item |
767dbb1a | 631 | Listings of identifiers exported by a given module. |
62ae9557 | 632 | @item |
767dbb1a | 633 | Listings of callers/callees of procedures. |
94a2c24a | 634 | @item |
767dbb1a | 635 | Rudimentary support for debugging and error navigation. |
62ae9557 | 636 | @item |
767dbb1a | 637 | Support for multiple, simultaneous REPLs. |
62ae9557 NJ |
638 | @end itemize |
639 | ||
767dbb1a AW |
640 | See Geiser's web page at @uref{http://www.nongnu.org/geiser/}, for more |
641 | information. | |
62ae9557 NJ |
642 | |
643 | ||
46f7666d NJ |
644 | @c Local Variables: |
645 | @c TeX-master: "guile.texi" | |
646 | @c End: |