0.pre7.50:
[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. (Unlike earlier versions of SBCL,
140 byte compilation is no longer supported.)
141
142 SBCL uses a generational conservative garbage collector for some ports,
143 and a simple stop-and-copy garbage collector for other ports.
144
145 SBCL includes a source level debugger, as well as the ANSI TRACE
146 facility and a profiler.
147
148 .SH DIFFERENCES FROM CMU CL
149
150 SBCL can be built from scratch using a plain vanilla ANSI Common Lisp
151 system and a C compiler, and all of its properties are specified by
152 the version of the source code that it was created from. (This clean
153 bootstrappability was the immediate motivation for forking off of the
154 CMU CL development tree.) A variety of internal implementation
155 differences are motivated by this.
156
157 Maintenance work in SBCL since the fork has diverged in various
158 details from the maintenance work in CMU CL. E.g. as of 2001-04-12,
159 SBCL was more ANSI-compliant than CMU CL in various details such as
160 support for PRINT-OBJECT and DESCRIBE-OBJECT, and SBCL's compiler was
161 substantially better than CMU CL's at optimizing operations on
162 non-simple vectors.
163
164 Most extensions supported by CMU CL are not supported in SBCL,
165 including Motif support, the Hemlock editor, search paths, the
166 low-level Unix interface, the WIRE protocol, multithreading support,
167 various user-level macros and functions (e.g. LETF, ITERATE, MEMQ,
168 REQUIRED-ARGUMENT), and many others.
169
170 SBCL has retained some extensions from parent CMU CL. Many of the
171 retained extensions are in these categories:
172 .TP 3
173 \--
174 things which might be in the new ANSI spec, e.g. weak pointers,
175 finalization, foreign function interface to C, and Gray streams
176 .TP 3
177 \--
178 things which are universally available in Unix scripting languages,
179 e.g. RUN-PROGRAM and POSIX argv and getenv
180 .TP 3
181 \--
182 hooks into the low level workings of the system which can be useful
183 for debugging, e.g. a list of functions to be run whenever GC occurs,
184 or parameters to modify compiler diagnostic output
185 .TP 3
186 \--
187 unportable performance hacks, e.g. TRULY-THE, FREEZE-TYPE, and PURIFY
188 .PP
189
190 There are also a few retained extensions which don't fall into
191 any particular category, e.g.
192 .TP 3
193 \--
194 the ability to save running Lisp images as executable files
195 .PP
196
197 Some of the retained extensions have new names and/or different
198 options than their CMU CL counterparts. For example, the SBCL function
199 which saves a Lisp image to disk and kills it is called
200 SAVE-LISP-AND-DIE instead of SAVE-LISP, and it supports fewer keyword
201 options than CMU CL's SAVE-LISP.
202
203 (Why doesn't SBCL support more extensions? Why the hell did I (WHN)
204 drop all those nice extensions from CMU CL when the code already
205 exists? This is a frequently asked question on the mailing list. The
206 answer is that they're hard to maintain, and I have enough on my hands
207 already. Also, in the case of some big and unquestionably useful
208 extensions, like sockets and Motif, I think that SBCL has done its job
209 by supplying the FFI, and that people who need, and understand, and
210 are motivated to maintain the functionality should supply it as a
211 separate library, which I'd be happy to distribute or link to on the
212 SBCL home page. Finally, in the case of multithreading, I do think it
213 belongs in the new ANSI spec, and it'd be a good feature to have, but
214 I didn't think the CMU CL implementation was sufficiently mature, and
215 it's such a complicated and far-reaching extension that I thought that
216 trying to fix it would interfere with the more urgent task of getting
217 basic ANSI support up to speed.)
218
219 .SH THE COMPILER
220
221 SBCL inherits from CMU CL the "Python" native code compiler. This
222 compiler is very clever about understanding the type system of Common
223 Lisp and using it to produce efficient code, and about producing notes
224 to let the user know when the compiler doesn't have enough type
225 information to produce efficient code. It also tries (almost always
226 successfully) to follow the unusual but very useful principle that
227 type declarations should be checked at runtime unless the user
228 explicitly tells the system that speed is more important than safety.
229
230 The CMU CL version of this compiler reportedly produces pretty good
231 code for modern machines which have lots of registers, but its code
232 for the X86 is marred by a lot of extra loads and stores to
233 stack-based temporary variables. Because of this, and because of the
234 extra levels of indirection in Common Lisp relative to C, we find a
235 typical performance decrease by a factor of perhaps 2 to 5 for small
236 programs coded in SBCL instead of GCC.
237
238 For more information about the compiler, see the user manual.
239
240 .SH DOCUMENTATION
241
242 Currently, the documentation for the system is
243 .TP 3
244 \--
245 the user manual
246 .TP 3
247 \--
248 this man page
249 .TP 3
250 \--
251 doc strings and online help built into the SBCL executable
252 .PP
253
254 .SH SYSTEM REQUIREMENTS
255
256 Unlike its distinguished ancestor CMU CL, SBCL is currently on X86
257 (Linux, FreeBSD, and OpenBSD) and Alpha (Linux). It would probably be
258 straightforward to port the CMU CL support for SPARC, or to port to
259 NetBSD.
260
261 As of version 0.6.13, SBCL requires on the order of 16Mb RAM to run
262 on X86 systems. 
263
264 .SH ENVIRONMENT
265
266 .TP 10n
267 .BR SBCL_HOME
268 If this variable is set, it overrides the default directories for
269 files like "sbclrc" and "sbcl.core", so that instead of being searched
270 for in e.g. /etc/, /usr/local/etc/, /usr/lib/, and /usr/local/lib/, they
271 are searched for only in the directory named by SBCL_HOME. This is
272 intended to support users who wish to use their own version of SBCL
273 instead of the version which is currently installed as the system
274 default.
275 .PP
276
277 .SH FILES
278
279 /usr/lib/sbcl.core and /usr/local/lib/sbcl.core are the standard
280 locations for the standard SBCL core, unless overridden by the SBCL_HOME
281 variable.
282
283 /etc/sbclrc and /usr/local/etc/sbclrc are the standard locations for
284 system-wide SBCL initialization files, unless overridden by the
285 SBCL_HOME variable or the --sysinit command line option.
286
287
288 $HOME/.sbclrc is the standard location for a user's SBCL
289 initialization file, unless overridden by the --userinit
290 command line option.
291
292 .SH BUGS
293
294 To report a bug, please send mail to sbcl-help@lists.sourceforge.net
295 or sbcl-devel@lists.sourceforge.net. As with any software bug report,
296 it's most helpful if you remember to describe the environment where
297 the problem occurs (machine type, O/S name and version, etc.) and if
298 you can provide enough information to reproduce the problem,
299 preferably in compact form.
300
301 This section attempts to list the most serious and long-standing bugs
302 or surprising performance hits. For more detailed and current
303 information on bugs, see the BUGS file in the distribution.
304
305 It is possible to get in deep trouble by exhausting
306 memory. To plagiarize a sadly apt description of a language not
307 renowned for the production of bulletproof software, "[The current
308 SBCL implementation of] Common Lisp makes it harder for you to shoot
309 yourself in the foot, but when you do, the entire universe explodes."
310 .TP 3
311 \--
312 The system doesn't deal well with stack overflow. (It tends to cause
313 a segmentation fault instead of being caught cleanly.)
314 .TP 3
315 \--
316 Like CMU CL, the SBCL system overcommits memory at startup. On typical
317 Unix-alikes like Linux and FreeBSD, this means that if the SBCL system
318 turns out to use more virtual memory than the system has available for
319 it, other processes tend to be killed randomly (!).
320 .PP
321
322 The compiler is overaggressive about static typing, assuming that a
323 function's return type never changes. Thus compiling and loading a
324 file containing
325 (DEFUN FOO (X) NIL)
326 (DEFUN BAR (X) (IF (FOO X) 1 2))
327 (DEFUN FOO (X) (PLUSP X))
328 then running (FOO 1) gives 2 (because the compiler "knew"
329 that FOO's return type is NULL).
330
331 The compiler's handling of function return values unnecessarily
332 violates the "declarations are assertions" principle that it otherwise
333 adheres to. Using PROCLAIM or DECLAIM to specify the return type of a
334 function causes the compiler to believe you without checking. Thus
335 compiling a file containing
336 (DECLAIM (FTYPE (FUNCTION (T) NULL) SOMETIMES))
337 (DEFUN SOMETIMES (X) (ODDP X))
338 (DEFUN FOO (X) (IF (SOMETIMES X) 'THIS-TIME 'NOT-THIS-TIME))
339 then running (FOO 1) gives NOT-THIS-TIME, because the
340 never compiled code to check the declaration.
341
342 The implementation of multidimensional arrays, especially
343 multidimensional arrays of floating point numbers, is very
344 inefficient.
345
346 SYMBOL-FUNCTION is much slower than you might expect, being
347 implemented not as a slot access but as a search through the
348 compiler/kernel "globaldb" database.
349
350 CLOS (based on the PCL reference implementation) is somewhat
351 inefficient.
352
353 There are many nagging pre-ANSIisms, e.g.
354 .TP 3
355 \--
356 CLOS (based on the PCL reference implementation) is incompletely
357 integrated into the system, so that e.g. SB-PCL::FIND-CLASS is a
358 different function than CL::FIND-CLASS. (This is less of a problem in
359 practice than the speed, but it's still distasteful.)
360 .TP 3
361 --
362 The ANSI-recommended idiom for creating a function which is only
363 sometimes expanded inline,
364 (DECLAIM (INLINE F))
365 (DEFUN F ...)
366 (DECLAIM (NOTINLINE F)),
367 doesn't do what you'd expect. (Instead, you have to declare the
368 function as SB-EXT:MAYBE-INLINE to get the desired effect.)
369 .TP 3
370 \--
371 The DYNAMIC-EXTENT declaration is not implemented, and is simply
372 ignored. (This is allowed by the ANSI spec, but can have a large
373 efficiency cost in some kinds of code, e.g. code which uses a lot
374 of upward closures or &REST lists.)
375 .TP 3
376 --
377 Compiling DEFSTRUCT in strange places (e.g. inside a DEFUN) doesn't
378 do anything like what it should.
379 .TP 3
380 \--
381 The symbol * is the name of a type similar to T. (It's used as part of
382 the implementation of compound types like (ARRAY * 1) and (CONS * *).
383 In a strict ANSI implementation, * would not be the name of a type,
384 but instead just a symbol which is recognized and handled specially by
385 certain type expanders.)
386 .PP
387
388 .SH SUPPORT
389
390 Various information about SBCL is available at
391 <http://sbcl.sourceforge.net/>. The mailing lists there are the
392 recommended place to look for support.
393
394 .SH DISTRIBUTION
395
396 SBCL is a free implementation of Common Lisp derived from CMU CL. Both
397 sources and executables are freely available; this software is "as
398 is", and has no warranty of any kind. CMU and the authors assume no
399 responsibility for the consequences of any use of this software. See
400 the CREDITS file in the distribution for more information about
401 history, contributors and permissions.
402