1.0.13.47: spurious INLINE declaration for (SETF FOO) from typed DEFSTRUCT
[sbcl/simd.git] / doc / manual / start-stop.texinfo
blob77940c22be0e9669cb676415c1f5fcb9219cf638
1 @node Starting and Stopping
2 @comment  node-name,  next,  previous,  up
3 @chapter Starting and Stopping
5 @menu
6 * Starting SBCL::
7 * Stopping SBCL::
8 * Command Line Options::
9 * Initialization Files::
10 * Initialization and Exit Hooks::
11 @end menu
13 @node Starting SBCL
14 @comment  node-name,  next,  previous,  up
15 @section Starting SBCL
17 @menu
18 * Running from Shell::
19 * Running from Emacs::
20 * Shebang Scripts::
21 @end menu
23 @node Running from Shell
24 @comment  node-name,  next,  previous,  up
25 @subsection From Shell to Lisp
27 To run SBCL type @command{sbcl} at the command line.
29 You should end up in the toplevel @dfn{REPL} (read, eval, print
30 -loop), where you can interact with SBCL by typing expressions.
32 @smallexample
33 $ sbcl
34 This is SBCL 0.8.13.60, an implementation of ANSI Common Lisp.
35 More information about SBCL is available at <http://www.sbcl.org/>.
37 SBCL is free software, provided as is, with absolutely no warranty.
38 It is mostly in the public domain; some portions are provided under
39 BSD-style licenses.  See the CREDITS and COPYING files in the
40 distribution for more information.
41 * (+ 2 2)
44 * (quit)
46 @end smallexample
48 See also @ref{Command Line Options} and @ref{Stopping SBCL}.
50 @node Running from Emacs
51 @comment  node-name,  next,  previous,  up
52 @subsection Running from Emacs
54 To run SBCL as an inferior-lisp from Emacs in your @file{.emacs} do
55 something like:
57 @lisp
58 ;;; The SBCL binary and command-line arguments
59 (setq inferior-lisp-program "/usr/local/bin/sbcl --noinform")
60 @end lisp
62 For more information on using SBCL with Emacs, see @ref{Editor
63 Integration}.
66 @node Shebang Scripts
67 @comment  node-name,  next,  previous,  up
68 @subsection Shebang Scripts
70 SBCL doesn't come with built-in support for shebang-line execution,
71 but this can be provided with a shell trampoline, or by dispatching
72 from initialization files (@pxref{Unix-style Command Line Protocol} for
73 an example.)
76 @node Stopping SBCL
77 @comment  node-name,  next,  previous,  up
78 @section Stopping SBCL
80 @menu
81 * Quit::
82 * End of File::
83 * Saving a Core Image::
84 * Exit on Errors::
85 @end menu
87 @node Quit
88 @comment  node-name,  next,  previous,  up
89 @subsection Quit
91 SBCL can be stopped at any time by calling @code{sb-ext:quit},
92 optionally returning a specified numeric value to the calling process.
93 See notes in @ref{Threading} about the interaction between this
94 feature and sessions.
96 @include fun-sb-ext-quit.texinfo
98 @node End of File
99 @comment  node-name,  next,  previous,  up
100 @subsection End of File
102 By default SBCL also exits on end of input, caused either by user
103 pressing @kbd{Control-D} on an attached terminal, or end of input when
104 using SBCL as part of a shell pipeline.
106 @node Saving a Core Image
107 @comment  node-name,  next,  previous,  up
108 @subsection Saving a Core Image
110 SBCL has the ability to save its state as a file for later
111 execution. This functionality is important for its bootstrapping
112 process, and is also provided as an extension to the user.
114 @include fun-sb-ext-save-lisp-and-die.texinfo
115 @include var-sb-ext-star-save-hooks-star.texinfo
117 To facilitate distribution of SBCL applications using external
118 resources, the filesystem location of the SBCL core file being used is
119 available from Lisp.
121 @include var-sb-ext-star-core-pathname-star.texinfo
123 @node Exit on Errors
124 @comment  node-name,  next,  previous,  up
125 @subsection Exit on Errors
127 SBCL can also be configured to exit if an unhandled error occurs,
128 which is mainly useful for acting as part of a shell pipeline; doing
129 so under most other circumstances would mean giving up large parts of
130 the flexibility and robustness of Common Lisp. See @ref{Debugger Entry}.
132 @node Command Line Options
133 @comment  node-name,  next,  previous,  up
134 @section Command Line Options
136 @c FIXME: This is essentially cut-and-paste from the manpage
137 @c What should probably be done is generate both this and the
138 @c man-page from ``sbcl --help'' output.
140 Command line options can be considered an advanced topic; for ordinary
141 interactive use, no command line arguments should be necessary.
143 In order to understand the command line argument syntax for SBCL, it
144 is helpful to understand that the SBCL system is implemented as two
145 components, a low-level runtime environment written in C and a
146 higher-level system written in Common Lisp itself. Some command line
147 arguments are processed during the initialization of the low-level
148 runtime environment, some command line arguments are processed during
149 the initialization of the Common Lisp system, and any remaining
150 command line arguments are passed on to user code.
152 The full, unambiguous syntax for invoking SBCL at the command line is:
154 @command{sbcl} @var{runtime-option}* @code{--end-runtime-options} @var{toplevel-option}* @code{--end-toplevel-options} @var{user-options}*
156 For convenience, the @code{--end-runtime-options} and
157 @code{--end-toplevel-options} elements can be omitted. Omitting these
158 elements can be convenient when you are running the program
159 interactively, and you can see that no ambiguities are possible with
160 the option values you are using. Omitting these elements is probably a
161 bad idea for any batch file where any of the options are under user
162 control, since it makes it impossible for SBCL to detect erroneous
163 command line input, so that erroneous command line arguments will be
164 passed on to the user program even if they was intended for the
165 runtime system or the Lisp system.
167 @menu
168 * Runtime Options::
169 * Toplevel Options::
170 @end menu
172 @node Runtime Options
173 @comment  node-name,  next,  previous,  up
174 @subsection Runtime Options
176 @table @code
178 @item --core @var{corefilename}
179 Run the specified Lisp core file instead of the default. Note that if
180 the Lisp core file is a user-created core file, it may run a
181 nonstandard toplevel which does not recognize the standard toplevel
182 options.
184 @item --dynamic-space-size @var{megabytes}
185 Size of the dynamic space reserved on startup in megabytes. Default
186 value is platform dependent.
188 @item --noinform
189 Suppress the printing of any banner or other informational message at
190 startup. This makes it easier to write Lisp programs which work
191 cleanly in Unix pipelines. See also the @code{--noprint} and
192 @code{--disable-debugger} options.
194 @item --help
195 Print some basic information about SBCL, then exit.
197 @item --version
198 Print SBCL's version information, then exit.
200 @end table
202 In the future, runtime options may be added to control behaviour such
203 as lazy allocation of memory.
205 Runtime options, including any --end-runtime-options option, are
206 stripped out of the command line before the Lisp toplevel logic gets a
207 chance to see it.
209 @node Toplevel Options
210 @comment  node-name,  next,  previous,  up
211 @subsection Toplevel Options
213 @table @code
215 @item --sysinit @var{filename}
216 Load filename instead of the default system initialization file
217 (@pxref{System Initialization File}.)
219 @item --no-sysinit
220 Don't load a system-wide initialization file.  If this option is given,
221 the @code{--sysinit} option is ignored.
223 @item --userinit @var{filename}
224 Load filename instead of the default user initialization file
225 (@pxref{User Initialization File}.)
227 @item --no-userinit
228 Don't load a user initialization file.  If this option is given,
229 the @code{--userinit} option is ignored.
231 @item --eval @var{command}
232 After executing any initialization file, but before starting the
233 read-eval-print loop on standard input, read and evaluate the com-
234 mand given. More than one @code{--eval} option can be used, and all
235 will be read and executed, in the order they appear on the command
236 line.
238 @item --load @var{filename}
239 This is equivalent to @code{--eval '(load "@var{filename}")'}. The
240 special syntax is intended to reduce quoting headaches when invoking
241 SBCL from shell scripts.
243 @item --noprint
244 When ordinarily the toplevel "read-eval-print loop" would be exe-
245 cuted, execute a "read-eval loop" instead, i.e. don't print a prompt
246 and don't echo results. Combined with the @code{--noinform} runtime
247 option, this makes it easier to write Lisp "scripts" which work
248 cleanly in Unix pipelines.
250 @item --disable-debugger
251 This is equivalent to @code{--eval '(sb-ext:disable-debugger)'}.
252 @xref{Debugger Entry}.
254 @end table
257 @node Initialization Files
258 @comment  node-name,  next,  previous,  up
259 @section Initialization Files
261 This section covers initialization files processed at startup, which
262 can be used to customize the lisp environment.
264 @menu
265 * System Initialization File::
266 * User Initialization File::
267 * Initialization File Semantics::
268 * Initialization Examples::
269 @end menu
271 @node System Initialization File
272 @comment  node-name,  next,  previous,  up
273 @subsection System Initialization File
275 Site-wide startup script. Unless overridden with the command line
276 option @code{--sysinit} defaults to @file{@env{SBCL_HOME}/sbclrc}, or
277 if that doesn't exist to @file{/etc/sbclrc}.
279 No system initialization file is required.
281 @node User Initialization File
282 @comment  node-name,  next,  previous,  up
283 @subsection User Initialization File
285 Per-user startup script. Unless overridden with the command line
286 option @code{--userinit} defaults to @file{@env{HOME}/.sbclrc}.
288 No user initialization file is required.
290 @node Initialization File Semantics
291 @comment  node-name,  next,  previous,  up
292 @subsection Initialization File Semantics
294 SBCL processes initialization files with @code{read} and @code{eval},
295 not @code{load}; hence initialization files can be used to set startup
296 @code{*package*} and @code{*readtable*}, and for proclaiming a global
297 optimization policy.
299 @node Initialization Examples
300 @comment  node-name,  next,  previous,  up
301 @subsection Initialization Examples
303 Some examples of what you may consider doing in the initialization
304 files follow.
306 @menu
307 * Unix-style Command Line Protocol::
308 * Automatic Recompilation of Stale Fasls::
309 @end menu
311 @node Unix-style Command Line Protocol
312 @comment  node-name,  next,  previous,  up
313 @subsubsection Unix-style Command Line Protocol
314 @vindex sb-ext:*posix-argv*
315 @vindex *posix-argv*
317 Standard Unix tools that are interpreters follow a common command line
318 protocol that is necessary to work with ``shebang scripts''. SBCL
319 doesn't do this by default, but adding the following snippet to an
320 initialization file does the trick:
322 @lisp
323 ;;; If the first user-processable command-line argument is a filename,
324 ;;; disable the debugger, load the file handling shebang-line and quit.
325 (let ((script (and (second *posix-argv*)
326                    (probe-file (second *posix-argv*)))))
327    (when script
328       ;; Handle shebang-line
329       (set-dispatch-macro-character #\# #\!
330                                     (lambda (stream char arg)
331                                        (declare (ignore char arg))
332                                        (read-line stream)))
333       ;; Disable debugger
334       (setf *invoke-debugger-hook*
335             (lambda (condition hook)
336               (declare (ignore hook))
337               ;; Uncomment to get backtraces on errors
338               ;; (sb-debug:backtrace 20)
339               (format *error-output* "Error: ~A~%" condition)
340               (quit)))
341       (load script)
342       (quit)))
343 @end lisp
345 Example file (@file{hello.lisp}):
347 @lisp
348 #!/usr/local/bin/sbcl --noinform
349 (write-line "Hello, World!")
350 @end lisp
352 Usage examples:
354 @smallexample
355 $ ./hello.lisp
356 Hello, World!
357 @end smallexample
359 @smallexample
360 $ sbcl hello.lisp
361 This is SBCL 0.8.13.70, an implementation of ANSI Common Lisp.
362 More information about SBCL is available at <http://www.sbcl.org/>.
364 SBCL is free software, provided as is, with absolutely no warranty.
365 It is mostly in the public domain; some portions are provided under
366 BSD-style licenses.  See the CREDITS and COPYING files in the
367 distribution for more information.
368 Hello, World!
369 @end smallexample
372 @node Automatic Recompilation of Stale Fasls
373 @comment  node-name,  next,  previous,  up
374 @subsubsection Automatic Recompilation of Stale Fasls
376 SBCL fasl-format is at current stage of development undergoing
377 non-backwards compatible changes fairly often. The following snippet
378 handles recompilation automatically for ASDF-based systems.
380 @lisp
381 (require :asdf)
383 ;;; If a fasl was stale, try to recompile and load (once).
384 (defmethod asdf:perform :around ((o asdf:load-op)
385                                  (c asdf:cl-source-file))
386    (handler-case (call-next-method o c)
387       ;; If a fasl was stale, try to recompile and load (once).
388       (sb-ext:invalid-fasl ()
389          (asdf:perform (make-instance 'asdf:compile-op) c)
390          (call-next-method))))
391 @end lisp
393 @node Initialization and Exit Hooks
394 @comment  node-name,  next,  previous,  up
395 @section Initialization and Exit Hooks
397 SBCL provides hooks into the system initialization and exit.
399 @include var-sb-ext-star-init-hooks-star.texinfo
400 @include var-sb-ext-star-exit-hooks-star.texinfo