guile-invoke.texi 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. @c -*-texinfo-*-
  2. @c This is part of the GNU Guile Reference Manual.
  3. @c Copyright (C) 1996-1997,2000-2005,2010-2011,2013-2014,2016,2019
  4. @c Free Software Foundation, Inc.
  5. @c See the file guile.texi for copying conditions.
  6. @node Invoking Guile
  7. @section Invoking Guile
  8. @cindex invocation
  9. Many features of Guile depend on and can be changed by information that
  10. the user provides either before or when Guile is started. Below is a
  11. description of what information to provide and how to provide it.
  12. @menu
  13. * Command-line Options:: Command-line options understood by Guile.
  14. * Environment Variables:: Variables that affect Guile's behavior.
  15. @end menu
  16. @node Command-line Options
  17. @subsection Command-line Options
  18. @cindex Command-line Options
  19. @cindex command-line arguments
  20. @cindex arguments (command line)
  21. @cindex options (command line)
  22. @cindex switches (command line)
  23. @cindex startup (command-line arguments)
  24. @cindex invocation (command-line arguments)
  25. Here we describe Guile's command-line processing in detail. Guile
  26. processes its arguments from left to right, recognizing the switches
  27. described below. For examples, see @ref{Scripting Examples}.
  28. @table @code
  29. @item @var{script} @var{arg...}
  30. @itemx -s @var{script} @var{arg...}
  31. @cindex script mode
  32. By default, Guile will read a file named on the command line as a
  33. script. Any command-line arguments @var{arg...} following @var{script}
  34. become the script's arguments; the @code{command-line} function returns
  35. a list of strings of the form @code{(@var{script} @var{arg...})}.
  36. It is possible to name a file using a leading hyphen, for example,
  37. @file{-myfile.scm}. In this case, the file name must be preceded by
  38. @option{-s} to tell Guile that a (script) file is being named.
  39. Scripts are read and evaluated as Scheme source code just as the
  40. @code{load} function would. After loading @var{script}, Guile exits.
  41. @item -c @var{expr} @var{arg...}
  42. @cindex evaluate expression, command-line argument
  43. Evaluate @var{expr} as Scheme code, and then exit. Any command-line
  44. arguments @var{arg...} following @var{expr} become command-line
  45. arguments; the @code{command-line} function returns a list of strings of
  46. the form @code{(@var{guile} @var{arg...})}, where @var{guile} is the
  47. path of the Guile executable.
  48. @item -- @var{arg...}
  49. Run interactively, prompting the user for expressions and evaluating
  50. them. Any command-line arguments @var{arg...} following the @option{--}
  51. become command-line arguments for the interactive session; the
  52. @code{command-line} function returns a list of strings of the form
  53. @code{(@var{guile} @var{arg...})}, where @var{guile} is the path of the
  54. Guile executable.
  55. @item -L @var{directory}
  56. Add @var{directory} to the front of Guile's module load path. The given
  57. directories are searched in the order given on the command line and
  58. before any directories in the @env{GUILE_LOAD_PATH} environment
  59. variable. Paths added here are @emph{not} in effect during execution of
  60. the user's @file{.guile} file.
  61. @item -C @var{directory}
  62. Like @option{-L}, but adjusts the load path for @emph{compiled} files.
  63. @item -x @var{extension}
  64. Add @var{extension} to the front of Guile's load extension list
  65. (@pxref{Load Paths, @code{%load-extensions}}). The specified extensions
  66. are tried in the order given on the command line, and before the default
  67. load extensions. Extensions added here are @emph{not} in effect during
  68. execution of the user's @file{.guile} file.
  69. @item -l @var{file}
  70. Load Scheme source code from @var{file}, and continue processing the
  71. command line.
  72. @item -e @var{function}
  73. Make @var{function} the @dfn{entry point} of the script. After loading
  74. the script file (with @option{-s}) or evaluating the expression (with
  75. @option{-c}), apply @var{function} to a list containing the program name
  76. and the command-line arguments---the list provided by the
  77. @code{command-line} function.
  78. A @option{-e} switch can appear anywhere in the argument list, but Guile
  79. always invokes the @var{function} as the @emph{last} action it performs.
  80. This is weird, but because of the way script invocation works under
  81. POSIX, the @option{-s} option must always come last in the list.
  82. The @var{function} is most often a simple symbol that names a function
  83. that is defined in the script. It can also be of the form @code{(@@
  84. @var{module-name} @var{symbol})}, and in that case, the symbol is
  85. looked up in the module named @var{module-name}.
  86. As a shorthand you can use the form @code{(symbol ...)}, that is, a list
  87. of only symbols that doesn't start with @code{@@}. It is equivalent to
  88. @code{(@@ @var{module-name} main)}, where @var{module-name} is
  89. @code{(symbol ...)} form. @xref{Using Guile Modules} and @ref{Scripting
  90. Examples}.
  91. @item -ds
  92. Treat a final @option{-s} option as if it occurred at this point in the
  93. command line; load the script here.
  94. This switch is necessary because, although the POSIX script invocation
  95. mechanism effectively requires the @option{-s} option to appear last, the
  96. programmer may well want to run the script before other actions
  97. requested on the command line. For examples, see @ref{Scripting
  98. Examples}.
  99. @item \
  100. Read more command-line arguments, starting from the second line of the
  101. script file. @xref{The Meta Switch}.
  102. @item --use-srfi=@var{list}
  103. @cindex loading srfi modules (command line)
  104. The option @option{--use-srfi} expects a comma-separated list of numbers,
  105. each representing a SRFI module to be loaded into the interpreter
  106. before evaluating a script file or starting the REPL. Additionally,
  107. the feature identifier for the loaded SRFIs is recognized by
  108. the procedure @code{cond-expand} when this option is used.
  109. Here is an example that loads the modules SRFI-8 ('receive') and SRFI-13
  110. ('string library') before the GUILE interpreter is started:
  111. @example
  112. guile --use-srfi=8,13
  113. @end example
  114. @item --r6rs
  115. @cindex r6rs (command line)
  116. Adapt Guile's initial environment to better support R6RS. @xref{R6RS
  117. Incompatibilities}, for some caveats.
  118. @item --debug
  119. @cindex debugging virtual machine (command line)
  120. Start with the debugging virtual machine (VM) engine. Using the
  121. debugging VM will enable support for VM hooks, which are needed for
  122. tracing, breakpoints, and accurate call counts when profiling. The
  123. debugging VM is slower than the regular VM, though, by about ten
  124. percent. @xref{VM Hooks}, for more information.
  125. By default, the debugging VM engine is only used when entering an
  126. interactive session. When executing a script with @option{-s} or
  127. @option{-c}, the normal, faster VM is used by default.
  128. @vnew{1.8}
  129. @item --no-debug
  130. @cindex debugging virtual machine (command line)
  131. Do not use the debugging VM engine, even when entering an interactive
  132. session.
  133. Note that, despite the name, Guile running with @option{--no-debug}
  134. @emph{does} support the usual debugging facilities, such as printing a
  135. detailed backtrace upon error. The only difference with
  136. @option{--debug} is lack of support for VM hooks and the facilities that
  137. build upon it (see above).
  138. @item -q
  139. @cindex init file, not loading
  140. @cindex @file{.guile} file, not loading
  141. Do not load the initialization file, @file{.guile}. This option only
  142. has an effect when running interactively; running scripts does not load
  143. the @file{.guile} file. @xref{Init File}.
  144. @item --listen[=@var{p}]
  145. While this program runs, listen on a local port or a path for REPL
  146. clients. If @var{p} starts with a number, it is assumed to be a local
  147. port on which to listen. If it starts with a forward slash, it is
  148. assumed to be the file name of a UNIX domain socket on which to listen.
  149. If @var{p} is not given, the default is local port 37146. If you look
  150. at it upside down, it almost spells ``Guile''. If you have netcat
  151. installed, you should be able to @kbd{nc localhost 37146} and get a
  152. Guile prompt. Alternately you can fire up Emacs and connect to the
  153. process; see @ref{Using Guile in Emacs} for more details.
  154. @quotation Note
  155. Opening a port allows anyone who can connect to that port to do anything
  156. Guile can do, as the user
  157. that the Guile process is running as. Do not use @option{--listen} on
  158. multi-user machines. Of course, if you do not pass @option{--listen} to
  159. Guile, no port will be opened.
  160. Guile protects against the
  161. @uref{https://en.wikipedia.org/wiki/Inter-protocol_exploitation,
  162. @dfn{HTTP inter-protocol exploitation attack}}, a scenario whereby an
  163. attacker can, @i{via} an HTML page, cause a web browser to send data to
  164. TCP servers listening on a loopback interface or private network.
  165. Nevertheless, you are advised to use UNIX domain sockets, as in
  166. @code{--listen=/some/local/file}, whenever possible.
  167. @end quotation
  168. That said, @option{--listen} is great for interactive debugging and
  169. development.
  170. @vnew{2.0}
  171. @item --auto-compile
  172. Compile source files automatically (default behavior).
  173. @vnew{2.0.1}
  174. @item --fresh-auto-compile
  175. Treat the auto-compilation cache as invalid, forcing recompilation.
  176. @vnew{2.0}
  177. @item --no-auto-compile
  178. Disable automatic source file compilation.
  179. @vnew{2.0.8}
  180. @item --language=@var{lang}
  181. For the remainder of the command line arguments, assume that files
  182. mentioned with @code{-l} and expressions passed with @code{-c} are
  183. written in @var{lang}. @var{lang} must be the name of one of the
  184. languages supported by the compiler (@pxref{Compiler Tower}). When run
  185. interactively, set the REPL's language to @var{lang} (@pxref{Using Guile
  186. Interactively}).
  187. The default language is @code{scheme}; other interesting values include
  188. @code{elisp} (for Emacs Lisp), and @code{ecmascript}.
  189. The example below shows the evaluation of expressions in Scheme, Emacs
  190. Lisp, and ECMAScript:
  191. @example
  192. guile -c "(apply + '(1 2))"
  193. guile --language=elisp -c "(= (funcall (symbol-function '+) 1 2) 3)"
  194. guile --language=ecmascript -c '(function (x) @{ return x * x; @})(2);'
  195. @end example
  196. To load a file written in Scheme and one written in Emacs Lisp, and then
  197. start a Scheme REPL, type:
  198. @example
  199. guile -l foo.scm --language=elisp -l foo.el --language=scheme
  200. @end example
  201. @vnew{2.0}
  202. @item -h@r{, }--help
  203. Display help on invoking Guile, and then exit.
  204. @item -v@r{, }--version
  205. Display the current version of Guile, and then exit.
  206. @end table
  207. @node Environment Variables
  208. @subsection Environment Variables
  209. @cindex environment variables
  210. @cindex shell
  211. @cindex initialization
  212. The @dfn{environment} is a feature of the operating system; it consists
  213. of a collection of variables with names and values. Each variable is
  214. called an @dfn{environment variable} (or, sometimes, a ``shell
  215. variable''); environment variable names are case-sensitive, and it is
  216. conventional to use upper-case letters only. The values are all text
  217. strings, even those that are written as numerals. (Note that here we
  218. are referring to names and values that are defined in the operating
  219. system shell from which Guile is invoked. This is not the same as a
  220. Scheme environment that is defined within a running instance of Guile.
  221. For a description of Scheme environments, @pxref{About Environments}.)
  222. How to set environment variables before starting Guile depends on the
  223. operating system and, especially, the shell that you are using. For
  224. example, here is how to tell Guile to provide detailed warning messages
  225. about deprecated features by setting @env{GUILE_WARN_DEPRECATED} using
  226. Bash:
  227. @example
  228. $ export GUILE_WARN_DEPRECATED="detailed"
  229. $ guile
  230. @end example
  231. @noindent
  232. Or, detailed warnings can be turned on for a single invocation using:
  233. @example
  234. $ env GUILE_WARN_DEPRECATED="detailed" guile
  235. @end example
  236. If you wish to retrieve or change the value of the shell environment
  237. variables that affect the run-time behavior of Guile from within a
  238. running instance of Guile, see @ref{Runtime Environment}.
  239. Here are the environment variables that affect the run-time behavior of
  240. Guile:
  241. @table @env
  242. @item GUILE_AUTO_COMPILE
  243. @vindex GUILE_AUTO_COMPILE
  244. This is a flag that can be used to tell Guile whether or not to compile
  245. Scheme source files automatically. Starting with Guile 2.0, Scheme
  246. source files will be compiled automatically, by default.
  247. If a compiled (@file{.go}) file corresponding to a @file{.scm} file is
  248. not found or is not newer than the @file{.scm} file, the @file{.scm}
  249. file will be compiled on the fly, and the resulting @file{.go} file
  250. stored away. An advisory note will be printed on the console.
  251. Compiled files will be stored in the directory
  252. @file{$XDG_CACHE_HOME/@/guile/@/ccache}, where @env{XDG_CACHE_HOME}
  253. defaults to the directory @file{$HOME/.cache}. This directory will be
  254. created if it does not already exist.
  255. Note that this mechanism depends on the timestamp of the @file{.go} file
  256. being newer than that of the @file{.scm} file; if the @file{.scm} or
  257. @file{.go} files are moved after installation, care should be taken to
  258. preserve their original timestamps.
  259. Set @env{GUILE_AUTO_COMPILE} to zero (0), to prevent Scheme files from
  260. being compiled automatically. Set this variable to ``fresh'' to tell
  261. Guile to compile Scheme files whether they are newer than the compiled
  262. files or not.
  263. @xref{Compilation}.
  264. @item GUILE_HISTORY
  265. @vindex GUILE_HISTORY
  266. This variable names the file that holds the Guile REPL command history.
  267. You can specify a different history file by setting this environment
  268. variable. By default, the history file is @file{$HOME/.guile_history}.
  269. @item GUILE_INSTALL_LOCALE
  270. @vindex GUILE_INSTALL_LOCALE
  271. This is a flag that can be used to tell Guile whether or not to install
  272. the current locale at startup, via a call to @code{(setlocale LC_ALL
  273. "")}@footnote{The @code{GUILE_INSTALL_LOCALE} environment variable was
  274. ignored in Guile versions prior to 2.0.9.}. @xref{Locales}, for more
  275. information on locales.
  276. You may explicitly indicate that you do not want to install
  277. the locale by setting @env{GUILE_INSTALL_LOCALE} to @code{0}, or
  278. explicitly enable it by setting the variable to @code{1}.
  279. Usually, installing the current locale is the right thing to do. It
  280. allows Guile to correctly parse and print strings with non-ASCII
  281. characters. Therefore, this option is on by default.
  282. @item GUILE_STACK_SIZE
  283. @vindex GUILE_STACK_SIZE
  284. Guile currently has a limited stack size for Scheme computations.
  285. Attempting to call too many nested functions will signal an error. This
  286. is good to detect infinite recursion, but sometimes the limit is reached
  287. for normal computations. This environment variable, if set to a
  288. positive integer, specifies the number of Scheme value slots to allocate
  289. for the stack.
  290. In the future we will implement stacks that can grow and shrink, but for
  291. now this hack will have to do.
  292. @item GUILE_LOAD_COMPILED_PATH
  293. @vindex GUILE_LOAD_COMPILED_PATH
  294. This variable may be used to augment the path that is searched for
  295. compiled Scheme files (@file{.go} files) when loading. Its value should
  296. be a colon-separated list of directories. If it contains the special
  297. path component @code{...} (ellipsis), then the default path is put in
  298. place of the ellipsis, otherwise the default path is placed at the end.
  299. The result is stored in @code{%load-compiled-path} (@pxref{Load Paths}).
  300. Here is an example using the Bash shell that adds the current directory,
  301. @file{.}, and the relative directory @file{../my-library} to
  302. @code{%load-compiled-path}:
  303. @example
  304. $ export GUILE_LOAD_COMPILED_PATH=".:../my-library"
  305. $ guile -c '(display %load-compiled-path) (newline)'
  306. (. ../my-library /usr/local/lib/guile/3.0/ccache)
  307. @end example
  308. @item GUILE_LOAD_PATH
  309. @vindex GUILE_LOAD_PATH
  310. This variable may be used to augment the path that is searched for
  311. Scheme files when loading. Its value should be a colon-separated list
  312. of directories. If it contains the special path component @code{...}
  313. (ellipsis), then the default path is put in place of the ellipsis,
  314. otherwise the default path is placed at the end. The result is stored
  315. in @code{%load-path} (@pxref{Load Paths}).
  316. Here is an example using the Bash shell that prepends the current
  317. directory to @code{%load-path}, and adds the relative directory
  318. @file{../srfi} to the end:
  319. @example
  320. $ env GUILE_LOAD_PATH=".:...:../srfi" \
  321. guile -c '(display %load-path) (newline)'
  322. (. /usr/local/share/guile/3.0 \
  323. /usr/local/share/guile/site/3.0 \
  324. /usr/local/share/guile/site \
  325. /usr/local/share/guile \
  326. ../srfi)
  327. @end example
  328. (Note: The line breaks, above, are for documentation purposes only, and
  329. not required in the actual example.)
  330. @item GUILE_WARN_DEPRECATED
  331. @vindex GUILE_WARN_DEPRECATED
  332. As Guile evolves, some features will be eliminated or replaced by newer
  333. features. To help users migrate their code as this evolution occurs,
  334. Guile will issue warning messages about code that uses features that
  335. have been marked for eventual elimination. @env{GUILE_WARN_DEPRECATED}
  336. can be set to ``no'' to tell Guile not to display these warning
  337. messages, or set to ``detailed'' to tell Guile to display more lengthy
  338. messages describing the warning. @xref{Deprecation}.
  339. @item HOME
  340. @vindex HOME
  341. Guile uses the environment variable @env{HOME}, the name of your home
  342. directory, to locate various files, such as @file{.guile} or
  343. @file{.guile_history}.
  344. @end table
  345. @c Local Variables:
  346. @c mode: texinfo
  347. @c TeX-master: "guile"
  348. @c End: