scheme-using.texi 24 KB

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