scheme-using.texi 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  1. @c -*-texinfo-*-
  2. @c This is part of the GNU Guile Reference Manual.
  3. @c Copyright (C) 2006, 2010, 2011, 2012, 2013
  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 if value history is enabled, or false otherwise.
  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 [#:hz hz=100] @
  230. [#:count-calls? count-calls?=#f] [#:display-style display-style=list]
  231. Profile execution of an expression. This command compiled @var{exp} and
  232. then runs it within the statprof profiler, passing all keyword options
  233. to the @code{statprof} procedure. For more on statprof and on the the
  234. options available to this command, @xref{Statprof}.
  235. @end deffn
  236. @deffn {REPL Command} trace exp [#:width w] [#:max-indent i]
  237. Trace execution.
  238. By default, the trace will limit its width to the width of your
  239. terminal, or @var{width} if specified. Nested procedure invocations
  240. will be printed farther to the right, though if the width of the
  241. indentation passes the @var{max-indent}, the indentation is abbreviated.
  242. @end deffn
  243. @node Debug Commands
  244. @subsubsection Debug Commands
  245. These debugging commands are only available within a recursive REPL;
  246. they do not work at the top level.
  247. @deffn {REPL Command} backtrace [count] [#:width w] [#:full? f]
  248. Print a backtrace.
  249. Print a backtrace of all stack frames, or innermost @var{count} frames.
  250. If @var{count} is negative, the last @var{count} frames will be shown.
  251. @end deffn
  252. @deffn {REPL Command} up [count]
  253. Select a calling stack frame.
  254. Select and print stack frames that called this one.
  255. An argument says how many frames up to go.
  256. @end deffn
  257. @deffn {REPL Command} down [count]
  258. Select a called stack frame.
  259. Select and print stack frames called by this one.
  260. An argument says how many frames down to go.
  261. @end deffn
  262. @deffn {REPL Command} frame [idx]
  263. Show a frame.
  264. Show the selected frame. With an argument, select a frame by index,
  265. then show it.
  266. @end deffn
  267. @deffn {REPL Command} locals
  268. Show local variables.
  269. Show locally-bound variables in the selected frame.
  270. @end deffn
  271. @deffn {REPL Command} error-message
  272. @deffnx {REPL Command} error
  273. Show error message.
  274. Display the message associated with the error that started the current
  275. debugging REPL.
  276. @end deffn
  277. @deffn {REPL Command} registers
  278. Show the VM registers associated with the current frame.
  279. @xref{Stack Layout}, for more information on VM stack frames.
  280. @end deffn
  281. @deffn {REPL Command} width [cols]
  282. Sets the number of display columns in the output of @code{,backtrace}
  283. and @code{,locals} to @var{cols}. If @var{cols} is not given, the width
  284. of the terminal is used.
  285. @end deffn
  286. The next 3 commands work at any REPL.
  287. @deffn {REPL Command} break proc
  288. Set a breakpoint at @var{proc}.
  289. @end deffn
  290. @deffn {REPL Command} break-at-source file line
  291. Set a breakpoint at the given source location.
  292. @end deffn
  293. @deffn {REPL Command} tracepoint proc
  294. Set a tracepoint on the given procedure. This will cause all calls to
  295. the procedure to print out a tracing message. @xref{Tracing Traps}, for
  296. more information.
  297. @end deffn
  298. The rest of the commands in this subsection all apply only when the
  299. stack is @dfn{continuable} --- in other words when it makes sense for
  300. the program that the stack comes from to continue running. Usually this
  301. means that the program stopped because of a trap or a breakpoint.
  302. @deffn {REPL Command} step
  303. Tell the debugged program to step to the next source location.
  304. @end deffn
  305. @deffn {REPL Command} next
  306. Tell the debugged program to step to the next source location in the
  307. same frame. (See @ref{Traps} for the details of how this works.)
  308. @end deffn
  309. @deffn {REPL Command} finish
  310. Tell the program being debugged to continue running until the completion
  311. of the current stack frame, and at that time to print the result and
  312. reenter the REPL.
  313. @end deffn
  314. @node Inspect Commands
  315. @subsubsection Inspect Commands
  316. @deffn {REPL Command} inspect exp
  317. Inspect the result(s) of evaluating @var{exp}.
  318. @end deffn
  319. @deffn {REPL Command} pretty-print exp
  320. Pretty-print the result(s) of evaluating @var{exp}.
  321. @end deffn
  322. @node System Commands
  323. @subsubsection System Commands
  324. @deffn {REPL Command} gc
  325. Garbage collection.
  326. @end deffn
  327. @deffn {REPL Command} statistics
  328. Display statistics.
  329. @end deffn
  330. @deffn {REPL Command} option [name] [exp]
  331. With no arguments, lists all options. With one argument, shows the
  332. current value of the @var{name} option. With two arguments, sets the
  333. @var{name} option to the result of evaluating the Scheme expression
  334. @var{exp}.
  335. @end deffn
  336. @deffn {REPL Command} quit
  337. Quit this session.
  338. @end deffn
  339. Current REPL options include:
  340. @table @code
  341. @item compile-options
  342. The options used when compiling expressions entered at the REPL.
  343. @xref{Compilation}, for more on compilation options.
  344. @item interp
  345. Whether to interpret or compile expressions given at the REPL, if such a
  346. choice is available. Off by default (indicating compilation).
  347. @item prompt
  348. A customized REPL prompt. @code{#f} by default, indicating the default
  349. prompt.
  350. @item print
  351. A procedure of two arguments used to print the result of evaluating each
  352. expression. The arguments are the current REPL and the value to print.
  353. By default, @code{#f}, to use the default procedure.
  354. @item value-history
  355. Whether value history is on or not. @xref{Value History}.
  356. @item on-error
  357. What to do when an error happens. By default, @code{debug}, meaning to
  358. enter the debugger. Other values include @code{backtrace}, to show a
  359. backtrace without entering the debugger, or @code{report}, to simply
  360. show a short error printout.
  361. @end table
  362. Default values for REPL options may be set using
  363. @code{repl-default-option-set!} from @code{(system repl common)}:
  364. @deffn {Scheme Procedure} repl-default-option-set! key value
  365. Set the default value of a REPL option. This function is particularly
  366. useful in a user's init file. @xref{Init File}.
  367. @end deffn
  368. @node Error Handling
  369. @subsection Error Handling
  370. When code being evaluated from the REPL hits an error, Guile enters a
  371. new prompt, allowing you to inspect the context of the error.
  372. @lisp
  373. scheme@@(guile-user)> (map string-append '("a" "b") '("c" #\d))
  374. ERROR: In procedure string-append:
  375. ERROR: Wrong type (expecting string): #\d
  376. Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.
  377. scheme@@(guile-user) [1]>
  378. @end lisp
  379. The new prompt runs inside the old one, in the dynamic context of the
  380. error. It is a recursive REPL, augmented with a reified representation
  381. of the stack, ready for debugging.
  382. @code{,backtrace} (abbreviated @code{,bt}) displays the Scheme call
  383. stack at the point where the error occurred:
  384. @lisp
  385. scheme@@(guile-user) [1]> ,bt
  386. 1 (map #<procedure string-append _> ("a" "b") ("c" #\d))
  387. 0 (string-append "b" #\d)
  388. @end lisp
  389. In the above example, the backtrace doesn't have much source
  390. information, as @code{map} and @code{string-append} are both
  391. primitives. But in the general case, the space on the left of the
  392. backtrace indicates the line and column in which a given procedure calls
  393. another.
  394. You can exit a recursive REPL in the same way that you exit any REPL:
  395. via @samp{(quit)}, @samp{,quit} (abbreviated @samp{,q}), or
  396. @kbd{C-d}, among other options.
  397. @node Interactive Debugging
  398. @subsection Interactive Debugging
  399. A recursive debugging REPL exposes a number of other meta-commands that
  400. inspect the state of the computation at the time of the error. These
  401. commands allow you to
  402. @itemize @bullet
  403. @item
  404. display the Scheme call stack at the point where the error occurred;
  405. @item
  406. move up and down the call stack, to see in detail the expression being
  407. evaluated, or the procedure being applied, in each @dfn{frame}; and
  408. @item
  409. examine the values of variables and expressions in the context of each
  410. frame.
  411. @end itemize
  412. @noindent
  413. @xref{Debug Commands}, for documentation of the individual
  414. commands. This section aims to give more of a walkthrough of a typical
  415. debugging session.
  416. First, we're going to need a good error. Let's try to macroexpand the
  417. expression @code{(unquote foo)}, outside of a @code{quasiquote} form,
  418. and see how the macroexpander reports this error.
  419. @lisp
  420. scheme@@(guile-user)> (macroexpand '(unquote foo))
  421. ERROR: In procedure macroexpand:
  422. ERROR: unquote: expression not valid outside of quasiquote in (unquote foo)
  423. Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.
  424. scheme@@(guile-user) [1]>
  425. @end lisp
  426. The @code{backtrace} command, which can also be invoked as @code{bt},
  427. displays the call stack (aka backtrace) at the point where the debugger
  428. was entered:
  429. @lisp
  430. scheme@@(guile-user) [1]> ,bt
  431. In ice-9/psyntax.scm:
  432. 1130:21 3 (chi-top (unquote foo) () ((top)) e (eval) (hygiene #))
  433. 1071:30 2 (syntax-type (unquote foo) () ((top)) #f #f (# #) #f)
  434. 1368:28 1 (chi-macro #<procedure de9360 at ice-9/psyntax.scm...> ...)
  435. In unknown file:
  436. 0 (scm-error syntax-error macroexpand "~a: ~a in ~a" # #f)
  437. @end lisp
  438. A call stack consists of a sequence of stack @dfn{frames}, with each
  439. frame describing one procedure which is waiting to do something with the
  440. values returned by another. Here we see that there are four frames on
  441. the stack.
  442. Note that @code{macroexpand} is not on the stack -- it must have made a
  443. tail call to @code{chi-top}, as indeed we would find if we searched
  444. @code{ice-9/psyntax.scm} for its definition.
  445. When you enter the debugger, the innermost frame is selected, which
  446. means that the commands for getting information about the ``current''
  447. frame, or for evaluating expressions in the context of the current
  448. frame, will do so by default with respect to the innermost frame. To
  449. select a different frame, so that these operations will apply to it
  450. instead, use the @code{up}, @code{down} and @code{frame} commands like
  451. this:
  452. @lisp
  453. scheme@@(guile-user) [1]> ,up
  454. In ice-9/psyntax.scm:
  455. 1368:28 1 (chi-macro #<procedure de9360 at ice-9/psyntax.scm...> ...)
  456. scheme@@(guile-user) [1]> ,frame 3
  457. In ice-9/psyntax.scm:
  458. 1130:21 3 (chi-top (unquote foo) () ((top)) e (eval) (hygiene #))
  459. scheme@@(guile-user) [1]> ,down
  460. In ice-9/psyntax.scm:
  461. 1071:30 2 (syntax-type (unquote foo) () ((top)) #f #f (# #) #f)
  462. @end lisp
  463. Perhaps we're interested in what's going on in frame 2, so we take a
  464. look at its local variables:
  465. @lisp
  466. scheme@@(guile-user) [1]> ,locals
  467. Local variables:
  468. $1 = e = (unquote foo)
  469. $2 = r = ()
  470. $3 = w = ((top))
  471. $4 = s = #f
  472. $5 = rib = #f
  473. $6 = mod = (hygiene guile-user)
  474. $7 = for-car? = #f
  475. $8 = first = unquote
  476. $9 = ftype = macro
  477. $10 = fval = #<procedure de9360 at ice-9/psyntax.scm:2817:2 (x)>
  478. $11 = fe = unquote
  479. $12 = fw = ((top))
  480. $13 = fs = #f
  481. $14 = fmod = (hygiene guile-user)
  482. @end lisp
  483. All of the values are accessible by their value-history names
  484. (@code{$@var{n}}):
  485. @lisp
  486. scheme@@(guile-user) [1]> $10
  487. $15 = #<procedure de9360 at ice-9/psyntax.scm:2817:2 (x)>
  488. @end lisp
  489. We can even invoke the procedure at the REPL directly:
  490. @lisp
  491. scheme@@(guile-user) [1]> ($10 'not-going-to-work)
  492. ERROR: In procedure macroexpand:
  493. ERROR: source expression failed to match any pattern in not-going-to-work
  494. Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.
  495. @end lisp
  496. Well at this point we've caused an error within an error. Let's just
  497. quit back to the top level:
  498. @lisp
  499. scheme@@(guile-user) [2]> ,q
  500. scheme@@(guile-user) [1]> ,q
  501. scheme@@(guile-user)>
  502. @end lisp
  503. Finally, as a word to the wise: hackers close their REPL prompts with
  504. @kbd{C-d}.
  505. @node Using Guile in Emacs
  506. @section Using Guile in Emacs
  507. @cindex Emacs
  508. Any text editor can edit Scheme, but some are better than others. Emacs
  509. is the best, of course, and not just because it is a fine text editor.
  510. Emacs has good support for Scheme out of the box, with sensible
  511. indentation rules, parenthesis-matching, syntax highlighting, and even a
  512. set of keybindings for structural editing, allowing navigation,
  513. cut-and-paste, and transposition operations that work on balanced
  514. S-expressions.
  515. As good as it is, though, two things will vastly improve your experience
  516. with Emacs and Guile.
  517. @cindex Paredit
  518. The first is Taylor Campbell's
  519. @uref{http://www.emacswiki.org/emacs/ParEdit, Paredit}. You should not
  520. code in any dialect of Lisp without Paredit. (They say that
  521. unopinionated writing is boring---hence this tone---but it's the
  522. truth, regardless.) Paredit is the bee's knees.
  523. @cindex Geiser
  524. The second is
  525. @iftex
  526. Jos@'e
  527. @end iftex
  528. @ifnottex
  529. José
  530. @end ifnottex
  531. Antonio Ortega Ruiz's
  532. @uref{http://www.nongnu.org/geiser/, Geiser}. Geiser complements Emacs'
  533. @code{scheme-mode} with tight integration to running Guile processes via
  534. a @code{comint-mode} REPL buffer.
  535. Of course there are keybindings to switch to the REPL, and a good REPL
  536. environment, but Geiser goes beyond that, providing:
  537. @itemize @bullet
  538. @item
  539. Form evaluation in the context of the current file's module.
  540. @item
  541. Macro expansion.
  542. @item
  543. File/module loading and/or compilation.
  544. @item
  545. Namespace-aware identifier completion (including local bindings, names
  546. visible in the current module, and module names).
  547. @item
  548. Autodoc: the echo area shows information about the signature of the
  549. procedure/macro around point automatically.
  550. @item
  551. Jump to definition of identifier at point.
  552. @item
  553. Access to documentation (including docstrings when the implementation
  554. provides it).
  555. @item
  556. Listings of identifiers exported by a given module.
  557. @item
  558. Listings of callers/callees of procedures.
  559. @item
  560. Rudimentary support for debugging and error navigation.
  561. @item
  562. Support for multiple, simultaneous REPLs.
  563. @end itemize
  564. See Geiser's web page at @uref{http://www.nongnu.org/geiser/}, for more
  565. information.
  566. @node Using Guile Tools
  567. @section Using Guile Tools
  568. @cindex guild
  569. @cindex guile-tools
  570. @cindex wizards
  571. Guile also comes with a growing number of command-line utilities: a
  572. compiler, a disassembler, some module inspectors, and in the future, a
  573. system to install Guile packages from the internet. These tools may be
  574. invoked using the @code{guild} program.
  575. @example
  576. $ guild compile -o foo.go foo.scm
  577. wrote `foo.go'
  578. @end example
  579. This program used to be called @code{guile-tools} up to
  580. Guile version 2.0.1, and for backward
  581. compatibility it still may be called as such. However we changed the
  582. name to @code{guild}, not only because it is pleasantly shorter and
  583. easier to read, but also because this tool will serve to bind Guile
  584. wizards together, by allowing hackers to share code with each other
  585. using a CPAN-like system.
  586. @xref{Compilation}, for more on @code{guild compile}.
  587. A complete list of guild scripts can be had by invoking @code{guild
  588. list}, or simply @code{guild}.
  589. @node Installing Site Packages
  590. @section Installing Site Packages
  591. @cindex site
  592. @cindex site path
  593. @cindex load path
  594. @findex %site-dir
  595. @findex %site-ccache-dir
  596. At some point, you will probably want to share your code with other
  597. people. To do so effectively, it is important to follow a set of common
  598. conventions, to make it easy for the user to install and use your
  599. package.
  600. The first thing to do is to install your Scheme files where Guile can
  601. find them. When Guile goes to find a Scheme file, it will search a
  602. @dfn{load path} to find the file: first in Guile's own path, then in
  603. paths for @dfn{site packages}. A site package is any Scheme code that
  604. is installed and not part of Guile itself. @xref{Load Paths}, for more
  605. on load paths.
  606. There are several site paths, for historical reasons, but the one that
  607. should generally be used can be obtained by invoking the
  608. @code{%site-dir} procedure. @xref{Build Config}. If Guile
  609. @value{EFFECTIVE-VERSION} is installed on your system in @code{/usr/},
  610. then @code{(%site-dir)} will be
  611. @code{/usr/share/guile/site/@value{EFFECTIVE-VERSION}}. Scheme files
  612. should be installed there.
  613. If you do not install compiled @code{.go} files, Guile will compile your
  614. modules and programs when they are first used, and cache them in the
  615. user's home directory. @xref{Compilation}, for more on
  616. auto-compilation. However, it is better to compile the files before
  617. they are installed, and to just copy the files to a place that Guile can
  618. find them.
  619. As with Scheme files, Guile searches a path to find compiled @code{.go}
  620. files, the @code{%load-compiled-path}. By default, this path has two
  621. entries: a path for Guile's files, and a path for site packages. You
  622. should install your @code{.go} files into the latter directory, whose
  623. value is returned by invoking the @code{%site-ccache-dir} procedure. As
  624. in the previous example, if Guile @value{EFFECTIVE-VERSION} is installed
  625. on your system in @code{/usr/}, then @code{(%site-ccache-dir)} site
  626. packages will be
  627. @code{/usr/lib/guile/@value{EFFECTIVE-VERSION}/site-ccache}.
  628. Note that a @code{.go} file will only be loaded in preference to a
  629. @code{.scm} file if it is newer. For that reason, you should install
  630. your Scheme files first, and your compiled files second. @xref{Load
  631. Paths}, for more on the loading process.
  632. Finally, although this section is only about Scheme, sometimes you need
  633. to install C extensions too. Shared libraries should be installed in
  634. the @dfn{extensions dir}. This value can be had from the build config
  635. (@pxref{Build Config}). Again, if Guile @value{EFFECTIVE-VERSION} is
  636. installed on your system in @code{/usr/}, then the extensions dir will
  637. be @code{/usr/lib/guile/@value{EFFECTIVE-VERSION}/extensions}.
  638. @c Local Variables:
  639. @c TeX-master: "guile.texi"
  640. @c End: