api-evaluation.texi 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630
  1. @c -*-texinfo-*-
  2. @c This is part of the GNU Guile Reference Manual.
  3. @c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009,
  4. @c 2010, 2011, 2012, 2013, 2014, 2020, 2021 Free Software Foundation, Inc.
  5. @c See the file guile.texi for copying conditions.
  6. @node Read/Load/Eval/Compile
  7. @section Reading and Evaluating Scheme Code
  8. This chapter describes Guile functions that are concerned with reading,
  9. loading, evaluating, and compiling Scheme code at run time.
  10. @menu
  11. * Scheme Syntax:: Standard and extended Scheme syntax.
  12. * Scheme Read:: Reading Scheme code.
  13. * Scheme Write:: Writing Scheme values to a port.
  14. * Fly Evaluation:: Procedures for on the fly evaluation.
  15. * Compilation:: How to compile Scheme files and procedures.
  16. * Loading:: Loading Scheme code from file.
  17. * Load Paths:: Where Guile looks for code.
  18. * Character Encoding of Source Files:: Loading non-ASCII Scheme code from file.
  19. * Delayed Evaluation:: Postponing evaluation until it is needed.
  20. * Local Evaluation:: Evaluation in a local lexical environment.
  21. * Local Inclusion:: Compile-time inclusion of one file in another.
  22. * Sandboxed Evaluation:: Evaluation with limited capabilities.
  23. * REPL Servers:: Serving a REPL over a socket.
  24. * Cooperative REPL Servers:: REPL server for single-threaded applications.
  25. @end menu
  26. @node Scheme Syntax
  27. @subsection Scheme Syntax: Standard and Guile Extensions
  28. @menu
  29. * Expression Syntax::
  30. * Comments::
  31. * Block Comments::
  32. * Case Sensitivity::
  33. * Keyword Syntax::
  34. * Reader Extensions::
  35. @end menu
  36. @node Expression Syntax
  37. @subsubsection Expression Syntax
  38. An expression to be evaluated takes one of the following forms.
  39. @table @nicode
  40. @item @var{symbol}
  41. A symbol is evaluated by dereferencing. A binding of that symbol is
  42. sought and the value there used. For example,
  43. @example
  44. (define x 123)
  45. x @result{} 123
  46. @end example
  47. @item (@var{proc} @var{args}@dots{})
  48. A parenthesised expression is a function call. @var{proc} and each
  49. argument are evaluated, then the function (which @var{proc} evaluated
  50. to) is called with those arguments.
  51. The order in which @var{proc} and the arguments are evaluated is
  52. unspecified, so be careful when using expressions with side effects.
  53. @example
  54. (max 1 2 3) @result{} 3
  55. (define (get-some-proc) min)
  56. ((get-some-proc) 1 2 3) @result{} 1
  57. @end example
  58. The same sort of parenthesised form is used for a macro invocation,
  59. but in that case the arguments are not evaluated. See the
  60. descriptions of macros for more on this (@pxref{Macros}, and
  61. @pxref{Syntax Rules}).
  62. @item @var{constant}
  63. Number, string, character and boolean constants evaluate ``to
  64. themselves'', so can appear as literals.
  65. @example
  66. 123 @result{} 123
  67. 99.9 @result{} 99.9
  68. "hello" @result{} "hello"
  69. #\z @result{} #\z
  70. #t @result{} #t
  71. @end example
  72. Note that an application must not attempt to modify literal strings,
  73. since they may be in read-only memory.
  74. @item (quote @var{data})
  75. @itemx '@var{data}
  76. @findex quote
  77. @findex '
  78. Quoting is used to obtain a literal symbol (instead of a variable
  79. reference), a literal list (instead of a function call), or a literal
  80. vector. @nicode{'} is simply a shorthand for a @code{quote} form.
  81. For example,
  82. @example
  83. 'x @result{} x
  84. '(1 2 3) @result{} (1 2 3)
  85. '#(1 (2 3) 4) @result{} #(1 (2 3) 4)
  86. (quote x) @result{} x
  87. (quote (1 2 3)) @result{} (1 2 3)
  88. (quote #(1 (2 3) 4)) @result{} #(1 (2 3) 4)
  89. @end example
  90. Note that an application must not attempt to modify literal lists or
  91. vectors obtained from a @code{quote} form, since they may be in
  92. read-only memory.
  93. @item (quasiquote @var{data})
  94. @itemx `@var{data}
  95. @findex quasiquote
  96. @findex `
  97. Backquote quasi-quotation is like @code{quote}, but selected
  98. sub-expressions are evaluated. This is a convenient way to construct
  99. a list or vector structure most of which is constant, but at certain
  100. points should have expressions substituted.
  101. The same effect can always be had with suitable @code{list},
  102. @code{cons} or @code{vector} calls, but quasi-quoting is often easier.
  103. @table @nicode
  104. @item (unquote @var{expr})
  105. @itemx ,@var{expr}
  106. @findex unquote
  107. @findex ,
  108. Within the quasiquote @var{data}, @code{unquote} or @code{,} indicates
  109. an expression to be evaluated and inserted. The comma syntax @code{,}
  110. is simply a shorthand for an @code{unquote} form. For example,
  111. @example
  112. `(1 2 (* 9 9) 3 4) @result{} (1 2 (* 9 9) 3 4)
  113. `(1 2 ,(* 9 9) 3 4) @result{} (1 2 81 3 4)
  114. `(1 (unquote (+ 1 1)) 3) @result{} (1 2 3)
  115. `#(1 ,(/ 12 2)) @result{} #(1 6)
  116. @end example
  117. @item (unquote-splicing @var{expr})
  118. @itemx ,@@@var{expr}
  119. @findex unquote-splicing
  120. @findex ,@@
  121. Within the quasiquote @var{data}, @code{unquote-splicing} or
  122. @code{,@@} indicates an expression to be evaluated and the elements of
  123. the returned list inserted. @var{expr} must evaluate to a list. The
  124. ``comma-at'' syntax @code{,@@} is simply a shorthand for an
  125. @code{unquote-splicing} form.
  126. @example
  127. (define x '(2 3))
  128. `(1 ,x 4) @result{} (1 (2 3) 4)
  129. `(1 ,@@x 4) @result{} (1 2 3 4)
  130. `(1 (unquote-splicing (map 1+ x))) @result{} (1 3 4)
  131. `#(9 ,@@x 9) @result{} #(9 2 3 9)
  132. @end example
  133. Notice @code{,@@} differs from plain @code{,} in the way one level of
  134. nesting is stripped. For @code{,@@} the elements of a returned list
  135. are inserted, whereas with @code{,} it would be the list itself
  136. inserted.
  137. @end table
  138. @c
  139. @c FIXME: What can we say about the mutability of a quasiquote
  140. @c result? R5RS doesn't seem to specify anything, though where it
  141. @c says backquote without commas is the same as plain quote then
  142. @c presumably the "fixed" portions of a quasiquote expression must be
  143. @c treated as immutable.
  144. @c
  145. @end table
  146. @node Comments
  147. @subsubsection Comments
  148. @c FIXME::martin: Review me!
  149. Comments in Scheme source files are written by starting them with a
  150. semicolon character (@code{;}). The comment then reaches up to the end
  151. of the line. Comments can begin at any column, and the may be inserted
  152. on the same line as Scheme code.
  153. @lisp
  154. ; Comment
  155. ;; Comment too
  156. (define x 1) ; Comment after expression
  157. (let ((y 1))
  158. ;; Display something.
  159. (display y)
  160. ;;; Comment at left margin.
  161. (display (+ y 1)))
  162. @end lisp
  163. It is common to use a single semicolon for comments following
  164. expressions on a line, to use two semicolons for comments which are
  165. indented like code, and three semicolons for comments which start at
  166. column 0, even if they are inside an indented code block. This
  167. convention is used when indenting code in Emacs' Scheme mode.
  168. @node Block Comments
  169. @subsubsection Block Comments
  170. @cindex multiline comments
  171. @cindex block comments
  172. @cindex #!
  173. @cindex !#
  174. @c FIXME::martin: Review me!
  175. In addition to the standard line comments defined by R5RS, Guile has
  176. another comment type for multiline comments, called @dfn{block
  177. comments}. This type of comment begins with the character sequence
  178. @code{#!} and ends with the characters @code{!#}.
  179. These comments are compatible with the block
  180. comments in the Scheme Shell @file{scsh} (@pxref{The Scheme shell
  181. (scsh)}). The characters @code{#!} were chosen because they are the
  182. magic characters used in shell scripts for indicating that the name of
  183. the program for executing the script follows on the same line.
  184. Thus a Guile script often starts like this.
  185. @lisp
  186. #! /usr/local/bin/guile -s
  187. !#
  188. @end lisp
  189. More details on Guile scripting can be found in the scripting section
  190. (@pxref{Guile Scripting}).
  191. @cindex R6RS block comments
  192. @cindex SRFI-30 block comments
  193. Similarly, Guile (starting from version 2.0) supports nested block
  194. comments as specified by R6RS and
  195. @url{http://srfi.schemers.org/srfi-30/srfi-30.html, SRFI-30}:
  196. @lisp
  197. (+ 1 #| this is a #| nested |# block comment |# 2)
  198. @result{} 3
  199. @end lisp
  200. For backward compatibility, this syntax can be overridden with
  201. @code{read-hash-extend} (@pxref{Reader Extensions,
  202. @code{read-hash-extend}}).
  203. There is one special case where the contents of a comment can actually
  204. affect the interpretation of code. When a character encoding
  205. declaration, such as @code{coding: utf-8} appears in one of the first
  206. few lines of a source file, it indicates to Guile's default reader
  207. that this source code file is not ASCII. For details see @ref{Character
  208. Encoding of Source Files}.
  209. @node Case Sensitivity
  210. @subsubsection Case Sensitivity
  211. @cindex fold-case
  212. @cindex no-fold-case
  213. @c FIXME::martin: Review me!
  214. Scheme as defined in R5RS is not case sensitive when reading symbols.
  215. Guile, on the contrary is case sensitive by default, so the identifiers
  216. @lisp
  217. guile-whuzzy
  218. Guile-Whuzzy
  219. @end lisp
  220. are the same in R5RS Scheme, but are different in Guile.
  221. It is possible to turn off case sensitivity in Guile by setting the
  222. reader option @code{case-insensitive}. For more information on reader
  223. options, @xref{Scheme Read}.
  224. @lisp
  225. (read-enable 'case-insensitive)
  226. @end lisp
  227. It is also possible to disable (or enable) case sensitivity within a
  228. single file by placing the reader directives @code{#!fold-case} (or
  229. @code{#!no-fold-case}) within the file itself.
  230. @node Keyword Syntax
  231. @subsubsection Keyword Syntax
  232. @node Reader Extensions
  233. @subsubsection Reader Extensions
  234. @deffn {Scheme Procedure} read-hash-extend chr proc
  235. @deffnx {C Function} scm_read_hash_extend (chr, proc)
  236. Install the procedure @var{proc} for reading expressions
  237. starting with the character sequence @code{#} and @var{chr}.
  238. @var{proc} will be called with two arguments: the character
  239. @var{chr} and the port to read further data from. The object
  240. returned will be the return value of @code{read}.
  241. Passing @code{#f} for @var{proc} will remove a previous setting.
  242. @end deffn
  243. @node Scheme Read
  244. @subsection Reading Scheme Code
  245. @rnindex read
  246. @deffn {Scheme Procedure} read [port]
  247. @deffnx {C Function} scm_read (port)
  248. Read an s-expression from the input port @var{port}, or from
  249. the current input port if @var{port} is not specified.
  250. Any whitespace before the next token is discarded.
  251. @end deffn
  252. The behaviour of Guile's Scheme reader can be modified by manipulating
  253. its read options.
  254. @cindex options - read
  255. @cindex read options
  256. @deffn {Scheme Procedure} read-options [setting]
  257. Display the current settings of the global read options. If
  258. @var{setting} is omitted, only a short form of the current read options
  259. is printed. Otherwise if @var{setting} is the symbol @code{help}, a
  260. complete options description is displayed.
  261. @end deffn
  262. The set of available options, and their default values, may be had by
  263. invoking @code{read-options} at the prompt.
  264. @smalllisp
  265. scheme@@(guile-user)> (read-options)
  266. (square-brackets keywords #f positions)
  267. scheme@@(guile-user)> (read-options 'help)
  268. positions yes Record positions of source code expressions.
  269. case-insensitive no Convert symbols to lower case.
  270. keywords #f Style of keyword recognition: #f, 'prefix or 'postfix.
  271. r6rs-hex-escapes no Use R6RS variable-length character and string hex escapes.
  272. square-brackets yes Treat `[' and `]' as parentheses, for R6RS compatibility.
  273. hungry-eol-escapes no In strings, consume leading whitespace after an
  274. escaped end-of-line.
  275. curly-infix no Support SRFI-105 curly infix expressions.
  276. r7rs-symbols no Support R7RS |...| symbol notation.
  277. @end smalllisp
  278. Note that Guile also includes a preliminary mechanism for setting read
  279. options on a per-port basis. For instance, the @code{case-insensitive}
  280. read option is set (or unset) on the port when the reader encounters the
  281. @code{#!fold-case} or @code{#!no-fold-case} reader directives.
  282. Similarly, the @code{#!curly-infix} reader directive sets the
  283. @code{curly-infix} read option on the port, and
  284. @code{#!curly-infix-and-bracket-lists} sets @code{curly-infix} and
  285. unsets @code{square-brackets} on the port (@pxref{SRFI-105}). There is
  286. currently no other way to access or set the per-port read options.
  287. The boolean options may be toggled with @code{read-enable} and
  288. @code{read-disable}. The non-boolean @code{keywords} option must be set
  289. using @code{read-set!}.
  290. @deffn {Scheme Procedure} read-enable option-name
  291. @deffnx {Scheme Procedure} read-disable option-name
  292. @deffnx {Scheme Syntax} read-set! option-name value
  293. Modify the read options. @code{read-enable} should be used with boolean
  294. options and switches them on, @code{read-disable} switches them off.
  295. @code{read-set!} can be used to set an option to a specific value. Due
  296. to historical oddities, it is a macro that expects an unquoted option
  297. name.
  298. @end deffn
  299. For example, to make @code{read} fold all symbols to their lower case
  300. (perhaps for compatibility with older Scheme code), you can enter:
  301. @lisp
  302. (read-enable 'case-insensitive)
  303. @end lisp
  304. For more information on the effect of the @code{r6rs-hex-escapes} and
  305. @code{hungry-eol-escapes} options, see (@pxref{String Syntax}).
  306. For more information on the @code{r7rs-symbols} option, see
  307. (@pxref{Symbol Read Syntax}).
  308. @node Scheme Write
  309. @subsection Writing Scheme Values
  310. Any scheme value may be written to a port. Not all values may be read
  311. back in (@pxref{Scheme Read}), however.
  312. @rnindex write
  313. @rnindex print
  314. @deffn {Scheme Procedure} write obj [port]
  315. Send a representation of @var{obj} to @var{port} or to the current
  316. output port if not given.
  317. The output is designed to be machine readable, and can be read back
  318. with @code{read} (@pxref{Scheme Read}). Strings are printed in
  319. double quotes, with escapes if necessary, and characters are printed in
  320. @samp{#\} notation.
  321. @end deffn
  322. @rnindex display
  323. @deffn {Scheme Procedure} display obj [port]
  324. Send a representation of @var{obj} to @var{port} or to the current
  325. output port if not given.
  326. The output is designed for human readability, it differs from
  327. @code{write} in that strings are printed without double quotes and
  328. escapes, and characters are printed as per @code{write-char}, not in
  329. @samp{#\} form.
  330. @end deffn
  331. As was the case with the Scheme reader, there are a few options that
  332. affect the behavior of the Scheme printer.
  333. @cindex options - print
  334. @cindex print options
  335. @deffn {Scheme Procedure} print-options [setting]
  336. Display the current settings of the read options. If @var{setting} is
  337. omitted, only a short form of the current read options is
  338. printed. Otherwise if @var{setting} is the symbol @code{help}, a
  339. complete options description is displayed.
  340. @end deffn
  341. The set of available options, and their default values, may be had by
  342. invoking @code{print-options} at the prompt.
  343. @smalllisp
  344. scheme@@(guile-user)> (print-options)
  345. (quote-keywordish-symbols reader highlight-suffix "@}" highlight-prefix "@{")
  346. scheme@@(guile-user)> (print-options 'help)
  347. highlight-prefix @{ The string to print before highlighted values.
  348. highlight-suffix @} The string to print after highlighted values.
  349. quote-keywordish-symbols reader How to print symbols that have a colon
  350. as their first or last character. The
  351. value '#f' does not quote the colons;
  352. '#t' quotes them; 'reader' quotes them
  353. when the reader option 'keywords' is
  354. not '#f'.
  355. escape-newlines yes Render newlines as \n when printing
  356. using `write'.
  357. r7rs-symbols no Escape symbols using R7RS |...| symbol
  358. notation.
  359. @end smalllisp
  360. These options may be modified with the print-set! syntax.
  361. @deffn {Scheme Syntax} print-set! option-name value
  362. Modify the print options. Due to historical oddities, @code{print-set!}
  363. is a macro that expects an unquoted option name.
  364. @end deffn
  365. @node Fly Evaluation
  366. @subsection Procedures for On the Fly Evaluation
  367. Scheme has the lovely property that its expressions may be represented
  368. as data. The @code{eval} procedure takes a Scheme datum and evaluates
  369. it as code.
  370. @rnindex eval
  371. @c ARGFIXME environment/environment specifier
  372. @deffn {Scheme Procedure} eval exp module_or_state
  373. @deffnx {C Function} scm_eval (exp, module_or_state)
  374. Evaluate @var{exp}, a list representing a Scheme expression,
  375. in the top-level environment specified by @var{module_or_state}.
  376. While @var{exp} is evaluated (using @code{primitive-eval}),
  377. @var{module_or_state} is made the current module. The current module
  378. is reset to its previous value when @code{eval} returns.
  379. XXX - dynamic states.
  380. Example: (eval '(+ 1 2) (interaction-environment))
  381. @end deffn
  382. @rnindex interaction-environment
  383. @deffn {Scheme Procedure} interaction-environment
  384. @deffnx {C Function} scm_interaction_environment ()
  385. Return a specifier for the environment that contains
  386. implementation--defined bindings, typically a superset of those
  387. listed in the report. The intent is that this procedure will
  388. return the environment in which the implementation would
  389. evaluate expressions dynamically typed by the user.
  390. @end deffn
  391. @xref{Environments}, for other environments.
  392. One does not always receive code as Scheme data, of course, and this is
  393. especially the case for Guile's other language implementations
  394. (@pxref{Other Languages}). For the case in which all you have is a
  395. string, we have @code{eval-string}. There is a legacy version of this
  396. procedure in the default environment, but you really want the one from
  397. @code{(ice-9 eval-string)}, so load it up:
  398. @example
  399. (use-modules (ice-9 eval-string))
  400. @end example
  401. @deffn {Scheme Procedure} eval-string string [#:module=#f] [#:file=#f] @
  402. [#:line=#f] [#:column=#f] @
  403. [#:lang=(current-language)] @
  404. [#:compile?=#f]
  405. Parse @var{string} according to the current language, normally Scheme.
  406. Evaluate or compile the expressions it contains, in order, returning the
  407. last expression.
  408. If the @var{module} keyword argument is set, save a module excursion
  409. (@pxref{Module System Reflection}) and set the current module to
  410. @var{module} before evaluation.
  411. The @var{file}, @var{line}, and @var{column} keyword arguments can be
  412. used to indicate that the source string begins at a particular source
  413. location.
  414. Finally, @var{lang} is a language, defaulting to the current language,
  415. and the expression is compiled if @var{compile?} is true or there is no
  416. evaluator for the given language.
  417. @end deffn
  418. @deffn {C Function} scm_eval_string (string)
  419. @deffnx {C Function} scm_eval_string_in_module (string, module)
  420. These C bindings call @code{eval-string} from @code{(ice-9
  421. eval-string)}, evaluating within @var{module} or the current module.
  422. @end deffn
  423. @deftypefn {C Function} SCM scm_c_eval_string (const char *string)
  424. @code{scm_eval_string}, but taking a C string in locale encoding instead
  425. of an @code{SCM}.
  426. @end deftypefn
  427. @deffn {Scheme Procedure} apply proc arg @dots{} arglst
  428. @deffnx {C Function} scm_apply_0 (proc, arglst)
  429. @deffnx {C Function} scm_apply_1 (proc, arg1, arglst)
  430. @deffnx {C Function} scm_apply_2 (proc, arg1, arg2, arglst)
  431. @deffnx {C Function} scm_apply_3 (proc, arg1, arg2, arg3, arglst)
  432. @deffnx {C Function} scm_apply (proc, arg, rest)
  433. @rnindex apply
  434. Call @var{proc} with arguments @var{arg} @dots{} and the
  435. elements of the @var{arglst} list.
  436. @code{scm_apply} takes parameters corresponding to a Scheme level
  437. @code{(lambda (proc arg1 . rest) ...)}. So @var{arg1} and all but the
  438. last element of the @var{rest} list make up @var{arg} @dots{}, and the
  439. last element of @var{rest} is the @var{arglst} list. Or if @var{rest}
  440. is the empty list @code{SCM_EOL} then there's no @var{arg} @dots{}, and
  441. (@var{arg1}) is the @var{arglst}.
  442. @var{arglst} is not modified, but the @var{rest} list passed to
  443. @code{scm_apply} is modified.
  444. @end deffn
  445. @deffn {C Function} scm_call_0 (proc)
  446. @deffnx {C Function} scm_call_1 (proc, arg1)
  447. @deffnx {C Function} scm_call_2 (proc, arg1, arg2)
  448. @deffnx {C Function} scm_call_3 (proc, arg1, arg2, arg3)
  449. @deffnx {C Function} scm_call_4 (proc, arg1, arg2, arg3, arg4)
  450. @deffnx {C Function} scm_call_5 (proc, arg1, arg2, arg3, arg4, arg5)
  451. @deffnx {C Function} scm_call_6 (proc, arg1, arg2, arg3, arg4, arg5, arg6)
  452. @deffnx {C Function} scm_call_7 (proc, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
  453. @deffnx {C Function} scm_call_8 (proc, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
  454. @deffnx {C Function} scm_call_9 (proc, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
  455. Call @var{proc} with the given arguments.
  456. @end deffn
  457. @deffn {C Function} scm_call (proc, ...)
  458. Call @var{proc} with any number of arguments. The argument list must be
  459. terminated by @code{SCM_UNDEFINED}. For example:
  460. @example
  461. scm_call (scm_c_public_ref ("guile", "+"),
  462. scm_from_int (1),
  463. scm_from_int (2),
  464. SCM_UNDEFINED);
  465. @end example
  466. @end deffn
  467. @deffn {C Function} scm_call_n (proc, argv, nargs)
  468. Call @var{proc} with the array of arguments @var{argv}, as a
  469. @code{SCM*}. The length of the arguments should be passed in
  470. @var{nargs}, as a @code{size_t}.
  471. @end deffn
  472. @deffn {Scheme Procedure} primitive-eval exp
  473. @deffnx {C Function} scm_primitive_eval (exp)
  474. Evaluate @var{exp} in the top-level environment specified by
  475. the current module.
  476. @end deffn
  477. @node Compilation
  478. @subsection Compiling Scheme Code
  479. The @code{eval} procedure directly interprets the S-expression
  480. representation of Scheme. An alternate strategy for evaluation is to
  481. determine ahead of time what computations will be necessary to
  482. evaluate the expression, and then use that recipe to produce the
  483. desired results. This is known as @dfn{compilation}.
  484. While it is possible to compile simple Scheme expressions such as
  485. @code{(+ 2 2)} or even @code{"Hello world!"}, compilation is most
  486. interesting in the context of procedures. Compiling a lambda expression
  487. produces a compiled procedure, which is just like a normal procedure
  488. except typically much faster, because it can bypass the generic
  489. interpreter.
  490. Functions from system modules in a Guile installation are normally
  491. compiled already, so they load and run quickly.
  492. @cindex automatic compilation
  493. Note that well-written Scheme programs will not typically call the
  494. procedures in this section, for the same reason that it is often bad
  495. taste to use @code{eval}. By default, Guile automatically compiles any
  496. files it encounters that have not been compiled yet (@pxref{Invoking
  497. Guile, @code{--auto-compile}}). The compiler can also be invoked
  498. explicitly from the shell as @code{guild compile foo.scm}.
  499. (Why are calls to @code{eval} and @code{compile} usually in bad taste?
  500. Because they are limited, in that they can only really make sense for
  501. top-level expressions. Also, most needs for ``compile-time''
  502. computation are fulfilled by macros and closures. Of course one good
  503. counterexample is the REPL itself, or any code that reads expressions
  504. from a port.)
  505. Automatic compilation generally works transparently, without any need
  506. for user intervention. However Guile does not yet do proper dependency
  507. tracking, so that if file @file{@var{a}.scm} uses macros from
  508. @file{@var{b}.scm}, and @var{@var{b}.scm} changes, @code{@var{a}.scm}
  509. would not be automatically recompiled. To forcibly invalidate the
  510. auto-compilation cache, pass the @code{--fresh-auto-compile} option to
  511. Guile, or set the @code{GUILE_AUTO_COMPILE} environment variable to
  512. @code{fresh} (instead of to @code{0} or @code{1}).
  513. For more information on the compiler itself, see @ref{Compiling to the
  514. Virtual Machine}. For information on the virtual machine, see @ref{A
  515. Virtual Machine for Guile}.
  516. The command-line interface to Guile's compiler is the @command{guild
  517. compile} command:
  518. @deffn {Command} {guild compile} [@option{option}...] @var{file}...
  519. Compile @var{file}, a source file, and store bytecode in the compilation cache
  520. or in the file specified by the @option{-o} option. The following options are
  521. available:
  522. @table @option
  523. @item -L @var{dir}
  524. @itemx --load-path=@var{dir}
  525. Add @var{dir} to the front of the module load path.
  526. @item -o @var{ofile}
  527. @itemx --output=@var{ofile}
  528. Write output bytecode to @var{ofile}. By convention, bytecode file
  529. names end in @code{.go}. When @option{-o} is omitted, the output file
  530. name is as for @code{compile-file} (see below).
  531. @item -x @var{extension}
  532. Recognize @var{extension} as a valid source file name extension.
  533. For example, to compile R6RS code, you might want to pass @command{-x
  534. .sls} so that files ending in @file{.sls} can be found.
  535. @item -W @var{warning}
  536. @itemx --warn=@var{warning}
  537. @cindex warnings, compiler
  538. Enable specific warning passes; use @code{-Whelp} for a list of
  539. available options. The default is @code{-W1}, which enables a number of
  540. common warnings. Pass @code{-W0} to disable all warnings.
  541. @item -O @var{opt}
  542. @itemx --optimize=@var{opt}
  543. @cindex optimizations, compiler
  544. Enable or disable specific compiler optimizations; use @code{-Ohelp} for
  545. a list of available options. The default is @code{-O2}, which enables
  546. most optimizations. @code{-O0} is recommended if compilation speed is
  547. more important than the speed of the compiled code. Pass
  548. @code{-Ono-@var{opt}} to disable a specific compiler pass. Any number
  549. of @code{-O} options can be passed to the compiler, with later ones
  550. taking precedence.
  551. @item --r6rs
  552. @itemx --r7rs
  553. Compile in an environment whose default bindings, reader options, and
  554. load paths are adapted for specific Scheme standards. @xref{R6RS
  555. Support}, and @xref{R7RS Support}.
  556. @item -f @var{lang}
  557. @itemx --from=@var{lang}
  558. Use @var{lang} as the source language of @var{file}. If this option is omitted,
  559. @code{scheme} is assumed.
  560. @item -t @var{lang}
  561. @itemx --to=@var{lang}
  562. Use @var{lang} as the target language of @var{file}. If this option is omitted,
  563. @code{rtl} is assumed.
  564. @item -T @var{target}
  565. @itemx --target=@var{target}
  566. Produce code for @var{target} instead of @var{%host-type} (@pxref{Build
  567. Config, %host-type}). Target must be a valid GNU triplet, such as
  568. @code{armv5tel-unknown-linux-gnueabi} (@pxref{Specifying Target
  569. Triplets,,, autoconf, GNU Autoconf Manual}).
  570. @end table
  571. Each @var{file} is assumed to be UTF-8-encoded, unless it contains a
  572. coding declaration as recognized by @code{file-encoding}
  573. (@pxref{Character Encoding of Source Files}).
  574. @end deffn
  575. The compiler can also be invoked directly by Scheme code. These
  576. interfaces are in their own module:
  577. @example
  578. (use-modules (system base compile))
  579. @end example
  580. @deffn {Scheme Procedure} compile exp [#:env=#f] @
  581. [#:from=(current-language)] @
  582. [#:to=value] [#:opts='()] @
  583. [#:optimization-level=(default-optimization-level)] @
  584. [#:warning-level=(default-warning-level)]
  585. Compile the expression @var{exp} in the environment @var{env}. If
  586. @var{exp} is a procedure, the result will be a compiled procedure;
  587. otherwise @code{compile} is mostly equivalent to @code{eval}.
  588. For a discussion of languages and compiler options, @xref{Compiling to
  589. the Virtual Machine}.
  590. @end deffn
  591. @deffn {Scheme Procedure} compile-file file [#:output-file=#f] @
  592. [#:from=(current-language)] [#:to='rtl] @
  593. [#:env=(default-environment from)] @
  594. [#:opts='()] @
  595. [#:optimization-level=(default-optimization-level)] @
  596. [#:warning-level=(default-warning-level)] @
  597. [#:canonicalization='relative]
  598. Compile the file named @var{file}.
  599. Output will be written to a @var{output-file}. If you do not supply an
  600. output file name, output is written to a file in the cache directory, as
  601. computed by @code{(compiled-file-name @var{file})}.
  602. @var{from} and @var{to} specify the source and target languages.
  603. @xref{Compiling to the Virtual Machine}, for more information on these
  604. options, and on @var{env} and @var{opts}.
  605. As with @command{guild compile}, @var{file} is assumed to be
  606. UTF-8-encoded unless it contains a coding declaration.
  607. @end deffn
  608. @deffn {Scheme Parameter} default-optimization-level
  609. The default optimization level, as an integer from 0 to 9. The default
  610. is 2.
  611. @end deffn
  612. @deffn {Scheme Parameter} default-warning-level
  613. The default warning level, as an integer from 0 to 9. The default is 1.
  614. @end deffn
  615. @xref{Parameters}, for more on how to set parameters.
  616. @deffn {Scheme Procedure} compiled-file-name file
  617. Compute a cached location for a compiled version of a Scheme file named
  618. @var{file}.
  619. This file will usually be below the @file{$HOME/.cache/guile/ccache}
  620. directory, depending on the value of the @env{XDG_CACHE_HOME}
  621. environment variable. The intention is that @code{compiled-file-name}
  622. provides a fallback location for caching auto-compiled files. If you
  623. want to place a compile file in the @code{%load-compiled-path}, you
  624. should pass the @var{output-file} option to @code{compile-file},
  625. explicitly.
  626. @end deffn
  627. @defvr {Scheme Variable} %auto-compilation-options
  628. This variable contains the options passed to the @code{compile-file}
  629. procedure when auto-compiling source files. By default, it enables
  630. useful compilation warnings. It can be customized from @file{~/.guile}.
  631. @end defvr
  632. @node Loading
  633. @subsection Loading Scheme Code from File
  634. @rnindex load
  635. @deffn {Scheme Procedure} load filename [reader]
  636. Load @var{filename} and evaluate its contents in the top-level
  637. environment.
  638. @var{reader} if provided should be either @code{#f}, or a procedure with
  639. the signature @code{(lambda (port) @dots{})} which reads the next
  640. expression from @var{port}. If @var{reader} is @code{#f} or absent,
  641. Guile's built-in @code{read} procedure is used (@pxref{Scheme Read}).
  642. The @var{reader} argument takes effect by setting the value of the
  643. @code{current-reader} fluid (see below) before loading the file, and
  644. restoring its previous value when loading is complete. The Scheme code
  645. inside @var{filename} can itself change the current reader procedure on
  646. the fly by setting @code{current-reader} fluid.
  647. If the variable @code{%load-hook} is defined, it should be bound to a
  648. procedure that will be called before any code is loaded. See
  649. documentation for @code{%load-hook} later in this section.
  650. @end deffn
  651. @deffn {Scheme Procedure} load-compiled filename
  652. Load the compiled file named @var{filename}.
  653. Compiling a source file (@pxref{Read/Load/Eval/Compile}) and then
  654. calling @code{load-compiled} on the resulting file is equivalent to
  655. calling @code{load} on the source file.
  656. @end deffn
  657. @deffn {Scheme Procedure} primitive-load filename
  658. @deffnx {C Function} scm_primitive_load (filename)
  659. Load the file named @var{filename} and evaluate its contents in the
  660. top-level environment. @var{filename} must either be a full pathname or
  661. be a pathname relative to the current directory. If the variable
  662. @code{%load-hook} is defined, it should be bound to a procedure that
  663. will be called before any code is loaded. See the documentation for
  664. @code{%load-hook} later in this section.
  665. @end deffn
  666. @deftypefn {C Function} SCM scm_c_primitive_load (const char *filename)
  667. @code{scm_primitive_load}, but taking a C string instead of an
  668. @code{SCM}.
  669. @end deftypefn
  670. @defvar current-reader
  671. @code{current-reader} holds the read procedure that is currently being
  672. used by the above loading procedures to read expressions (from the file
  673. that they are loading). @code{current-reader} is a fluid, so it has an
  674. independent value in each dynamic root and should be read and set using
  675. @code{fluid-ref} and @code{fluid-set!} (@pxref{Fluids and Dynamic
  676. States}).
  677. Changing @code{current-reader} is typically useful to introduce local
  678. syntactic changes, such that code following the @code{fluid-set!} call
  679. is read using the newly installed reader. The @code{current-reader}
  680. change should take place at evaluation time when the code is evaluated,
  681. or at compilation time when the code is compiled:
  682. @findex eval-when
  683. @example
  684. (eval-when (compile eval)
  685. (fluid-set! current-reader my-own-reader))
  686. @end example
  687. The @code{eval-when} form above ensures that the @code{current-reader}
  688. change occurs at the right time.
  689. @end defvar
  690. @defvar %load-hook
  691. A procedure to be called @code{(%load-hook @var{filename})} whenever a
  692. file is loaded, or @code{#f} for no such call. @code{%load-hook} is
  693. used by all of the loading functions (@code{load} and
  694. @code{primitive-load}, and @code{load-from-path} and
  695. @code{primitive-load-path} documented in the next section).
  696. For example an application can set this to show what's loaded,
  697. @example
  698. (set! %load-hook (lambda (filename)
  699. (format #t "Loading ~a ...\n" filename)))
  700. (load-from-path "foo.scm")
  701. @print{} Loading /usr/local/share/guile/site/foo.scm ...
  702. @end example
  703. @end defvar
  704. @deffn {Scheme Procedure} current-load-port
  705. @deffnx {C Function} scm_current_load_port ()
  706. Return the current-load-port.
  707. The load port is used internally by @code{primitive-load}.
  708. @end deffn
  709. @node Load Paths
  710. @subsection Load Paths
  711. The procedure in the previous section look for Scheme code in the file
  712. system at specific location. Guile also has some procedures to search
  713. the load path for code.
  714. @defvar %load-path
  715. List of directories which should be searched for Scheme modules and
  716. libraries. When Guile starts up, @code{%load-path} is initialized to
  717. the default load path @code{(list (%library-dir) (%site-dir)
  718. (%global-site-dir) (%package-data-dir))}. The @env{GUILE_LOAD_PATH}
  719. environment variable can be used to prepend or append additional
  720. directories (@pxref{Environment Variables}).
  721. @xref{Build Config}, for more on @code{%site-dir} and related
  722. procedures.
  723. @end defvar
  724. @deffn {Scheme Procedure} load-from-path filename
  725. Similar to @code{load}, but searches for @var{filename} in the load
  726. paths. Preferentially loads a compiled version of the file, if it is
  727. available and up-to-date.
  728. @end deffn
  729. A user can extend the load path by calling @code{add-to-load-path}.
  730. @deffn {Scheme Syntax} add-to-load-path dir
  731. Add @var{dir} to the load path.
  732. @end deffn
  733. For example, a script might include this form to add the directory that
  734. it is in to the load path:
  735. @example
  736. (add-to-load-path (dirname (current-filename)))
  737. @end example
  738. It's better to use @code{add-to-load-path} than to modify
  739. @code{%load-path} directly, because @code{add-to-load-path} takes care
  740. of modifying the path both at compile-time and at run-time.
  741. @deffn {Scheme Procedure} primitive-load-path filename [exception-on-not-found]
  742. @deffnx {C Function} scm_primitive_load_path (filename)
  743. Search @code{%load-path} for the file named @var{filename} and
  744. load it into the top-level environment. If @var{filename} is a
  745. relative pathname and is not found in the list of search paths,
  746. an error is signalled. Preferentially loads a compiled version of the
  747. file, if it is available and up-to-date.
  748. If @var{filename} is a relative pathname and is not found in the list of
  749. search paths, one of three things may happen, depending on the optional
  750. second argument, @var{exception-on-not-found}. If it is @code{#f},
  751. @code{#f} will be returned. If it is a procedure, it will be called
  752. with no arguments. (This allows a distinction to be made between
  753. exceptions raised by loading a file, and exceptions related to the
  754. loader itself.) Otherwise an error is signalled.
  755. For compatibility with Guile 1.8 and earlier, the C function takes only
  756. one argument, which can be either a string (the file name) or an
  757. argument list.
  758. @end deffn
  759. @deffn {Scheme Procedure} %search-load-path filename
  760. @deffnx {C Function} scm_sys_search_load_path (filename)
  761. Search @code{%load-path} for the file named @var{filename}, which must
  762. be readable by the current user. If @var{filename} is found in the list
  763. of paths to search or is an absolute pathname, return its full pathname.
  764. Otherwise, return @code{#f}. Filenames may have any of the optional
  765. extensions in the @code{%load-extensions} list; @code{%search-load-path}
  766. will try each extension automatically.
  767. @end deffn
  768. @defvar %load-extensions
  769. A list of default file extensions for files containing Scheme code.
  770. @code{%search-load-path} tries each of these extensions when looking for
  771. a file to load. By default, @code{%load-extensions} is bound to the
  772. list @code{("" ".scm")}.
  773. @end defvar
  774. As mentioned above, when Guile searches the @code{%load-path} for a
  775. source file, it will also search the @code{%load-compiled-path} for a
  776. corresponding compiled file. If the compiled file is as new or newer
  777. than the source file, it will be loaded instead of the source file,
  778. using @code{load-compiled}.
  779. @defvar %load-compiled-path
  780. Like @code{%load-path}, but for compiled files. By default, this path
  781. has two entries: one for compiled files from Guile itself, and one for
  782. site packages. The @env{GUILE_LOAD_COMPILED_PATH} environment variable
  783. can be used to prepend or append additional directories
  784. (@pxref{Environment Variables}).
  785. @end defvar
  786. When @code{primitive-load-path} searches the @code{%load-compiled-path}
  787. for a corresponding compiled file for a relative path it does so by
  788. appending @code{.go} to the relative path. For example, searching for
  789. @code{ice-9/popen} could find
  790. @code{/usr/lib/guile/3.0/ccache/ice-9/popen.go}, and use it instead of
  791. @code{/usr/share/guile/3.0/ice-9/popen.scm}.
  792. If @code{primitive-load-path} does not find a corresponding @code{.go}
  793. file in the @code{%load-compiled-path}, or the @code{.go} file is out of
  794. date, it will search for a corresponding auto-compiled file in the
  795. fallback path, possibly creating one if one does not exist.
  796. @xref{Installing Site Packages}, for more on how to correctly install
  797. site packages. @xref{Modules and the File System}, for more on the
  798. relationship between load paths and modules. @xref{Compilation}, for
  799. more on the fallback path and auto-compilation.
  800. Finally, there are a couple of helper procedures for general path
  801. manipulation.
  802. @deffn {Scheme Procedure} parse-path path [tail]
  803. @deffnx {C Function} scm_parse_path (path, tail)
  804. Parse @var{path}, which is expected to be a colon-separated string, into
  805. a list and return the resulting list with @var{tail} appended. If
  806. @var{path} is @code{#f}, @var{tail} is returned.
  807. @end deffn
  808. @deffn {Scheme Procedure} parse-path-with-ellipsis path base
  809. @deffnx {C Function} scm_parse_path_with_ellipsis (path, base)
  810. Parse @var{path}, which is expected to be a colon-separated string, into
  811. a list and return the resulting list with @var{base} (a list) spliced in
  812. place of the @code{...} path component, if present, or else @var{base}
  813. is added to the end. If @var{path} is @code{#f}, @var{base} is
  814. returned.
  815. @end deffn
  816. @deffn {Scheme Procedure} search-path path filename [extensions [require-exts?]]
  817. @deffnx {C Function} scm_search_path (path, filename, rest)
  818. Search @var{path} for a directory containing a file named
  819. @var{filename}. The file must be readable, and not a directory. If we
  820. find one, return its full filename; otherwise, return @code{#f}. If
  821. @var{filename} is absolute, return it unchanged. If given,
  822. @var{extensions} is a list of strings; for each directory in @var{path},
  823. we search for @var{filename} concatenated with each @var{extension}. If
  824. @var{require-exts?} is true, require that the returned file name have
  825. one of the given extensions; if @var{require-exts?} is not given, it
  826. defaults to @code{#f}.
  827. For compatibility with Guile 1.8 and earlier, the C function takes only
  828. three arguments.
  829. @end deffn
  830. @node Character Encoding of Source Files
  831. @subsection Character Encoding of Source Files
  832. @cindex source file encoding
  833. @cindex primitive-load
  834. @cindex load
  835. Scheme source code files are usually encoded in ASCII or UTF-8, but the
  836. built-in reader can interpret other character encodings as well. When
  837. Guile loads Scheme source code, it uses the @code{file-encoding}
  838. procedure (described below) to try to guess the encoding of the file.
  839. In the absence of any hints, UTF-8 is assumed. One way to provide a
  840. hint about the encoding of a source file is to place a coding
  841. declaration in the top 500 characters of the file.
  842. A coding declaration has the form @code{coding: XXXXXX}, where
  843. @code{XXXXXX} is the name of a character encoding in which the source
  844. code file has been encoded. The coding declaration must appear in a
  845. scheme comment. It can either be a semicolon-initiated comment, or the
  846. first block @code{#!} comment in the file.
  847. The name of the character encoding in the coding declaration is
  848. typically lower case and containing only letters, numbers, and hyphens,
  849. as recognized by @code{set-port-encoding!} (@pxref{Ports,
  850. @code{set-port-encoding!}}). Common examples of character encoding
  851. names are @code{utf-8} and @code{iso-8859-1},
  852. @url{http://www.iana.org/assignments/character-sets, as defined by
  853. IANA}. Thus, the coding declaration is mostly compatible with Emacs.
  854. However, there are some differences in encoding names recognized by
  855. Emacs and encoding names defined by IANA, the latter being essentially a
  856. subset of the former. For instance, @code{latin-1} is a valid encoding
  857. name for Emacs, but it's not according to the IANA standard, which Guile
  858. follows; instead, you should use @code{iso-8859-1}, which is both
  859. understood by Emacs and dubbed by IANA (IANA writes it uppercase but
  860. Emacs wants it lowercase and Guile is case insensitive.)
  861. For source code, only a subset of all possible character encodings can
  862. be interpreted by the built-in source code reader. Only those
  863. character encodings in which ASCII text appears unmodified can be
  864. used. This includes @code{UTF-8} and @code{ISO-8859-1} through
  865. @code{ISO-8859-15}. The multi-byte character encodings @code{UTF-16}
  866. and @code{UTF-32} may not be used because they are not compatible with
  867. ASCII.
  868. @cindex read
  869. @cindex encoding
  870. @cindex port encoding
  871. @findex set-port-encoding!
  872. There might be a scenario in which one would want to read non-ASCII
  873. code from a port, such as with the function @code{read}, instead of
  874. with @code{load}. If the port's character encoding is the same as the
  875. encoding of the code to be read by the port, not other special
  876. handling is necessary. The port will automatically do the character
  877. encoding conversion. The functions @code{setlocale} or by
  878. @code{set-port-encoding!} are used to set port encodings
  879. (@pxref{Ports}).
  880. If a port is used to read code of unknown character encoding, it can
  881. accomplish this in three steps. First, the character encoding of the
  882. port should be set to ISO-8859-1 using @code{set-port-encoding!}.
  883. Then, the procedure @code{file-encoding}, described below, is used to
  884. scan for a coding declaration when reading from the port. As a side
  885. effect, it rewinds the port after its scan is complete. After that,
  886. the port's character encoding should be set to the encoding returned
  887. by @code{file-encoding}, if any, again by using
  888. @code{set-port-encoding!}. Then the code can be read as normal.
  889. Alternatively, one can use the @code{#:guess-encoding} keyword argument
  890. of @code{open-file} and related procedures. @xref{File Ports}.
  891. @deffn {Scheme Procedure} file-encoding port
  892. @deffnx {C Function} scm_file_encoding (port)
  893. Attempt to scan the first few hundred bytes from the @var{port} for
  894. hints about its character encoding. Return a string containing the
  895. encoding name or @code{#f} if the encoding cannot be determined. The
  896. port is rewound.
  897. Currently, the only supported method is to look for an Emacs-like
  898. character coding declaration (@pxref{Recognize Coding, how Emacs
  899. recognizes file encoding,, emacs, The GNU Emacs Reference Manual}). The
  900. coding declaration is of the form @code{coding: XXXXX} and must appear
  901. in a Scheme comment. Additional heuristics may be added in the future.
  902. @end deffn
  903. @node Delayed Evaluation
  904. @subsection Delayed Evaluation
  905. @cindex delayed evaluation
  906. @cindex promises
  907. Promises are a convenient way to defer a calculation until its result
  908. is actually needed, and to run such a calculation only once. Also
  909. @pxref{SRFI-45}.
  910. @deffn syntax delay expr
  911. @rnindex delay
  912. Return a promise object which holds the given @var{expr} expression,
  913. ready to be evaluated by a later @code{force}.
  914. @end deffn
  915. @deffn {Scheme Procedure} promise? obj
  916. @deffnx {C Function} scm_promise_p (obj)
  917. Return true if @var{obj} is a promise.
  918. @end deffn
  919. @rnindex force
  920. @deffn {Scheme Procedure} force p
  921. @deffnx {C Function} scm_force (p)
  922. Return the value obtained from evaluating the @var{expr} in the given
  923. promise @var{p}. If @var{p} has previously been forced then its
  924. @var{expr} is not evaluated again, instead the value obtained at that
  925. time is simply returned.
  926. During a @code{force}, an @var{expr} can call @code{force} again on
  927. its own promise, resulting in a recursive evaluation of that
  928. @var{expr}. The first evaluation to return gives the value for the
  929. promise. Higher evaluations run to completion in the normal way, but
  930. their results are ignored, @code{force} always returns the first
  931. value.
  932. @end deffn
  933. @node Local Evaluation
  934. @subsection Local Evaluation
  935. Guile includes a facility to capture a lexical environment, and later
  936. evaluate a new expression within that environment. This code is
  937. implemented in a module.
  938. @example
  939. (use-modules (ice-9 local-eval))
  940. @end example
  941. @deffn syntax the-environment
  942. Captures and returns a lexical environment for use with
  943. @code{local-eval} or @code{local-compile}.
  944. @end deffn
  945. @deffn {Scheme Procedure} local-eval exp env
  946. @deffnx {C Function} scm_local_eval (exp, env)
  947. @deffnx {Scheme Procedure} local-compile exp env [opts=()]
  948. Evaluate or compile the expression @var{exp} in the lexical environment
  949. @var{env}.
  950. @end deffn
  951. Here is a simple example, illustrating that it is the variable
  952. that gets captured, not just its value at one point in time.
  953. @example
  954. (define e (let ((x 100)) (the-environment)))
  955. (define fetch-x (local-eval '(lambda () x) e))
  956. (fetch-x)
  957. @result{} 100
  958. (local-eval '(set! x 42) e)
  959. (fetch-x)
  960. @result{} 42
  961. @end example
  962. While @var{exp} is evaluated within the lexical environment of
  963. @code{(the-environment)}, it has the dynamic environment of the call to
  964. @code{local-eval}.
  965. @code{local-eval} and @code{local-compile} can only evaluate
  966. expressions, not definitions.
  967. @example
  968. (local-eval '(define foo 42)
  969. (let ((x 100)) (the-environment)))
  970. @result{} syntax error: definition in expression context
  971. @end example
  972. Note that the current implementation of @code{(the-environment)} only
  973. captures ``normal'' lexical bindings, and pattern variables bound by
  974. @code{syntax-case}. It does not currently capture local syntax
  975. transformers bound by @code{let-syntax}, @code{letrec-syntax} or
  976. non-top-level @code{define-syntax} forms. Any attempt to reference such
  977. captured syntactic keywords via @code{local-eval} or
  978. @code{local-compile} produces an error.
  979. @node Local Inclusion
  980. @subsection Local Inclusion
  981. This section has discussed various means of linking Scheme code
  982. together: fundamentally, loading up files at run-time using @code{load}
  983. and @code{load-compiled}. Guile provides another option to compose
  984. parts of programs together at expansion-time instead of at run-time.
  985. @deffn {Scheme Syntax} include file-name
  986. Open @var{file-name}, at expansion-time, and read the Scheme forms that
  987. it contains, splicing them into the location of the @code{include},
  988. within a @code{begin}.
  989. If @var{file-name} is a relative path, it is searched for relative to
  990. the path that contains the file that the @code{include} form appears in.
  991. @end deffn
  992. If you are a C programmer, if @code{load} in Scheme is like
  993. @code{dlopen} in C, consider @code{include} to be like the C
  994. preprocessor's @code{#include}. When you use @code{include}, it is as
  995. if the contents of the included file were typed in instead of the
  996. @code{include} form.
  997. Because the code is included at compile-time, it is available to the
  998. macroexpander. Syntax definitions in the included file are available to
  999. later code in the form in which the @code{include} appears, without the
  1000. need for @code{eval-when}. (@xref{Eval When}.)
  1001. For the same reason, compiling a form that uses @code{include} results
  1002. in one compilation unit, composed of multiple files. Loading the
  1003. compiled file is one @code{stat} operation for the compilation unit,
  1004. instead of @code{2*@var{n}} in the case of @code{load} (once for each
  1005. loaded source file, and once each corresponding compiled file, in the
  1006. best case).
  1007. Unlike @code{load}, @code{include} also works within nested lexical
  1008. contexts. It so happens that the optimizer works best within a lexical
  1009. context, because all of the uses of bindings in a lexical context are
  1010. visible, so composing files by including them within a @code{(let ()
  1011. ...)} can sometimes lead to important speed improvements.
  1012. On the other hand, @code{include} does have all the disadvantages of
  1013. early binding: once the code with the @code{include} is compiled, no
  1014. change to the included file is reflected in the future behavior of the
  1015. including form.
  1016. Also, the particular form of @code{include}, which requires an absolute
  1017. path, or a path relative to the current directory at compile-time, is
  1018. not very amenable to compiling the source in one place, but then
  1019. installing the source to another place. For this reason, Guile provides
  1020. another form, @code{include-from-path}, which looks for the source file
  1021. to include within a load path.
  1022. @deffn {Scheme Syntax} include-from-path file-name
  1023. Like @code{include}, but instead of expecting @code{file-name} to be an
  1024. absolute file name, it is expected to be a relative path to search in
  1025. the @code{%load-path}.
  1026. @end deffn
  1027. @code{include-from-path} is more useful when you want to install all of
  1028. the source files for a package (as you should!). It makes it possible
  1029. to evaluate an installed file from source, instead of relying on the
  1030. @code{.go} file being up to date.
  1031. @node Sandboxed Evaluation
  1032. @subsection Sandboxed Evaluation
  1033. Sometimes you would like to evaluate code that comes from an untrusted
  1034. party. The safest way to do this is to buy a new computer, evaluate the
  1035. code on that computer, then throw the machine away. However if you are
  1036. unwilling to take this simple approach, Guile does include a limited
  1037. ``sandbox'' facility that can allow untrusted code to be evaluated with
  1038. some confidence.
  1039. To use the sandboxed evaluator, load its module:
  1040. @example
  1041. (use-modules (ice-9 sandbox))
  1042. @end example
  1043. Guile's sandboxing facility starts with the ability to restrict the time
  1044. and space used by a piece of code.
  1045. @deffn {Scheme Procedure} call-with-time-limit limit thunk limit-reached
  1046. Call @var{thunk}, but cancel it if @var{limit} seconds of wall-clock
  1047. time have elapsed. If the computation is cancelled, call
  1048. @var{limit-reached} in tail position. @var{thunk} must not disable
  1049. interrupts or prevent an abort via a @code{dynamic-wind} unwind handler.
  1050. @end deffn
  1051. @deffn {Scheme Procedure} call-with-allocation-limit limit thunk limit-reached
  1052. Call @var{thunk}, but cancel it if @var{limit} bytes have been
  1053. allocated. If the computation is cancelled, call @var{limit-reached} in
  1054. tail position. @var{thunk} must not disable interrupts or prevent an
  1055. abort via a @code{dynamic-wind} unwind handler.
  1056. This limit applies to both stack and heap allocation. The computation
  1057. will not be aborted before @var{limit} bytes have been allocated, but
  1058. for the heap allocation limit, the check may be postponed until the next garbage collection.
  1059. Note that as a current shortcoming, the heap size limit applies to all
  1060. threads; concurrent allocation by other unrelated threads counts towards
  1061. the allocation limit.
  1062. @end deffn
  1063. @deffn {Scheme Procedure} call-with-time-and-allocation-limits time-limit allocation-limit thunk
  1064. Invoke @var{thunk} in a dynamic extent in which its execution is limited
  1065. to @var{time-limit} seconds of wall-clock time, and its allocation to
  1066. @var{allocation-limit} bytes. @var{thunk} must not disable interrupts
  1067. or prevent an abort via a @code{dynamic-wind} unwind handler.
  1068. If successful, return all values produced by invoking @var{thunk}. Any
  1069. uncaught exception thrown by the thunk will propagate out. If the time
  1070. or allocation limit is exceeded, an exception will be thrown to the
  1071. @code{limit-exceeded} key.
  1072. @end deffn
  1073. The time limit and stack limit are both very precise, but the heap limit
  1074. only gets checked asynchronously, after a garbage collection. In
  1075. particular, if the heap is already very large, the number of allocated
  1076. bytes between garbage collections will be large, and therefore the
  1077. precision of the check is reduced.
  1078. Additionally, due to the mechanism used by the allocation limit (the
  1079. @code{after-gc-hook}), large single allocations like @code{(make-vector
  1080. #e1e7)} are only detected after the allocation completes, even if the
  1081. allocation itself causes garbage collection. It's possible therefore
  1082. for user code to not only exceed the allocation limit set, but also to
  1083. exhaust all available memory, causing out-of-memory conditions at any
  1084. allocation site. Failure to allocate memory in Guile itself should be
  1085. safe and cause an exception to be thrown, but most systems are not
  1086. designed to handle @code{malloc} failures. An allocation failure may
  1087. therefore exercise unexpected code paths in your system, so it is a
  1088. weakness of the sandbox (and therefore an interesting point of attack).
  1089. The main sandbox interface is @code{eval-in-sandbox}.
  1090. @deffn {Scheme Procedure} eval-in-sandbox exp [#:time-limit 0.1] @
  1091. [#:allocation-limit #e10e6] @
  1092. [#:bindings all-pure-bindings] @
  1093. [#:module (make-sandbox-module bindings)] @
  1094. [#:sever-module? #t]
  1095. Evaluate the Scheme expression @var{exp} within an isolated
  1096. "sandbox". Limit its execution to @var{time-limit} seconds of
  1097. wall-clock time, and limit its allocation to @var{allocation-limit}
  1098. bytes.
  1099. The evaluation will occur in @var{module}, which defaults to the result
  1100. of calling @code{make-sandbox-module} on @var{bindings}, which itself
  1101. defaults to @code{all-pure-bindings}. This is the core of the
  1102. sandbox: creating a scope for the expression that is @dfn{safe}.
  1103. A safe sandbox module has two characteristics. Firstly, it will not
  1104. allow the expression being evaluated to avoid being cancelled due to
  1105. time or allocation limits. This ensures that the expression terminates
  1106. in a timely fashion.
  1107. Secondly, a safe sandbox module will prevent the evaluation from
  1108. receiving information from previous evaluations, or from affecting
  1109. future evaluations. All combinations of binding sets exported by
  1110. @code{(ice-9 sandbox)} form safe sandbox modules.
  1111. The @var{bindings} should be given as a list of import sets. One import
  1112. set is a list whose car names an interface, like @code{(ice-9 q)}, and
  1113. whose cdr is a list of imports. An import is either a bare symbol or a
  1114. pair of @code{(@var{out} . @var{in})}, where @var{out} and @var{in} are
  1115. both symbols and denote the name under which a binding is exported from
  1116. the module, and the name under which to make the binding available,
  1117. respectively. Note that @var{bindings} is only used as an input to the
  1118. default initializer for the @var{module} argument; if you pass
  1119. @code{#:module}, @var{bindings} is unused. If @var{sever-module?} is
  1120. true (the default), the module will be unlinked from the global module
  1121. tree after the evaluation returns, to allow @var{mod} to be
  1122. garbage-collected.
  1123. If successful, return all values produced by @var{exp}. Any uncaught
  1124. exception thrown by the expression will propagate out. If the time or
  1125. allocation limit is exceeded, an exception will be thrown to the
  1126. @code{limit-exceeded} key.
  1127. @end deffn
  1128. Constructing a safe sandbox module is tricky in general. Guile defines
  1129. an easy way to construct safe modules from predefined sets of bindings.
  1130. Before getting to that interface, here are some general notes on safety.
  1131. @enumerate
  1132. @item The time and allocation limits rely on the ability to interrupt
  1133. and cancel a computation. For this reason, no binding included in a
  1134. sandbox module should be able to indefinitely postpone interrupt
  1135. handling, nor should a binding be able to prevent an abort. In practice
  1136. this second consideration means that @code{dynamic-wind} should not be
  1137. included in any binding set.
  1138. @item The time and allocation limits apply only to the
  1139. @code{eval-in-sandbox} call. If the call returns a procedure which is
  1140. later called, no limit is ``automatically'' in place. Users of
  1141. @code{eval-in-sandbox} have to be very careful to reimpose limits when
  1142. calling procedures that escape from sandboxes.
  1143. @item Similarly, the dynamic environment of the @code{eval-in-sandbox}
  1144. call is not necessarily in place when any procedure that escapes from
  1145. the sandbox is later called.
  1146. This detail prevents us from exposing @code{primitive-eval} to the
  1147. sandbox, for two reasons. The first is that it's possible for legacy
  1148. code to forge references to any binding, if the
  1149. @code{allow-legacy-syntax-objects?} parameter is true. The default for
  1150. this parameter is true; @pxref{Syntax Transformer Helpers} for the
  1151. details. The parameter is bound to @code{#f} for the duration of the
  1152. @code{eval-in-sandbox} call itself, but that will not be in place during
  1153. calls to escaped procedures.
  1154. The second reason we don't expose @code{primitive-eval} is that
  1155. @code{primitive-eval} implicitly works in the current module, which for
  1156. an escaped procedure will probably be different than the module that is
  1157. current for the @code{eval-in-sandbox} call itself.
  1158. The common denominator here is that if an interface exposed to the
  1159. sandbox relies on dynamic environments, it is easy to mistakenly grant
  1160. the sandboxed procedure additional capabilities in the form of bindings
  1161. that it should not have access to. For this reason, the default sets of
  1162. predefined bindings do not depend on any dynamically scoped value.
  1163. @item Mutation may allow a sandboxed evaluation to break some invariant
  1164. in users of data supplied to it. A lot of code culturally doesn't
  1165. expect mutation, but if you hand mutable data to a sandboxed evaluation
  1166. and you also grant mutating capabilities to that evaluation, then the
  1167. sandboxed code may indeed mutate that data. The default set of bindings
  1168. to the sandbox do not include any mutating primitives.
  1169. Relatedly, @code{set!} may allow a sandbox to mutate a primitive,
  1170. invalidating many system-wide invariants. Guile is currently quite
  1171. permissive when it comes to imported bindings and mutability. Although
  1172. @code{set!} to a module-local or lexically bound variable would be fine,
  1173. we don't currently have an easy way to disallow @code{set!} to an
  1174. imported binding, so currently no binding set includes @code{set!}.
  1175. @item Mutation may allow a sandboxed evaluation to keep state, or
  1176. make a communication mechanism with other code. On the one hand this
  1177. sounds cool, but on the other hand maybe this is part of your threat
  1178. model. Again, the default set of bindings doesn't include mutating
  1179. primitives, preventing sandboxed evaluations from keeping state.
  1180. @item The sandbox should probably not be able to open a network
  1181. connection, or write to a file, or open a file from disk. The default
  1182. binding set includes no interaction with the operating system.
  1183. @end enumerate
  1184. If you, dear reader, find the above discussion interesting, you will
  1185. enjoy Jonathan Rees' dissertation, ``A Security Kernel Based on the
  1186. Lambda Calculus''.
  1187. @defvr {Scheme Variable} all-pure-bindings
  1188. All ``pure'' bindings that together form a safe subset of those bindings
  1189. available by default to Guile user code.
  1190. @end defvr
  1191. @defvr {Scheme Variable} all-pure-and-impure-bindings
  1192. Like @code{all-pure-bindings}, but additionally including mutating
  1193. primitives like @code{vector-set!}. This set is still safe in the sense
  1194. mentioned above, with the caveats about mutation.
  1195. @end defvr
  1196. The components of these composite sets are as follows:
  1197. @defvr {Scheme Variable} alist-bindings
  1198. @defvrx {Scheme Variable} array-bindings
  1199. @defvrx {Scheme Variable} bit-bindings
  1200. @defvrx {Scheme Variable} bitvector-bindings
  1201. @defvrx {Scheme Variable} char-bindings
  1202. @defvrx {Scheme Variable} char-set-bindings
  1203. @defvrx {Scheme Variable} clock-bindings
  1204. @defvrx {Scheme Variable} core-bindings
  1205. @defvrx {Scheme Variable} error-bindings
  1206. @defvrx {Scheme Variable} fluid-bindings
  1207. @defvrx {Scheme Variable} hash-bindings
  1208. @defvrx {Scheme Variable} iteration-bindings
  1209. @defvrx {Scheme Variable} keyword-bindings
  1210. @defvrx {Scheme Variable} list-bindings
  1211. @defvrx {Scheme Variable} macro-bindings
  1212. @defvrx {Scheme Variable} nil-bindings
  1213. @defvrx {Scheme Variable} number-bindings
  1214. @defvrx {Scheme Variable} pair-bindings
  1215. @defvrx {Scheme Variable} predicate-bindings
  1216. @defvrx {Scheme Variable} procedure-bindings
  1217. @defvrx {Scheme Variable} promise-bindings
  1218. @defvrx {Scheme Variable} prompt-bindings
  1219. @defvrx {Scheme Variable} regexp-bindings
  1220. @defvrx {Scheme Variable} sort-bindings
  1221. @defvrx {Scheme Variable} srfi-4-bindings
  1222. @defvrx {Scheme Variable} string-bindings
  1223. @defvrx {Scheme Variable} symbol-bindings
  1224. @defvrx {Scheme Variable} unspecified-bindings
  1225. @defvrx {Scheme Variable} variable-bindings
  1226. @defvrx {Scheme Variable} vector-bindings
  1227. @defvrx {Scheme Variable} version-bindings
  1228. The components of @code{all-pure-bindings}.
  1229. @end defvr
  1230. @defvr {Scheme Variable} mutating-alist-bindings
  1231. @defvrx {Scheme Variable} mutating-array-bindings
  1232. @defvrx {Scheme Variable} mutating-bitvector-bindings
  1233. @defvrx {Scheme Variable} mutating-fluid-bindings
  1234. @defvrx {Scheme Variable} mutating-hash-bindings
  1235. @defvrx {Scheme Variable} mutating-list-bindings
  1236. @defvrx {Scheme Variable} mutating-pair-bindings
  1237. @defvrx {Scheme Variable} mutating-sort-bindings
  1238. @defvrx {Scheme Variable} mutating-srfi-4-bindings
  1239. @defvrx {Scheme Variable} mutating-string-bindings
  1240. @defvrx {Scheme Variable} mutating-variable-bindings
  1241. @defvrx {Scheme Variable} mutating-vector-bindings
  1242. The additional components of @code{all-pure-and-impure-bindings}.
  1243. @end defvr
  1244. Finally, what do you do with a binding set? What is a binding set
  1245. anyway? @code{make-sandbox-module} is here for you.
  1246. @deffn {Scheme Procedure} make-sandbox-module bindings
  1247. Return a fresh module that only contains @var{bindings}.
  1248. The @var{bindings} should be given as a list of import sets. One import
  1249. set is a list whose car names an interface, like @code{(ice-9 q)}, and
  1250. whose cdr is a list of imports. An import is either a bare symbol or a
  1251. pair of @code{(@var{out} . @var{in})}, where @var{out} and @var{in} are
  1252. both symbols and denote the name under which a binding is exported from
  1253. the module, and the name under which to make the binding available,
  1254. respectively.
  1255. @end deffn
  1256. So you see that binding sets are just lists, and
  1257. @code{all-pure-and-impure-bindings} is really just the result of
  1258. appending all of the component binding sets.
  1259. @node REPL Servers
  1260. @subsection REPL Servers
  1261. @cindex REPL server
  1262. The procedures in this section are provided by
  1263. @lisp
  1264. (use-modules (system repl server))
  1265. @end lisp
  1266. When an application is written in Guile, it is often convenient to
  1267. allow the user to be able to interact with it by evaluating Scheme
  1268. expressions in a REPL.
  1269. The procedures of this module allow you to spawn a @dfn{REPL server},
  1270. which permits interaction over a local or TCP connection. Guile itself
  1271. uses them internally to implement the @option{--listen} switch,
  1272. @ref{Command-line Options}.
  1273. @deffn {Scheme Procedure} make-tcp-server-socket [#:host=#f] @
  1274. [#:addr] [#:port=37146]
  1275. Return a stream socket bound to a given address @var{addr} and port
  1276. number @var{port}. If the @var{host} is given, and @var{addr} is not,
  1277. then the @var{host} string is converted to an address. If neither is
  1278. given, we use the loopback address.
  1279. @end deffn
  1280. @deffn {Scheme Procedure} make-unix-domain-server-socket [#:path="/tmp/guile-socket"]
  1281. Return a UNIX domain socket, bound to a given @var{path}.
  1282. @end deffn
  1283. @deffn {Scheme Procedure} run-server [server-socket]
  1284. @deffnx {Scheme Procedure} spawn-server [server-socket]
  1285. Create and run a REPL, making it available over the given
  1286. @var{server-socket}. If @var{server-socket} is not provided, it
  1287. defaults to the socket created by calling @code{make-tcp-server-socket}
  1288. with no arguments.
  1289. @code{run-server} runs the server in the current thread, whereas
  1290. @code{spawn-server} runs the server in a new thread.
  1291. @end deffn
  1292. @deffn {Scheme Procedure} stop-server-and-clients!
  1293. Closes the connection on all running server sockets.
  1294. Please note that in the current implementation, the REPL threads are
  1295. cancelled without unwinding their stacks. If any of them are holding
  1296. mutexes or are within a critical section, the results are unspecified.
  1297. @end deffn
  1298. @node Cooperative REPL Servers
  1299. @subsection Cooperative REPL Servers
  1300. @cindex Cooperative REPL server
  1301. The procedures in this section are provided by
  1302. @lisp
  1303. (use-modules (system repl coop-server))
  1304. @end lisp
  1305. Whereas ordinary REPL servers run in their own threads (@pxref{REPL
  1306. Servers}), sometimes it is more convenient to provide REPLs that run at
  1307. specified times within an existing thread, for example in programs
  1308. utilizing an event loop or in single-threaded programs. This allows for
  1309. safe access and mutation of a program's data structures from the REPL,
  1310. without concern for thread synchronization.
  1311. Although the REPLs are run in the thread that calls
  1312. @code{spawn-coop-repl-server} and @code{poll-coop-repl-server},
  1313. dedicated threads are spawned so that the calling thread is not blocked.
  1314. The spawned threads read input for the REPLs and to listen for new
  1315. connections.
  1316. Cooperative REPL servers must be polled periodically to evaluate any
  1317. pending expressions by calling @code{poll-coop-repl-server} with the
  1318. object returned from @code{spawn-coop-repl-server}. The thread that
  1319. calls @code{poll-coop-repl-server} will be blocked for as long as the
  1320. expression takes to be evaluated or if the debugger is entered.
  1321. @deffn {Scheme Procedure} spawn-coop-repl-server [server-socket]
  1322. Create and return a new cooperative REPL server object, and spawn a new
  1323. thread to listen for connections on @var{server-socket}. Proper
  1324. functioning of the REPL server requires that
  1325. @code{poll-coop-repl-server} be called periodically on the returned
  1326. server object.
  1327. @end deffn
  1328. @deffn {Scheme Procedure} poll-coop-repl-server coop-server
  1329. Poll the cooperative REPL server @var{coop-server} and apply a pending
  1330. operation if there is one, such as evaluating an expression typed at the
  1331. REPL prompt. This procedure must be called from the same thread that
  1332. called @code{spawn-coop-repl-server}.
  1333. @end deffn
  1334. @c Local Variables:
  1335. @c TeX-master: "guile.texi"
  1336. @c End: