guile-invoke.texi 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  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,2021-2022
  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 --r7rs
  119. @cindex r7rs (command line)
  120. Adapt Guile's initial environment to better support R7RS. @xref{R7RS
  121. Incompatibilities}, for some caveats.
  122. @item --debug
  123. @cindex debugging virtual machine (command line)
  124. Start with the debugging virtual machine (VM) engine. Using the
  125. debugging VM will enable support for VM hooks, which are needed for
  126. tracing, breakpoints, and accurate call counts when profiling. The
  127. debugging VM is slower than the regular VM, though, by about ten
  128. percent. @xref{VM Hooks}, for more information.
  129. By default, the debugging VM engine is only used when entering an
  130. interactive session. When executing a script with @option{-s} or
  131. @option{-c}, the normal, faster VM is used by default.
  132. @vnew{1.8}
  133. @item --no-debug
  134. @cindex debugging virtual machine (command line)
  135. Do not use the debugging VM engine, even when entering an interactive
  136. session.
  137. Note that, despite the name, Guile running with @option{--no-debug}
  138. @emph{does} support the usual debugging facilities, such as printing a
  139. detailed backtrace upon error. The only difference with
  140. @option{--debug} is lack of support for VM hooks and the facilities that
  141. build upon it (see above).
  142. @item -q
  143. @cindex init file, not loading
  144. @cindex @file{.guile} file, not loading
  145. Do not load the initialization file, @file{.guile}. This option only
  146. has an effect when running interactively; running scripts does not load
  147. the @file{.guile} file. @xref{Init File}.
  148. @item --listen[=@var{p}]
  149. While this program runs, listen on a local port or a path for REPL
  150. clients. If @var{p} starts with a number, it is assumed to be a local
  151. port on which to listen. If it starts with a forward slash, it is
  152. assumed to be the file name of a UNIX domain socket on which to listen.
  153. If @var{p} is not given, the default is local port 37146. If you look
  154. at it upside down, it almost spells ``Guile''. If you have netcat
  155. installed, you should be able to @kbd{nc localhost 37146} and get a
  156. Guile prompt. Alternately you can fire up Emacs and connect to the
  157. process; see @ref{Using Guile in Emacs} for more details.
  158. @quotation Note
  159. Opening a port allows anyone who can connect to that port to do anything
  160. Guile can do, as the user
  161. that the Guile process is running as. Do not use @option{--listen} on
  162. multi-user machines. Of course, if you do not pass @option{--listen} to
  163. Guile, no port will be opened.
  164. Guile protects against the
  165. @uref{https://en.wikipedia.org/wiki/Inter-protocol_exploitation,
  166. @dfn{HTTP inter-protocol exploitation attack}}, a scenario whereby an
  167. attacker can, @i{via} an HTML page, cause a web browser to send data to
  168. TCP servers listening on a loopback interface or private network.
  169. Nevertheless, you are advised to use UNIX domain sockets, as in
  170. @code{--listen=/some/local/file}, whenever possible.
  171. @end quotation
  172. That said, @option{--listen} is great for interactive debugging and
  173. development.
  174. @vnew{2.0}
  175. @item --auto-compile
  176. Compile source files automatically (default behavior).
  177. @vnew{2.0.1}
  178. @item --fresh-auto-compile
  179. Treat the auto-compilation cache as invalid, forcing recompilation.
  180. @vnew{2.0}
  181. @item --no-auto-compile
  182. Disable automatic source file compilation.
  183. @vnew{2.0.8}
  184. @item --language=@var{lang}
  185. For the remainder of the command line arguments, assume that files
  186. mentioned with @code{-l} and expressions passed with @code{-c} are
  187. written in @var{lang}. @var{lang} must be the name of one of the
  188. languages supported by the compiler (@pxref{Compiler Tower}). When run
  189. interactively, set the REPL's language to @var{lang} (@pxref{Using Guile
  190. Interactively}).
  191. The default language is @code{scheme}; other interesting values include
  192. @code{elisp} (for Emacs Lisp), and @code{ecmascript}.
  193. The example below shows the evaluation of expressions in Scheme, Emacs
  194. Lisp, and ECMAScript:
  195. @example
  196. guile -c "(apply + '(1 2))"
  197. guile --language=elisp -c "(= (funcall (symbol-function '+) 1 2) 3)"
  198. guile --language=ecmascript -c '(function (x) @{ return x * x; @})(2);'
  199. @end example
  200. To load a file written in Scheme and one written in Emacs Lisp, and then
  201. start a Scheme REPL, type:
  202. @example
  203. guile -l foo.scm --language=elisp -l foo.el --language=scheme
  204. @end example
  205. @vnew{2.0}
  206. @item -h@r{, }--help
  207. Display help on invoking Guile, and then exit.
  208. @item -v@r{, }--version
  209. Display the current version of Guile, and then exit.
  210. @end table
  211. @node Environment Variables
  212. @subsection Environment Variables
  213. @cindex environment variables
  214. @cindex shell
  215. @cindex initialization
  216. The @dfn{environment} is a feature of the operating system; it consists
  217. of a collection of variables with names and values. Each variable is
  218. called an @dfn{environment variable} (or, sometimes, a ``shell
  219. variable''); environment variable names are case-sensitive, and it is
  220. conventional to use upper-case letters only. The values are all text
  221. strings, even those that are written as numerals. (Note that here we
  222. are referring to names and values that are defined in the operating
  223. system shell from which Guile is invoked. This is not the same as a
  224. Scheme environment that is defined within a running instance of Guile.
  225. For a description of Scheme environments, @pxref{About Environments}.)
  226. How to set environment variables before starting Guile depends on the
  227. operating system and, especially, the shell that you are using. For
  228. example, here is how to tell Guile to provide detailed warning messages
  229. about deprecated features by setting @env{GUILE_WARN_DEPRECATED} using
  230. Bash:
  231. @example
  232. $ export GUILE_WARN_DEPRECATED="detailed"
  233. $ guile
  234. @end example
  235. @noindent
  236. Or, detailed warnings can be turned on for a single invocation using:
  237. @example
  238. $ env GUILE_WARN_DEPRECATED="detailed" guile
  239. @end example
  240. If you wish to retrieve or change the value of the shell environment
  241. variables that affect the run-time behavior of Guile from within a
  242. running instance of Guile, see @ref{Runtime Environment}.
  243. Here are the environment variables that affect the run-time behavior of
  244. Guile:
  245. @table @env
  246. @item GUILE_AUTO_COMPILE
  247. @vindex GUILE_AUTO_COMPILE
  248. This is a flag that can be used to tell Guile whether or not to compile
  249. Scheme source files automatically. Starting with Guile 2.0, Scheme
  250. source files will be compiled automatically, by default.
  251. If a compiled (@file{.go}) file corresponding to a @file{.scm} file is
  252. not found or is not newer than the @file{.scm} file, the @file{.scm}
  253. file will be compiled on the fly, and the resulting @file{.go} file
  254. stored away. An advisory note will be printed on the console.
  255. Compiled files will be stored in the directory
  256. @file{$XDG_CACHE_HOME/@/guile/@/ccache}, where @env{XDG_CACHE_HOME}
  257. defaults to the directory @file{$HOME/.cache}. This directory will be
  258. created if it does not already exist.
  259. Note that this mechanism depends on the timestamp of the @file{.go} file
  260. being newer than that of the @file{.scm} file; if the @file{.scm} or
  261. @file{.go} files are moved after installation, care should be taken to
  262. preserve their original timestamps.
  263. Set @env{GUILE_AUTO_COMPILE} to zero (0), to prevent Scheme files from
  264. being compiled automatically. Set this variable to ``fresh'' to tell
  265. Guile to compile Scheme files whether they are newer than the compiled
  266. files or not.
  267. @xref{Compilation}.
  268. @item GUILE_HISTORY
  269. @vindex GUILE_HISTORY
  270. This variable names the file that holds the Guile REPL command history.
  271. You can specify a different history file by setting this environment
  272. variable. By default, the history file is @file{$HOME/.guile_history}.
  273. @item GUILE_INSTALL_LOCALE
  274. @vindex GUILE_INSTALL_LOCALE
  275. This is a flag that can be used to tell Guile whether or not to install
  276. the current locale at startup, via a call to @code{(setlocale LC_ALL
  277. "")}@footnote{The @code{GUILE_INSTALL_LOCALE} environment variable was
  278. ignored in Guile versions prior to 2.0.9.}. @xref{Locales}, for more
  279. information on locales.
  280. You may explicitly indicate that you do not want to install
  281. the locale by setting @env{GUILE_INSTALL_LOCALE} to @code{0}, or
  282. explicitly enable it by setting the variable to @code{1}.
  283. Usually, installing the current locale is the right thing to do. It
  284. allows Guile to correctly parse and print strings with non-ASCII
  285. characters. Therefore, this option is on by default.
  286. @item GUILE_LOAD_COMPILED_PATH
  287. @vindex GUILE_LOAD_COMPILED_PATH
  288. This variable may be used to augment the path that is searched for
  289. compiled Scheme files (@file{.go} files) when loading. Its value should
  290. be a colon-separated list of directories. If it contains the special
  291. path component @code{...} (ellipsis), then the default path is put in
  292. place of the ellipsis, otherwise the default path is placed at the end.
  293. The result is stored in @code{%load-compiled-path} (@pxref{Load Paths}).
  294. Here is an example using the Bash shell that adds the current directory,
  295. @file{.}, and the relative directory @file{../my-library} to
  296. @code{%load-compiled-path}:
  297. @example
  298. $ export GUILE_LOAD_COMPILED_PATH=".:../my-library"
  299. $ guile -c '(display %load-compiled-path) (newline)'
  300. (. ../my-library /usr/local/lib/guile/3.0/ccache)
  301. @end example
  302. @item GUILE_LOAD_PATH
  303. @vindex GUILE_LOAD_PATH
  304. This variable may be used to augment the path that is searched for
  305. Scheme files when loading. Its value should be a colon-separated list
  306. of directories. If it contains the special path component @code{...}
  307. (ellipsis), then the default path is put in place of the ellipsis,
  308. otherwise the default path is placed at the end. The result is stored
  309. in @code{%load-path} (@pxref{Load Paths}).
  310. Here is an example using the Bash shell that prepends the current
  311. directory to @code{%load-path}, and adds the relative directory
  312. @file{../srfi} to the end:
  313. @example
  314. $ env GUILE_LOAD_PATH=".:...:../srfi" \
  315. guile -c '(display %load-path) (newline)'
  316. (. /usr/local/share/guile/3.0 \
  317. /usr/local/share/guile/site/3.0 \
  318. /usr/local/share/guile/site \
  319. /usr/local/share/guile \
  320. ../srfi)
  321. @end example
  322. (Note: The line breaks, above, are for documentation purposes only, and
  323. not required in the actual example.)
  324. @item GUILE_EXTENSIONS_PATH
  325. @vindex GUILE_EXTENSIONS_PATH
  326. This variable may be used to augment the path that is searched for
  327. foreign libraries via @code{load-extension}, @code{dynamic-link},
  328. @code{load-foreign-library}, or the like. Its value should be a
  329. colon-separated (semicolon on Windows) list of directories.
  330. @xref{Foreign Libraries}.
  331. @item GUILE_WARN_DEPRECATED
  332. @vindex GUILE_WARN_DEPRECATED
  333. As Guile evolves, some features will be eliminated or replaced by newer
  334. features. To help users migrate their code as this evolution occurs,
  335. Guile will issue warning messages about code that uses features that
  336. have been marked for eventual elimination. @env{GUILE_WARN_DEPRECATED}
  337. can be set to ``no'' to tell Guile not to display these warning
  338. messages, or set to ``detailed'' to tell Guile to display more lengthy
  339. messages describing the warning. @xref{Deprecation}.
  340. @item HOME
  341. @vindex HOME
  342. Guile uses the environment variable @env{HOME}, the name of your home
  343. directory, to locate various files, such as @file{.guile} or
  344. @file{.guile_history}.
  345. @item GUILE_JIT_THRESHOLD
  346. @vindex GUILE_JIT_THRESHOLD
  347. Guile has a just-in-time (JIT) code generator that makes running Guile
  348. code fast. @xref{Just-In-Time Native Code}, for more. The unit of code
  349. generation is the function. Each function has its own counter that gets
  350. incremented when the function is called and at each loop iteration in
  351. the function. When the counter exceeds the @env{GUILE_JIT_THRESHOLD},
  352. the function will get JIT-compiled. Set @env{GUILE_JIT_THRESHOLD} to
  353. @code{-1} to disable JIT compilation, or @code{0} to eagerly JIT-compile
  354. each function as it's first seen.
  355. @item GUILE_JIT_LOG
  356. @vindex GUILE_JIT_LOG
  357. Set to @code{1}, @code{2}, or @code{3} to give increasing amounts of
  358. logging for JIT compilation events. Used for debugging.
  359. @item GUILE_JIT_STOP_AFTER
  360. @vindex GUILE_JIT_STOP_AFTER
  361. Though we have tested the JIT compiler as well as we can, it's possible
  362. that it has bugs. If you suspect that Guile's JIT compiler is causing
  363. your program to fail, set @env{GUILE_JIT_STOP_AFTER} to a positive
  364. integer indicating the maximum number of functions to JIT-compile. By
  365. bisecting over the value of @env{GUILE_JIT_STOP_AFTER}, you can pinpoint
  366. the precise function that is being miscompiled.
  367. @end table
  368. @c Local Variables:
  369. @c mode: texinfo
  370. @c TeX-master: "guile"
  371. @c End: