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