guile-invoke.texi 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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
  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 -x @var{extension}
  62. Add @var{extension} to the front of Guile's load extension list
  63. (@pxref{Load Paths, @code{%load-extensions}}). The specified extensions
  64. are tried in the order given on the command line, and before the default
  65. load extensions. Extensions added here are @emph{not} in effect during
  66. execution of the user's @file{.guile} file.
  67. @item -l @var{file}
  68. Load Scheme source code from @var{file}, and continue processing the
  69. command line.
  70. @item -e @var{function}
  71. Make @var{function} the @dfn{entry point} of the script. After loading
  72. the script file (with @option{-s}) or evaluating the expression (with
  73. @option{-c}), apply @var{function} to a list containing the program name
  74. and the command-line arguments---the list provided by the
  75. @code{command-line} function.
  76. A @option{-e} switch can appear anywhere in the argument list, but Guile
  77. always invokes the @var{function} as the @emph{last} action it performs.
  78. This is weird, but because of the way script invocation works under
  79. POSIX, the @option{-s} option must always come last in the list.
  80. The @var{function} is most often a simple symbol that names a function
  81. that is defined in the script. It can also be of the form @code{(@@
  82. @var{module-name} @var{symbol})}, and in that case, the symbol is
  83. looked up in the module named @var{module-name}.
  84. For compatibility with some versions of Guile 1.4, you can also use the
  85. form @code{(symbol ...)} (that is, a list of only symbols that doesn't
  86. start with @code{@@}), which is equivalent to @code{(@@ (symbol ...)
  87. main)}, or @code{(symbol ...) symbol} (that is, a list of only symbols
  88. followed by a symbol), which is equivalent to @code{(@@ (symbol ...)
  89. symbol)}. We recommend to use the equivalent forms directly since they
  90. correspond to the @code{(@@ ...)} read syntax that can be used in
  91. normal code. See @ref{Using Guile Modules} and @ref{Scripting
  92. Examples}.
  93. @item -ds
  94. Treat a final @option{-s} option as if it occurred at this point in the
  95. command line; load the script here.
  96. This switch is necessary because, although the POSIX script invocation
  97. mechanism effectively requires the @option{-s} option to appear last, the
  98. programmer may well want to run the script before other actions
  99. requested on the command line. For examples, see @ref{Scripting
  100. Examples}.
  101. @item \
  102. Read more command-line arguments, starting from the second line of the
  103. script file. @xref{The Meta Switch}.
  104. @item --use-srfi=@var{list}
  105. @cindex loading srfi modules (command line)
  106. The option @option{--use-srfi} expects a comma-separated list of numbers,
  107. each representing a SRFI module to be loaded into the interpreter
  108. before evaluating a script file or starting the REPL. Additionally,
  109. the feature identifier for the loaded SRFIs is recognized by
  110. the procedure @code{cond-expand} when this option is used.
  111. Here is an example that loads the modules SRFI-8 ('receive') and SRFI-13
  112. ('string library') before the GUILE interpreter is started:
  113. @example
  114. guile --use-srfi=8,13
  115. @end example
  116. @item --debug
  117. @cindex debugging virtual machine (command line)
  118. Start with the debugging virtual machine (VM) engine. Using the
  119. debugging VM will enable support for VM hooks, which are needed for
  120. tracing, breakpoints, and accurate call counts when profiling. The
  121. debugging VM is slower than the regular VM, though, by about ten
  122. percent. @xref{VM Hooks}, for more information.
  123. By default, the debugging VM engine is only used when entering an
  124. interactive session. When executing a script with @option{-s} or
  125. @option{-c}, the normal, faster VM is used by default.
  126. @vnew{1.8}
  127. @item --no-debug
  128. @cindex debugging virtual machine (command line)
  129. Do not use the debugging VM engine, even when entering an interactive
  130. session.
  131. Note that, despite the name, Guile running with @option{--no-debug}
  132. @emph{does} support the usual debugging facilities, such as printing a
  133. detailed backtrace upon error. The only difference with
  134. @option{--debug} is lack of support for VM hooks and the facilities that
  135. build upon it (see above).
  136. @item -q
  137. @cindex init file, not loading
  138. @cindex @file{.guile} file, not loading
  139. Do not load the initialization file, @file{.guile}. This option only
  140. has an effect when running interactively; running scripts does not load
  141. the @file{.guile} file. @xref{Init File}.
  142. @item --listen[=@var{p}]
  143. While this program runs, listen on a local port or a path for REPL
  144. clients. If @var{p} starts with a number, it is assumed to be a local
  145. port on which to listen. If it starts with a forward slash, it is
  146. assumed to be a path to a UNIX domain socket on which to listen.
  147. If @var{p} is not given, the default is local port 37146. If you look
  148. at it upside down, it almost spells ``Guile''. If you have netcat
  149. installed, you should be able to @kbd{nc localhost 37146} and get a
  150. Guile prompt. Alternately you can fire up Emacs and connect to the
  151. process; see @ref{Using Guile in Emacs} for more details.
  152. Note that opening a port allows anyone who can connect to that port---in
  153. the TCP case, any local user---to do anything Guile can do, as the user
  154. that the Guile process is running as. Do not use @option{--listen} on
  155. multi-user machines. Of course, if you do not pass @option{--listen} to
  156. Guile, no port will be opened.
  157. That said, @option{--listen} is great for interactive debugging and
  158. development.
  159. @vnew{2.0}
  160. @item --auto-compile
  161. Compile source files automatically (default behavior).
  162. @vnew{2.0.1}
  163. @item --fresh-auto-compile
  164. Treat the auto-compilation cache as invalid, forcing recompilation.
  165. @vnew{2.0}
  166. @item --no-auto-compile
  167. Disable automatic source file compilation.
  168. @vnew{2.0}
  169. @item -h@r{, }--help
  170. Display help on invoking Guile, and then exit.
  171. @item -v@r{, }--version
  172. Display the current version of Guile, and then exit.
  173. @end table
  174. @node Environment Variables
  175. @subsection Environment Variables
  176. @cindex environment variables
  177. @cindex shell
  178. @cindex initialization
  179. The @dfn{environment} is a feature of the operating system; it consists
  180. of a collection of variables with names and values. Each variable is
  181. called an @dfn{environment variable} (or, sometimes, a ``shell
  182. variable''); environment variable names are case-sensitive, and it is
  183. conventional to use upper-case letters only. The values are all text
  184. strings, even those that are written as numerals. (Note that here we
  185. are referring to names and values that are defined in the operating
  186. system shell from which Guile is invoked. This is not the same as a
  187. Scheme environment that is defined within a running instance of Guile.
  188. For a description of Scheme environments, @pxref{About Environments}.)
  189. How to set environment variables before starting Guile depends on the
  190. operating system and, especially, the shell that you are using. For
  191. example, here is how to tell Guile to provide detailed warning messages
  192. about deprecated features by setting @env{GUILE_WARN_DEPRECATED} using
  193. Bash:
  194. @example
  195. $ export GUILE_WARN_DEPRECATED="detailed"
  196. $ guile
  197. @end example
  198. @noindent
  199. Or, detailed warnings can be turned on for a single invocation using:
  200. @example
  201. $ env GUILE_WARN_DEPRECATED="detailed" guile
  202. @end example
  203. If you wish to retrieve or change the value of the shell environment
  204. variables that affect the run-time behavior of Guile from within a
  205. running instance of Guile, see @ref{Runtime Environment}.
  206. Here are the environment variables that affect the run-time behavior of
  207. Guile:
  208. @table @env
  209. @item GUILE_AUTO_COMPILE
  210. @vindex GUILE_AUTO_COMPILE
  211. This is a flag that can be used to tell Guile whether or not to compile
  212. Scheme source files automatically. Starting with Guile 2.0, Scheme
  213. source files will be compiled automatically, by default.
  214. If a compiled (@file{.go}) file corresponding to a @file{.scm} file is
  215. not found or is not newer than the @file{.scm} file, the @file{.scm}
  216. file will be compiled on the fly, and the resulting @file{.go} file
  217. stored away. An advisory note will be printed on the console.
  218. Compiled files will be stored in the directory
  219. @file{$XDG_CACHE_HOME/@/guile/@/ccache}, where @env{XDG_CACHE_HOME}
  220. defaults to the directory @file{$HOME/.cache}. This directory will be
  221. created if it does not already exist.
  222. Note that this mechanism depends on the timestamp of the @file{.go} file
  223. being newer than that of the @file{.scm} file; if the @file{.scm} or
  224. @file{.go} files are moved after installation, care should be taken to
  225. preserve their original timestamps.
  226. Set @env{GUILE_AUTO_COMPILE} to zero (0), to prevent Scheme files from
  227. being compiled automatically. Set this variable to ``fresh'' to tell
  228. Guile to compile Scheme files whether they are newer than the compiled
  229. files or not.
  230. @xref{Compilation}.
  231. @item GUILE_HISTORY
  232. @vindex GUILE_HISTORY
  233. This variable names the file that holds the Guile REPL command history.
  234. You can specify a different history file by setting this environment
  235. variable. By default, the history file is @file{$HOME/.guile_history}.
  236. @item GUILE_LOAD_COMPILED_PATH
  237. @vindex GUILE_LOAD_COMPILED_PATH
  238. This variable may be used to augment the path that is searched for
  239. compiled Scheme files (@file{.go} files) when loading. Its value should
  240. be a colon-separated list of directories, which will be prefixed to the
  241. value of the default search path stored in @code{%load-compiled-path}.
  242. Here is an example using the Bash shell that adds the current directory,
  243. @file{.}, and the relative directory @file{../my-library} to
  244. @code{%load-compiled-path}:
  245. @example
  246. $ export GUILE_LOAD_COMPILED_PATH=".:../my-library"
  247. $ guile -c '(display %load-compiled-path) (newline)'
  248. (. ../my-library /usr/local/lib/guile/2.0/ccache)
  249. @end example
  250. @item GUILE_LOAD_PATH
  251. @vindex GUILE_LOAD_PATH
  252. This variable may be used to augment the path that is searched for
  253. Scheme files when loading. Its value should be a colon-separated list
  254. of directories, which will be prefixed to the value of the default
  255. search path stored in @code{%load-path}.
  256. Here is an example using the Bash shell that adds the current directory
  257. and the parent of the current directory to @code{%load-path}:
  258. @example
  259. $ env GUILE_LOAD_PATH=".:.." \
  260. guile -c '(display %load-path) (newline)'
  261. (. .. /usr/local/share/guile/2.0 \
  262. /usr/local/share/guile/site/2.0 \
  263. /usr/local/share/guile/site /usr/local/share/guile)
  264. @end example
  265. (Note: The line breaks, above, are for documentation purposes only, and
  266. not required in the actual example.)
  267. @item GUILE_WARN_DEPRECATED
  268. @vindex GUILE_WARN_DEPRECATED
  269. As Guile evolves, some features will be eliminated or replaced by newer
  270. features. To help users migrate their code as this evolution occurs,
  271. Guile will issue warning messages about code that uses features that
  272. have been marked for eventual elimination. @env{GUILE_WARN_DEPRECATED}
  273. can be set to ``no'' to tell Guile not to display these warning
  274. messages, or set to ``detailed'' to tell Guile to display more lengthy
  275. messages describing the warning. @xref{Deprecation}.
  276. @item HOME
  277. @vindex HOME
  278. Guile uses the environment variable @env{HOME}, the name of your home
  279. directory, to locate various files, such as @file{.guile} or
  280. @file{.guile_history}.
  281. @item LTDL_LIBRARY_PATH
  282. @vindex LTDL_LIBRARY_PATH
  283. Guile now adds its install prefix to the @env{LTDL_LIBRARY_PATH}.
  284. Users may now install Guile in non-standard directories and run
  285. `/path/to/bin/guile', without having also to set @env{LTDL_LIBRARY_PATH}
  286. to include `/path/to/lib'.
  287. @end table
  288. @c Local Variables:
  289. @c mode: texinfo
  290. @c TeX-master: "guile"
  291. @c End: