0.pre7.49:
[sbcl.git] / doc / sbcl.1
1 .\" -*- Mode: Text -*-
2 .\"
3 .\" man page introduction to SBCL
4 .\"
5 .\" SBCL, including this man page, is derived from CMU Common Lisp, of
6 .\" which it was said (ca. 1991)
7 .\"   **********************************************************************
8 .\"   This code was written as part of the CMU Common Lisp project at
9 .\"   Carnegie Mellon University, and has been placed in the public domain.
10 .\"   If you want to use this code or any part of CMU Common Lisp, please
11 .\"   contact Scott Fahlman or slisp-group@cs.cmu.edu.
12 .\"   **********************************************************************
13 .\" Most of SBCL, including this man page, is in the public domain. See
14 .\" COPYING in the distribution for more information.
15 .\"
16 .TH SBCL 1 "$Date$"
17 .AT 3
18 .SH NAME
19 SBCL -- "Steel Bank Common Lisp"
20
21 .SH DESCRIPTION
22
23 SBCL is a free Common Lisp programming environment. It is derived from
24 the free CMU CL programming environment. (The name is intended to
25 acknowledge the connection: steel and banking are the industries where
26 Carnegie and Mellon made the big bucks.)
27
28 .SH COMMAND LINE SYNTAX
29
30 Command line syntax can be considered an advanced topic; for ordinary
31 interactive use, no command line arguments should be necessary.
32
33 In order to understand the command line argument syntax for SBCL, it
34 is helpful to understand that the SBCL system is implemented as two
35 components, a low-level runtime environment written in C and a
36 higher-level system written in Common Lisp itself. Some command line
37 arguments are processed during the initialization of the low-level
38 runtime environment, some command line arguments are processed during
39 the initialization of the Common Lisp system, and any remaining
40 command line arguments are passed on to user code.
41
42 The full, unambiguous syntax for invoking SBCL at the command line is
43 .TP 3
44 .B sbcl [runtime options] --end-runtime-options [toplevel options] --end-toplevel-options [user options]
45 .PP
46
47 For convenience, the --end-runtime-options and --end-toplevel-options
48 elements can be omitted. Omitting these elements can be convenient
49 when you are running the program interactively, and you can see that
50 no ambiguities are possible with the option values you are using.
51 Omitting these elements is probably a bad idea for any batch file
52 where any of the options are under user control, since it makes it
53 impossible for SBCL to detect erroneous command line input, so that
54 erroneous command line arguments will be passed on to the user program
55 even if they was intended for the runtime system or the Lisp system.
56
57 Supported runtime options are
58 .TP 3
59 .B --core <corefilename>
60 Run the specified Lisp core file instead of the default. (See the FILES
61 section.) Note that if the Lisp core file is a user-created core file, it may
62 run a nonstandard toplevel which does not recognize the standard toplevel
63 options.
64 .TP 3
65 .B --noinform
66 Suppress the printing of any banner or other informational message at
67 startup. (This makes it easier to write Lisp programs which work in
68 Unix pipelines. See also the "--noprogrammer" and "--noprint" options.)
69 .PP
70
71 In the future, runtime options may be added to control behavior such
72 as lazy allocation of memory.
73
74 Runtime options, including any --end-runtime-options option,
75 are stripped out of the command line before the
76 Lisp toplevel logic gets a chance to see it.
77
78 Supported toplevel options for the standard SBCL core are
79 .TP 3
80 .B --sysinit <filename>
81 Load filename instead of the default system-wide initialization file.
82 (See the FILES section.) There is no special option to cause no
83 system-wide initialization file to be read, but on a Unix system
84 "--sysinit /dev/null" can be used to achieve the same effect.
85 .TP 3
86 .B --userinit <filename>
87 Load filename instead of the default user initialization file. (See
88 the FILES section.) There is no special option to cause no user
89 initialization file to be read, but on a Unix system "--userinit
90 /dev/null" can be used to achieve the same effect.
91 .TP 3
92 .B --eval <command>
93 After executing any initialization file, but before starting the
94 read-eval-print loop on standard input, evaluate the command given.
95 More than one --eval option can be used, and all will be executed, in
96 the order they appear on the command line.
97 .TP 3
98 .B --noprint
99 When ordinarily the toplevel "read-eval-print loop" would be executed,
100 execute a "read-eval loop" instead, i.e. don't print a prompt and
101 don't echo results. Combined with the --noinform runtime option, this
102 makes it easier to write Lisp "scripts" which work in Unix pipelines.
103 .TP 3
104 .B --noprogrammer
105 By default, a Common Lisp system tries to ask the programmer for help
106 when it gets in trouble (by printing a debug prompt on *DEBUG-IO*).
107 However, this is not useful behavior for a system running with no
108 programmer available, and this option tries to set up more appropriate
109 behavior for that situation. Thus we set *DEBUG-IO* to send its
110 output to *ERROR-OUTPUT*, and to raise an error if any input is
111 requested from it; and we set *DEBUGGER-HOOK* to output a backtrace,
112 then exit the process with a failure code.
113 .PP
114
115 Regardless of the order in which --sysinit, --userinit, and --eval
116 options appear on the command line, the sysinit file, if it exists, is
117 loaded first; then the userinit file, if it exists, is loaded; then
118 any --eval commands are executed in sequence; then the read-eval-print
119 loop is started on standard input. At any step, error conditions or
120 commands such as SB-EXT:QUIT can cause execution to be terminated
121 before proceeding to subsequent steps.
122
123 Note that when running SBCL with the --core option, using a core file
124 created by a user call to the SB-EXT:SAVE-LISP-AND-DIE, the toplevel
125 options may be under the control of user code passed as arguments to
126 SB-EXT:SAVE-LISP-AND-DIE. For this purpose, the --end-toplevel-options
127 option itself can be considered a toplevel option, i.e. the user core,
128 at its option, may not support it.
129
130 In the standard SBCL startup sequence (i.e. with no user core
131 involved) toplevel options and any --end-toplevel-options option are
132 stripped out of the command line argument list before user code gets a
133 chance to see it.
134
135 .SH OVERVIEW
136
137 SBCL aims for but has not reached ANSI compliance.
138
139 SBCL compiles Lisp to native code, or optionally to more-compact but
140 much slower byte code.
141
142 SBCL's garbage collector is generational and conservative.
143
144 SBCL includes a source level debugger, as well as the ANSI TRACE
145 facility and a rudimentary profiler.
146
147 .SH DIFFERENCES FROM CMU CL
148
149 SBCL can be built from scratch using a plain vanilla ANSI Common Lisp
150 system and a C compiler, and all of its properties are specified by
151 the version of the source code that it was created from. (This clean
152 bootstrappability was the immediate motivation for forking off of the
153 CMU CL development tree.) A variety of internal implementation
154 differences are motivated by this.
155
156 Maintenance work in SBCL since the fork has diverged in various
157 details from the maintenance work in CMU CL. E.g. as of 2001-04-12,
158 SBCL was more ANSI-compliant than CMU CL in various details such as
159 support for PRINT-OBJECT and DESCRIBE-OBJECT, and SBCL's compiler was
160 substantially better than CMU CL's at optimizing operations on
161 non-simple vectors.
162
163 Most extensions supported by CMU CL are not supported in SBCL,
164 including Motif support, the Hemlock editor, search paths, the
165 low-level Unix interface, the WIRE protocol, multithreading support,
166 various user-level macros and functions (e.g. LETF, ITERATE, MEMQ,
167 REQUIRED-ARGUMENT), and many others.
168
169 SBCL has retained some extensions from parent CMU CL. Many of the
170 retained extensions are in these categories:
171 .TP 3
172 \--
173 things which might be in the new ANSI spec, e.g. weak pointers,
174 finalization, foreign function interface to C, and Gray streams
175 .TP 3
176 \--
177 things which are universally available in Unix scripting languages,
178 e.g. RUN-PROGRAM and POSIX argv and getenv
179 .TP 3
180 \--
181 hooks into the low level workings of the system which can be useful
182 for debugging, e.g. a list of functions to be run whenever GC occurs,
183 or parameters to modify compiler diagnostic output
184 .TP 3
185 \--
186 unportable performance hacks, e.g. TRULY-THE, FREEZE-TYPE, and PURIFY
187 .PP
188
189 There are also a few retained extensions which don't fall into
190 any particular category, e.g.
191 .TP 3
192 \--
193 the ability to save running Lisp images as executable files
194 .PP
195
196 Some of the retained extensions have new names and/or different
197 options than their CMU CL counterparts. For example, the SBCL function
198 which saves a Lisp image to disk and kills it is called
199 SAVE-LISP-AND-DIE instead of SAVE-LISP, and it supports fewer keyword
200 options than CMU CL's SAVE-LISP.
201
202 (Why doesn't SBCL support more extensions? Why the hell did I (WHN)
203 drop all those nice extensions from CMU CL when the code already
204 exists? This is a frequently asked question on the mailing list. The
205 answer is that they're hard to maintain, and I have enough on my hands
206 already. Also, in the case of some big and unquestionably useful
207 extensions, like sockets and Motif, I think that SBCL has done its job
208 by supplying the FFI, and that people who need, and understand, and
209 are motivated to maintain the functionality should supply it as a
210 separate library, which I'd be happy to distribute or link to on the
211 SBCL home page. Finally, in the case of multithreading, I do think it
212 belongs in the new ANSI spec, and it'd be a good feature to have, but
213 I didn't think the CMU CL implementation was sufficiently mature, and
214 it's such a complicated and far-reaching extension that I thought that
215 trying to fix it would interfere with the more urgent task of getting
216 basic ANSI support up to speed.)
217
218 .SH THE COMPILER
219
220 SBCL inherits from CMU CL the "Python" native code compiler. This
221 compiler is very clever about understanding the type system of Common
222 Lisp and using it to produce efficient code, and about producing notes
223 to let the user know when the compiler doesn't have enough type
224 information to produce efficient code. It also tries (almost always
225 successfully) to follow the unusual but very useful principle that
226 type declarations should be checked at runtime unless the user
227 explicitly tells the system that speed is more important than safety.
228
229 The CMU CL version of this compiler reportedly produces pretty good
230 code for modern machines which have lots of registers, but its code
231 for the X86 is marred by a lot of extra loads and stores to
232 stack-based temporary variables. Because of this, and because of the
233 extra levels of indirection in Common Lisp relative to C, we find a
234 typical performance decrease by a factor of perhaps 2 to 5 for small
235 programs coded in SBCL instead of GCC.
236
237 For more information about the compiler, see the user manual.
238
239 .SH DOCUMENTATION
240
241 Currently, the documentation for the system is
242 .TP 3
243 \--
244 the user manual
245 .TP 3
246 \--
247 this man page
248 .TP 3
249 \--
250 doc strings and online help built into the SBCL executable
251 .PP
252
253 .SH SYSTEM REQUIREMENTS
254
255 Unlike its distinguished ancestor CMU CL, SBCL is currently on X86
256 (Linux, FreeBSD, and OpenBSD) and Alpha (Linux). It would probably be
257 straightforward to port the CMU CL support for SPARC, or to port to
258 NetBSD.
259
260 As of version 0.6.13, SBCL requires on the order of 16Mb RAM to run
261 on X86 systems. 
262
263 .SH ENVIRONMENT
264
265 .TP 10n
266 .BR SBCL_HOME
267 If this variable is set, it overrides the default directories for
268 files like "sbclrc" and "sbcl.core", so that instead of being searched
269 for in e.g. /etc/, /usr/local/etc/, /usr/lib/, and /usr/local/lib/, they
270 are searched for only in the directory named by SBCL_HOME. This is
271 intended to support users who wish to use their own version of SBCL
272 instead of the version which is currently installed as the system
273 default.
274 .PP
275
276 .SH FILES
277
278 /usr/lib/sbcl.core and /usr/local/lib/sbcl.core are the standard
279 locations for the standard SBCL core, unless overridden by the SBCL_HOME
280 variable.
281
282 /etc/sbclrc and /usr/local/etc/sbclrc are the standard locations for
283 system-wide SBCL initialization files, unless overridden by the
284 SBCL_HOME variable or the --sysinit command line option.
285
286
287 $HOME/.sbclrc is the standard location for a user's SBCL
288 initialization file, unless overridden by the --userinit
289 command line option.
290
291 .SH BUGS
292
293 To report a bug, please send mail to sbcl-help@lists.sourceforge.net
294 or sbcl-devel@lists.sourceforge.net. As with any software bug report,
295 it's most helpful if you remember to describe the environment where
296 the problem occurs (machine type, O/S name and version, etc.) and if
297 you can provide enough information to reproduce the problem,
298 preferably in compact form.
299
300 This section attempts to list the most serious and long-standing bugs
301 or surprising performance hits. For more detailed and current
302 information on bugs, see the BUGS file in the distribution.
303
304 It is possible to get in deep trouble by exhausting
305 memory. To plagiarize a sadly apt description of a language not
306 renowned for the production of bulletproof software, "[The current
307 SBCL implementation of] Common Lisp makes it harder for you to shoot
308 yourself in the foot, but when you do, the entire universe explodes."
309 .TP 3
310 \--
311 The system doesn't deal well with stack overflow. (It tends to cause
312 a segmentation fault instead of being caught cleanly.)
313 .TP 3
314 \--
315 Like CMU CL, the SBCL system overcommits memory at startup. On typical
316 Unix-alikes like Linux and FreeBSD, this means that if the SBCL system
317 turns out to use more virtual memory than the system has available for
318 it, other processes tend to be killed randomly (!).
319 .PP
320
321 The compiler is overaggressive about static typing, assuming that a
322 function's return type never changes. Thus compiling and loading a
323 file containing
324 (DEFUN FOO (X) NIL)
325 (DEFUN BAR (X) (IF (FOO X) 1 2))
326 (DEFUN FOO (X) (PLUSP X))
327 then running (FOO 1) gives 2 (because the compiler "knew"
328 that FOO's return type is NULL).
329
330 The compiler's handling of function return values unnecessarily
331 violates the "declarations are assertions" principle that it otherwise
332 adheres to. Using PROCLAIM or DECLAIM to specify the return type of a
333 function causes the compiler to believe you without checking. Thus
334 compiling a file containing
335 (DECLAIM (FTYPE (FUNCTION (T) NULL) SOMETIMES))
336 (DEFUN SOMETIMES (X) (ODDP X))
337 (DEFUN FOO (X) (IF (SOMETIMES X) 'THIS-TIME 'NOT-THIS-TIME))
338 then running (FOO 1) gives NOT-THIS-TIME, because the
339 never compiled code to check the declaration.
340
341 The implementation of multidimensional arrays, especially
342 multidimensional arrays of floating point numbers, is very
343 inefficient.
344
345 SYMBOL-FUNCTION is much slower than you might expect, being
346 implemented not as a slot access but as a search through the
347 compiler/kernel "globaldb" database.
348
349 CLOS (based on the PCL reference implementation) is somewhat
350 inefficient.
351
352 There are many nagging pre-ANSIisms, e.g.
353 .TP 3
354 \--
355 CLOS (based on the PCL reference implementation) is incompletely
356 integrated into the system, so that e.g. SB-PCL::FIND-CLASS is a
357 different function than CL::FIND-CLASS. (This is less of a problem in
358 practice than the speed, but it's still distasteful.)
359 .TP 3
360 --
361 The ANSI-recommended idiom for creating a function which is only
362 sometimes expanded inline,
363 (DECLAIM (INLINE F))
364 (DEFUN F ...)
365 (DECLAIM (NOTINLINE F)),
366 doesn't do what you'd expect. (Instead, you have to declare the
367 function as SB-EXT:MAYBE-INLINE to get the desired effect.)
368 .TP 3
369 \--
370 The DYNAMIC-EXTENT declaration is not implemented, and is simply
371 ignored. (This is allowed by the ANSI spec, but can have a large
372 efficiency cost in some kinds of code, e.g. code which uses a lot
373 of upward closures or &REST lists.)
374 .TP 3
375 --
376 Compiling DEFSTRUCT in strange places (e.g. inside a DEFUN) doesn't
377 do anything like what it should.
378 .TP 3
379 \--
380 The symbol * is the name of a type similar to T. (It's used as part of
381 the implementation of compound types like (ARRAY * 1) and (CONS * *).
382 In a strict ANSI implementation, * would not be the name of a type,
383 but instead just a symbol which is recognized and handled specially by
384 certain type expanders.)
385 .PP
386
387 .SH SUPPORT
388
389 Various information about SBCL is available at
390 <http://sbcl.sourceforge.net/>. The mailing lists there are the
391 recommended place to look for support.
392
393 .SH DISTRIBUTION
394
395 SBCL is a free implementation of Common Lisp derived from CMU CL. Both
396 sources and executables are freely available; this software is "as
397 is", and has no warranty of any kind. CMU and the authors assume no
398 responsibility for the consequences of any use of this software. See
399 the CREDITS file in the distribution for more information about
400 history, contributors and permissions.
401