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