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