guile-invoke.texi 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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, 2010, 2011, 2013
  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. For compatibility with some versions of Guile 1.4, you can also use the
  87. form @code{(symbol ...)} (that is, a list of only symbols that doesn't
  88. start with @code{@@}), which is equivalent to @code{(@@ (symbol ...)
  89. main)}, or @code{(symbol ...) symbol} (that is, a list of only symbols
  90. followed by a symbol), which is equivalent to @code{(@@ (symbol ...)
  91. symbol)}. We recommend to use the equivalent forms directly since they
  92. correspond to the @code{(@@ ...)} read syntax that can be used in
  93. normal code. See @ref{Using Guile Modules} and @ref{Scripting
  94. Examples}.
  95. @item -ds
  96. Treat a final @option{-s} option as if it occurred at this point in the
  97. command line; load the script here.
  98. This switch is necessary because, although the POSIX script invocation
  99. mechanism effectively requires the @option{-s} option to appear last, the
  100. programmer may well want to run the script before other actions
  101. requested on the command line. For examples, see @ref{Scripting
  102. Examples}.
  103. @item \
  104. Read more command-line arguments, starting from the second line of the
  105. script file. @xref{The Meta Switch}.
  106. @item --use-srfi=@var{list}
  107. @cindex loading srfi modules (command line)
  108. The option @option{--use-srfi} expects a comma-separated list of numbers,
  109. each representing a SRFI module to be loaded into the interpreter
  110. before evaluating a script file or starting the REPL. Additionally,
  111. the feature identifier for the loaded SRFIs is recognized by
  112. the procedure @code{cond-expand} when this option is used.
  113. Here is an example that loads the modules SRFI-8 ('receive') and SRFI-13
  114. ('string library') before the GUILE interpreter is started:
  115. @example
  116. guile --use-srfi=8,13
  117. @end example
  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 a path to 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. Note that opening a port allows anyone who can connect to that port---in
  155. the TCP case, any local user---to do anything Guile can do, as the user
  156. that the Guile process is running as. Do not use @option{--listen} on
  157. multi-user machines. Of course, if you do not pass @option{--listen} to
  158. Guile, no port will be opened.
  159. That said, @option{--listen} is great for interactive debugging and
  160. development.
  161. @vnew{2.0}
  162. @item --auto-compile
  163. Compile source files automatically (default behavior).
  164. @vnew{2.0.1}
  165. @item --fresh-auto-compile
  166. Treat the auto-compilation cache as invalid, forcing recompilation.
  167. @vnew{2.0}
  168. @item --no-auto-compile
  169. Disable automatic source file compilation.
  170. @vnew{2.0.8}
  171. @item --language=@var{lang}
  172. For the remainder of the command line arguments, assume that files
  173. mentioned with @code{-l} and expressions passed with @code{-c} are
  174. written in @var{lang}. @var{lang} must be the name of one of the
  175. languages supported by the compiler (@pxref{Compiler Tower}). When run
  176. interactively, set the REPL's language to @var{lang} (@pxref{Using Guile
  177. Interactively}).
  178. The default language is @code{scheme}; other interesting values include
  179. @code{elisp} (for Emacs Lisp), and @code{ecmascript}.
  180. The example below shows the evaluation of expressions in Scheme, Emacs
  181. Lisp, and ECMAScript:
  182. @example
  183. guile -c "(apply + '(1 2))"
  184. guile --language=elisp -c "(= (funcall (symbol-function '+) 1 2) 3)"
  185. guile --language=ecmascript -c '(function (x) @{ return x * x; @})(2);'
  186. @end example
  187. To load a file written in Scheme and one written in Emacs Lisp, and then
  188. start a Scheme REPL, type:
  189. @example
  190. guile -l foo.scm --language=elisp -l foo.el --language=scheme
  191. @end example
  192. @vnew{2.0}
  193. @item -h@r{, }--help
  194. Display help on invoking Guile, and then exit.
  195. @item -v@r{, }--version
  196. Display the current version of Guile, and then exit.
  197. @end table
  198. @node Environment Variables
  199. @subsection Environment Variables
  200. @cindex environment variables
  201. @cindex shell
  202. @cindex initialization
  203. The @dfn{environment} is a feature of the operating system; it consists
  204. of a collection of variables with names and values. Each variable is
  205. called an @dfn{environment variable} (or, sometimes, a ``shell
  206. variable''); environment variable names are case-sensitive, and it is
  207. conventional to use upper-case letters only. The values are all text
  208. strings, even those that are written as numerals. (Note that here we
  209. are referring to names and values that are defined in the operating
  210. system shell from which Guile is invoked. This is not the same as a
  211. Scheme environment that is defined within a running instance of Guile.
  212. For a description of Scheme environments, @pxref{About Environments}.)
  213. How to set environment variables before starting Guile depends on the
  214. operating system and, especially, the shell that you are using. For
  215. example, here is how to tell Guile to provide detailed warning messages
  216. about deprecated features by setting @env{GUILE_WARN_DEPRECATED} using
  217. Bash:
  218. @example
  219. $ export GUILE_WARN_DEPRECATED="detailed"
  220. $ guile
  221. @end example
  222. @noindent
  223. Or, detailed warnings can be turned on for a single invocation using:
  224. @example
  225. $ env GUILE_WARN_DEPRECATED="detailed" guile
  226. @end example
  227. If you wish to retrieve or change the value of the shell environment
  228. variables that affect the run-time behavior of Guile from within a
  229. running instance of Guile, see @ref{Runtime Environment}.
  230. Here are the environment variables that affect the run-time behavior of
  231. Guile:
  232. @table @env
  233. @item GUILE_AUTO_COMPILE
  234. @vindex GUILE_AUTO_COMPILE
  235. This is a flag that can be used to tell Guile whether or not to compile
  236. Scheme source files automatically. Starting with Guile 2.0, Scheme
  237. source files will be compiled automatically, by default.
  238. If a compiled (@file{.go}) file corresponding to a @file{.scm} file is
  239. not found or is not newer than the @file{.scm} file, the @file{.scm}
  240. file will be compiled on the fly, and the resulting @file{.go} file
  241. stored away. An advisory note will be printed on the console.
  242. Compiled files will be stored in the directory
  243. @file{$XDG_CACHE_HOME/@/guile/@/ccache}, where @env{XDG_CACHE_HOME}
  244. defaults to the directory @file{$HOME/.cache}. This directory will be
  245. created if it does not already exist.
  246. Note that this mechanism depends on the timestamp of the @file{.go} file
  247. being newer than that of the @file{.scm} file; if the @file{.scm} or
  248. @file{.go} files are moved after installation, care should be taken to
  249. preserve their original timestamps.
  250. Set @env{GUILE_AUTO_COMPILE} to zero (0), to prevent Scheme files from
  251. being compiled automatically. Set this variable to ``fresh'' to tell
  252. Guile to compile Scheme files whether they are newer than the compiled
  253. files or not.
  254. @xref{Compilation}.
  255. @item GUILE_HISTORY
  256. @vindex GUILE_HISTORY
  257. This variable names the file that holds the Guile REPL command history.
  258. You can specify a different history file by setting this environment
  259. variable. By default, the history file is @file{$HOME/.guile_history}.
  260. @item GUILE_INSTALL_LOCALE
  261. @vindex GUILE_INSTALL_LOCALE
  262. This is a flag that can be used to tell Guile whether or not to install
  263. the current locale at startup, via a call to @code{(setlocale LC_ALL
  264. "")}. @xref{Locales}, for more information on locales.
  265. You may explicitly indicate that you do not want to install
  266. the locale by setting @env{GUILE_INSTALL_LOCALE} to @code{0}, or
  267. explicitly enable it by setting the variable to @code{1}.
  268. Usually, installing the current locale is the right thing to do. It
  269. allows Guile to correctly parse and print strings with non-ASCII
  270. characters. Therefore, this option is on by default.
  271. @item GUILE_STACK_SIZE
  272. @vindex GUILE_STACK_SIZE
  273. Guile currently has a limited stack size for Scheme computations.
  274. Attempting to call too many nested functions will signal an error. This
  275. is good to detect infinite recursion, but sometimes the limit is reached
  276. for normal computations. This environment variable, if set to a
  277. positive integer, specifies the number of Scheme value slots to allocate
  278. for the stack.
  279. In the future we will implement stacks that can grow and shrink, but for
  280. now this hack will have to do.
  281. @item GUILE_LOAD_COMPILED_PATH
  282. @vindex GUILE_LOAD_COMPILED_PATH
  283. This variable may be used to augment the path that is searched for
  284. compiled Scheme files (@file{.go} files) when loading. Its value should
  285. be a colon-separated list of directories. If it contains the special
  286. path component @code{...} (ellipsis), then the default path is put in
  287. place of the ellipsis, otherwise the default path is placed at the end.
  288. The result is stored in @code{%load-compiled-path} (@pxref{Load Paths}).
  289. Here is an example using the Bash shell that adds the current directory,
  290. @file{.}, and the relative directory @file{../my-library} to
  291. @code{%load-compiled-path}:
  292. @example
  293. $ export GUILE_LOAD_COMPILED_PATH=".:../my-library"
  294. $ guile -c '(display %load-compiled-path) (newline)'
  295. (. ../my-library /usr/local/lib/guile/2.0/ccache)
  296. @end example
  297. @item GUILE_LOAD_PATH
  298. @vindex GUILE_LOAD_PATH
  299. This variable may be used to augment the path that is searched for
  300. Scheme files when loading. Its value should be a colon-separated list
  301. of directories. If it contains the special path component @code{...}
  302. (ellipsis), then the default path is put in place of the ellipsis,
  303. otherwise the default path is placed at the end. The result is stored
  304. in @code{%load-path} (@pxref{Load Paths}).
  305. Here is an example using the Bash shell that prepends the current
  306. directory to @code{%load-path}, and adds the relative directory
  307. @file{../srfi} to the end:
  308. @example
  309. $ env GUILE_LOAD_PATH=".:...:../srfi" \
  310. guile -c '(display %load-path) (newline)'
  311. (. /usr/local/share/guile/2.0 \
  312. /usr/local/share/guile/site/2.0 \
  313. /usr/local/share/guile/site \
  314. /usr/local/share/guile \
  315. ../srfi)
  316. @end example
  317. (Note: The line breaks, above, are for documentation purposes only, and
  318. not required in the actual example.)
  319. @item GUILE_WARN_DEPRECATED
  320. @vindex GUILE_WARN_DEPRECATED
  321. As Guile evolves, some features will be eliminated or replaced by newer
  322. features. To help users migrate their code as this evolution occurs,
  323. Guile will issue warning messages about code that uses features that
  324. have been marked for eventual elimination. @env{GUILE_WARN_DEPRECATED}
  325. can be set to ``no'' to tell Guile not to display these warning
  326. messages, or set to ``detailed'' to tell Guile to display more lengthy
  327. messages describing the warning. @xref{Deprecation}.
  328. @item HOME
  329. @vindex HOME
  330. Guile uses the environment variable @env{HOME}, the name of your home
  331. directory, to locate various files, such as @file{.guile} or
  332. @file{.guile_history}.
  333. @item LTDL_LIBRARY_PATH
  334. @vindex LTDL_LIBRARY_PATH
  335. Guile now adds its install prefix to the @env{LTDL_LIBRARY_PATH}.
  336. Users may now install Guile in non-standard directories and run
  337. `/path/to/bin/guile', without having also to set @env{LTDL_LIBRARY_PATH}
  338. to include `/path/to/lib'.
  339. @end table
  340. @c Local Variables:
  341. @c mode: texinfo
  342. @c TeX-master: "guile"
  343. @c End: