92eb13f012fe9d476831300d8b487d40458825c1
[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 It is free software, mostly in the public domain, but with some
29 subsystems under BSD-style licenses which allow modification and
30 reuse as long as credit is given. It is provided "as is", with no
31 warranty of any kind.
32
33 For more information about license issues, see the COPYING file in
34 the distribution. For more information about history, see the 
35 CREDITS file in the distribution.
36
37 .SH RUNNING SBCL
38
39 To run SBCL, type "sbcl" at the command line with no arguments. (SBCL
40 understands command line arguments, but you probably won't need to use
41 them unless you're a fairly advanced user, in which case you should
42 read the COMMAND LINE SYNTAX section, below.) You should see some
43 startup messages, then a prompt ("*"). Type a Lisp expression at the
44 prompt, and SBCL will read it, execute it, print the result, 
45 give you another prompt, and wait for your next input. E.g.
46   * (+ 1 2 3)
47   6
48   *
49
50 Many people like to run SBCL, like other Lisp systems, as a subprocess
51 under Emacs. The Emacs "ilisp" mode provides many convenient features,
52 like command line editing, tab completion, and various kinds of
53 coupling between Common Lisp source files and the interactive SBCL
54 subprocess.
55
56 .SH OVERVIEW
57
58 SBCL aims for but has not reached ANSI compliance.
59
60 SBCL compiles Common Lisp to native code, and is essentially a
61 "compiler-only" implementation of the ANSI standard. (Unlike earlier
62 versions of SBCL, byte compilation is no longer supported, and there
63 is only a vestigial interpreter. Thus, in particular,
64 COMPILED-FUNCTION-P is always equal to FUNCTIONP.)
65
66 SBCL uses a generational conservative garbage collector for some ports,
67 and a simple stop-and-copy garbage collector for other ports.
68
69 SBCL also includes some non-ANSI extensions, notably
70   * Lispy extensions:
71     ** CMU-CL-style safe implementation of type declarations:
72        "Declarations are assertions."
73     ** source level debugger
74     ** profiler
75     ** saving the state of the running SBCL process, producing a
76        "core" file which can be restarted later
77     ** Gray streams (overloadable CLOS classes whose instances can
78        be used wherever ANSI streams can be used)
79     ** weak pointers and finalization (which have unfortunately
80        suffered from at least some code rot, e.g. weak hash tables
81        don't work)
82   * system interface extensions:
83     ** calling out to C code (a.k.a. FFI, foreign function interface)
84     ** some simple support for operations with a "scripting language" 
85        flavor, e.g. reading POSIX argc and argv, or executing a 
86        subprogram
87
88 .SH DIFFERENCES FROM CMU CL
89
90 SBCL can be built from scratch using a plain vanilla ANSI Common Lisp
91 system and a C compiler, and all of its properties are specified by
92 the version of the source code that it was created from. (This clean
93 bootstrappability was the immediate motivation for forking off of the
94 CMU CL development tree.) A variety of internal implementation
95 differences are motivated by this.
96
97 Maintenance work in SBCL since the fork has diverged in various
98 details from the maintenance work in CMU CL. E.g. as of 2001-04-12,
99 SBCL was more ANSI-compliant than CMU CL in various details such as
100 support for PRINT-OBJECT and DESCRIBE-OBJECT, and SBCL's compiler was
101 substantially better than CMU CL's at optimizing operations on
102 non-simple vectors.
103
104 Most extensions supported by CMU CL are not supported in SBCL,
105 including Motif support, the Hemlock editor, search paths, the
106 low-level Unix interface, the WIRE protocol, multithreading support,
107 various user-level macros and functions (e.g. LETF, ITERATE, MEMQ,
108 REQUIRED-ARGUMENT), and many others.
109
110 SBCL has retained some extensions from parent CMU CL. Many of the
111 retained extensions are in these categories:
112 .TP 3
113 \--
114 things which might be in the new ANSI spec, e.g. weak pointers,
115 finalization, foreign function interface to C, and Gray streams
116 .TP 3
117 \--
118 things which are universally available in Unix scripting languages,
119 e.g. RUN-PROGRAM and POSIX argv and getenv
120 .TP 3
121 \--
122 hooks into the low level workings of the system which can be useful
123 for debugging, e.g. a list of functions to be run whenever GC occurs,
124 or parameters to modify compiler diagnostic output
125 .TP 3
126 \--
127 unportable performance hacks, e.g. TRULY-THE, FREEZE-TYPE, and PURIFY
128 .PP
129
130 There are also a few retained extensions which don't fall into
131 any particular category, e.g.
132 .TP 3
133 \--
134 the ability to save running Lisp images as executable files
135 .PP
136
137 Some of the retained extensions have new names and/or different
138 options than their CMU CL counterparts. For example, the SBCL function
139 which saves a Lisp image to disk and kills it is called
140 SAVE-LISP-AND-DIE instead of SAVE-LISP, and it supports fewer keyword
141 options than CMU CL's SAVE-LISP.
142
143 (Why doesn't SBCL support more extensions? Why the hell did I (WHN)
144 drop all those nice extensions from CMU CL when the code already
145 exists? This is a frequently asked question on the mailing list. The
146 answer is that they're hard to maintain, and I have enough on my hands
147 already. Also, in the case of some big and unquestionably useful
148 extensions, like sockets and Motif, I think that SBCL has done its job
149 by supplying the FFI, and that people who need, and understand, and
150 are motivated to maintain the functionality should supply it as a
151 separate library, which I'd be happy to distribute or link to on the
152 SBCL home page. Finally, in the case of multithreading, I do think it
153 belongs in the new ANSI spec, and it'd be a good feature to have, but
154 I didn't think the CMU CL implementation was sufficiently mature, and
155 it's such a complicated and far-reaching extension that I thought that
156 trying to fix it would interfere with the more urgent task of getting
157 basic ANSI support up to speed.)
158
159 .SH THE COMPILER
160
161 As noted above, SBCL is essentially a compiler-only implementation of
162 Lisp, with all nontrivial code being implemented by compilation, even
163 when you type it interactively at the "interpreter" prompt.
164
165 SBCL inherits from CMU CL the "Python" native code compiler. (Though
166 we've essentially dropped the name to avoid confusion with the
167 scripting language also called Python.) This compiler is very clever
168 about understanding the type system of Common Lisp and using it to
169 optimize code, and about producing notes to let the user know when the
170 compiler doesn't have enough type information to produce efficient
171 code. It also tries (almost always successfully) to follow the unusual
172 but very useful principle that "declarations are assertions", i.e.
173 type declarations should be checked at runtime unless the user
174 explicitly tells the system that speed is more important than safety.
175
176 The CMU CL version of this compiler reportedly produces pretty good
177 code for modern CPU architectures which have lots of registers, but
178 its code for the X86 is marred by a lot of extra loads and stores to
179 stack-based temporary variables. Because of this, and because of the
180 extra levels of indirection in Common Lisp relative to C, the
181 performance of SBCL isn't going to impress people who are impressed by
182 small constant factors. However, even on the X86 it tends to be faster
183 than byte interpreted languages (and can be a lot faster).
184
185 For more information about the compiler, see the user manual.
186
187 .SH DOCUMENTATION
188
189 Currently, the documentation for the system is
190 .TP 3
191 \--
192 this man page
193 .TP 3
194 \--
195 the user manual
196 .TP 3
197 \--
198 doc strings and online help built into the SBCL executable
199 .PP
200
201 .SH COMMAND LINE SYNTAX
202
203 Command line syntax can be considered an advanced topic; for ordinary
204 interactive use, no command line arguments should be necessary.
205
206 In order to understand the command line argument syntax for SBCL, it
207 is helpful to understand that the SBCL system is implemented as two
208 components, a low-level runtime environment written in C and a
209 higher-level system written in Common Lisp itself. Some command line
210 arguments are processed during the initialization of the low-level
211 runtime environment, some command line arguments are processed during
212 the initialization of the Common Lisp system, and any remaining
213 command line arguments are passed on to user code.
214
215 The full, unambiguous syntax for invoking SBCL at the command line is
216 .TP 3
217 .B sbcl [runtime options] --end-runtime-options [toplevel options] --end-toplevel-options [user options]
218 .PP
219
220 For convenience, the --end-runtime-options and --end-toplevel-options
221 elements can be omitted. Omitting these elements can be convenient
222 when you are running the program interactively, and you can see that
223 no ambiguities are possible with the option values you are using.
224 Omitting these elements is probably a bad idea for any batch file
225 where any of the options are under user control, since it makes it
226 impossible for SBCL to detect erroneous command line input, so that
227 erroneous command line arguments will be passed on to the user program
228 even if they was intended for the runtime system or the Lisp system.
229
230 Supported runtime options are
231 .TP 3
232 .B --core <corefilename>
233 Run the specified Lisp core file instead of the default. (See the FILES
234 section.) Note that if the Lisp core file is a user-created core file, it may
235 run a nonstandard toplevel which does not recognize the standard toplevel
236 options.
237 .TP 3
238 .B --noinform
239 Suppress the printing of any banner or other informational message at
240 startup. (This makes it easier to write Lisp programs which work in
241 Unix pipelines. See also the "--noprogrammer" and "--noprint" options.)
242 .PP
243
244 In the future, runtime options may be added to control behavior such
245 as lazy allocation of memory.
246
247 Runtime options, including any --end-runtime-options option,
248 are stripped out of the command line before the
249 Lisp toplevel logic gets a chance to see it.
250
251 Supported toplevel options for the standard SBCL core are
252 .TP 3
253 .B --sysinit <filename>
254 Load filename instead of the default system-wide initialization file.
255 (See the FILES section.) There is no special option to cause no
256 system-wide initialization file to be read, but on a Unix system
257 "--sysinit /dev/null" can be used to achieve the same effect.
258 .TP 3
259 .B --userinit <filename>
260 Load filename instead of the default user initialization file. (See
261 the FILES section.) There is no special option to cause no user
262 initialization file to be read, but on a Unix system "--userinit
263 /dev/null" can be used to achieve the same effect.
264 .TP 3
265 .B --eval <command>
266 After executing any initialization file, but before starting the
267 read-eval-print loop on standard input, evaluate the command given.
268 More than one --eval option can be used, and all will be executed, in
269 the order they appear on the command line.
270 .TP 3
271 .B --noprint
272 When ordinarily the toplevel "read-eval-print loop" would be executed,
273 execute a "read-eval loop" instead, i.e. don't print a prompt and
274 don't echo results. Combined with the --noinform runtime option, this
275 makes it easier to write Lisp "scripts" which work in Unix pipelines.
276 .TP 3
277 .B --noprogrammer
278 By default, a Common Lisp system tries to ask the programmer for help
279 when it gets in trouble (by printing a debug prompt on *DEBUG-IO*).
280 However, this is not useful behavior for a system running with no
281 programmer available, and this option tries to set up more appropriate
282 behavior for that situation. Thus we set *DEBUG-IO* to send its
283 output to *ERROR-OUTPUT*, and to raise an error if any input is
284 requested from it; and we set *DEBUGGER-HOOK* to output a backtrace,
285 then exit the process with a failure code.
286 .PP
287
288 Regardless of the order in which --sysinit, --userinit, and --eval
289 options appear on the command line, the sysinit file, if it exists, is
290 loaded first; then the userinit file, if it exists, is loaded; then
291 any --eval commands are executed in sequence; then the read-eval-print
292 loop is started on standard input. At any step, error conditions or
293 commands such as SB-EXT:QUIT can cause execution to be terminated
294 before proceeding to subsequent steps.
295
296 Note that when running SBCL with the --core option, using a core file
297 created by a user call to the SB-EXT:SAVE-LISP-AND-DIE, the toplevel
298 options may be under the control of user code passed as arguments to
299 SB-EXT:SAVE-LISP-AND-DIE. For this purpose, the --end-toplevel-options
300 option itself can be considered a toplevel option, i.e. the user core,
301 at its option, may not support it.
302
303 In the standard SBCL startup sequence (i.e. with no user core
304 involved) toplevel options and any --end-toplevel-options option are
305 stripped out of the command line argument list before user code gets a
306 chance to see it.
307
308 .SH SYSTEM REQUIREMENTS
309
310 Unlike its distinguished ancestor CMU CL, SBCL currently runs only on X86
311 (Linux, FreeBSD, and OpenBSD) and Alpha (Linux). For information on 
312 other ongoing ports, see the sbcl-devel mailing list, and/or the
313 web site.
314
315 SBCL requires on the order of 16Mb RAM to run on X86 systems. 
316
317 .SH ENVIRONMENT
318
319 .TP 10n
320 .BR SBCL_HOME
321 If this variable is set, it overrides the default directories for
322 files like "sbclrc" and "sbcl.core", so that instead of being searched
323 for in e.g. /etc/, /usr/local/etc/, /usr/lib/, and /usr/local/lib/, they
324 are searched for only in the directory named by SBCL_HOME. This is
325 intended to support users who wish to use their own version of SBCL
326 instead of the version which is currently installed as the system
327 default.
328 .PP
329
330 .SH FILES
331
332 /usr/lib/sbcl.core and /usr/local/lib/sbcl.core are the standard
333 locations for the standard SBCL core, unless overridden by the SBCL_HOME
334 variable.
335
336 /etc/sbclrc and /usr/local/etc/sbclrc are the standard locations for
337 system-wide SBCL initialization files, unless overridden by the
338 SBCL_HOME variable or the --sysinit command line option.
339
340 $HOME/.sbclrc is the standard location for a user's SBCL
341 initialization file, unless overridden by the --userinit
342 command line option.
343
344 .SH KNOWN BUGS
345
346 This section attempts to list the most serious and long-standing bugs.
347 For more detailed and current information on bugs, see the BUGS file
348 in the distribution.
349
350 It is possible to get in deep trouble by exhausting
351 memory. To plagiarize a sadly apt description of a language not
352 renowned for the production of bulletproof software, "[The current
353 SBCL implementation of] Common Lisp makes it harder for you to shoot
354 yourself in the foot, but when you do, the entire universe explodes."
355 .TP 3
356 \--
357 The system doesn't deal well with stack overflow. (It tends to cause
358 a segmentation fault instead of being caught cleanly.)
359 .TP 3
360 \--
361 Like CMU CL, the SBCL system overcommits memory at startup. On typical
362 Unix-alikes like Linux and FreeBSD, this means that if the SBCL system
363 turns out to use more virtual memory than the system has available for
364 it, other processes tend to be killed randomly (!).
365 .PP
366
367 The compiler's handling of function return values unnecessarily
368 violates the "declarations are assertions" principle that it otherwise
369 adheres to. Using PROCLAIM or DECLAIM to specify the return type of a
370 function causes the compiler to believe you without checking. Thus
371 compiling a file containing
372 (DECLAIM (FTYPE (FUNCTION (T) NULL) SOMETIMES))
373 (DEFUN SOMETIMES (X) (ODDP X))
374 (DEFUN FOO (X) (IF (SOMETIMES X) 'THIS-TIME 'NOT-THIS-TIME))
375 then running (FOO 1) gives NOT-THIS-TIME, because the
376 never compiled code to check the declaration.
377
378 Some things are implemented very inefficiently.
379 .TP 3
380 \--
381 Multidimensional arrays are inefficient, especially
382 multidimensional arrays of floating point numbers
383 .TP 3
384 \--
385 The DYNAMIC-EXTENT declaration isn't implemented at all, not even
386 for &REST lists or upward closures, so such constructs always allocate
387 their temporary storage from the heap, causing GC overhead.
388 .TP 3
389 \--
390 CLOS isn't particularly efficient. (In part, CLOS is so dynamic
391 that it's slow for fundamental reasons, but beyond that, the
392 SBCL implementation of CLOS doesn't do some important known
393 optimizations.)
394 .TP 3
395 \--
396 SBCL, like most implementations of Common Lisp, has trouble
397 passing floating point numbers around efficiently, because
398 they're larger than a machine word. (Thus, they get "boxed" in
399 heap-allocated storage, causing GC overhead.) Within
400 a single compilation unit,
401 or when doing built-in operations like SQRT and AREF,
402 or some special operations like structure slot accesses,
403 this is avoidable: see the user manual for some
404 efficiency hints. But for general function calls across
405 the boundaries of compilation units, passing a floating point
406 number as a function argument (or returning a floating point
407 number as a function value) is a fundamentally slow operation.
408 .PP
409
410 There are still some nagging pre-ANSIisms, notably
411 .TP 3
412 \--
413 CLOS (based on the PCL reference implementation) is incompletely
414 integrated into the system, so that e.g. SB-PCL::FIND-CLASS is a
415 different function than CL::FIND-CLASS. (In practice, you need to
416 be a pretty advanced user before this is a serious problem, and
417 by then you can usually work around it, but it's still distasteful.
418 It's arguably the outstanding "This should be fixed by version 1.0"
419 issue.)
420 .TP 3
421 --
422 The ANSI-recommended idiom for creating a function which is only
423 sometimes expanded inline,
424 (DECLAIM (INLINE F))
425 (DEFUN F ...)
426 (DECLAIM (NOTINLINE F)),
427 doesn't do what you'd expect. (Instead, you have to declare the
428 function as SB-EXT:MAYBE-INLINE to get the desired effect.)
429 .TP 3
430 \--
431 There are several nonconforming bits of type syntax. E.g. (1) The type
432 FOO is strictly equivalent to (FOO), so e.g. the type OR is treated as
433 the type (OR), i.e. the empty type. This is the way that the ancestral
434 code worked, and even though ANSI specifically forbids it, it hasn't
435 been fixed yet. (2) The symbol * is the name of a type similar to T.
436 (It's used as part of the implementation of compound types like (ARRAY
437 * 1) and (CONS * *). In a strict ANSI implementation, * would not be
438 the name of a type, but instead just a symbol which is recognized and
439 handled specially by certain type expanders.)
440 .PP
441
442 .SH REPORTING BUGS
443
444 To report a bug, please send mail to sbcl-help@lists.sourceforge.net
445 or sbcl-devel@lists.sourceforge.net.
446
447 As with any software bug report, it's most helpful if you can provide
448 enough information to reproduce the symptoms reliably, and if you say
449 clearly what the symptoms are. E.g. "There seems to be something wrong
450 with TAN of very small negative arguments. When I execute
451 (TAN LEAST-NEGATIVE-SINGLE-FLOAT) interactively on sbcl-1.2.3 on my Linux
452 4.5 X86 box, I get an UNBOUND-VARIABLE error."
453
454 .SH SUPPORT
455
456 Various information about SBCL is available at
457 <http://sbcl.sourceforge.net/>. The mailing lists there are the
458 recommended place to look for support.
459
460 .SH AUTHORS
461
462 Dozens of people have made substantial contributions to SBCL and its
463 subsystems, and to the CMU CL system on which it was based, over the
464 years. See the CREDITS file in the distribution.