Implementation Notes for GNU CLISP

These notes document CLISP version 2.46

Bruno Haible

Michael Stoll

Sam Steingold

See COPYRIGHT for the list of other contributors and the license.

Legal Status of the CLISP Implementation Notes

These notes are dually licensed under GNU GFDL and GNU GPL. This means that you can redistribute this document under either of these two licenses, at your choice.

These notes are covered by the GNU GFDLPermission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License (GFDL), either version 1.2 of the License, or (at your option) any later version published by the Free Software Foundation (FSF); with no Invariant Sections, with no Front-Cover Text, and with no Back-Cover Texts. A copy of the license is included in Appendix B, GNU Free Documentation License.

These notes are covered by the GNU GPLThis document documents free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (GPL), either version 2 of the License, or (at your option) any later version published by the Free Software Foundation (FSF). A copy of the license is included in Appendix C, GNU General Public License.

CLISP Release History
Release 1April 1987 - July 1992bruno
  • The project was started when both original authors, bruno and Michael Stoll, were students in Germany.
  • The original version was for Atari ST only, written in 68000 assembly language and Common Lisp.
Release 2.01992-10-09bruno
  • comp.os.linux announcement (Linux binaries only)
Release 2.11993-01-01bruno
  • The first portable release, with source, released under GNU GPL.
  • Supported platforms: Atari ST, Amiga 500-2000, DOS (emx, djgpp), OS/2 (emx), Unix (Linux, Sun4, Sun386, HP9000/800).
Release 2.1.11993-01-11bruno
Release 2.1.21993-02-01bruno
Release 2.1.31993-02-03bruno
Release 2.21993-02-21bruno
  • Add test suite.
Release 2.2.11993-03-04bruno
Release 2.2.21993-03-19bruno
Release 2.31993-03-30bruno
Release 2.3.11993-04-05bruno
Release 2.41993-05-24bruno
Release 2.51993-06-29bruno
Release 2.5.11993-07-17bruno
  • immutable objects
Release 2.61993-08-22bruno
Release 2.6.11993-09-01bruno
Release 2.71993-09-27bruno
Release 2.81993-11-08bruno
Release 2.91994-01-08bruno
Release 2.101994-06-22bruno
Release 2.111994-07-04bruno
Release 2.121994-08-23bruno
Release 2.12.11994-09-01bruno
Release 2.131994-10-26bruno
Release 2.13.11995-01-01bruno
Release 2.141995-04-04bruno
Release 2.151995-04-25bruno
Release 2.161995-06-23bruno
Release 2.171996-07-21bruno
Release 2.171996-07-22bruno
Release 2.181997-05-03bruno
Release 2.191997-08-07bruno
Release 2.201997-09-25bruno
Release 2.20.11997-12-06bruno
Release 2.211998-09-09bruno
Release 2.221999-01-08bruno
Release 2.231999-07-22bruno
Release 2.242000-03-06bruno
Release 2.252001-03-15sds
Release 2.25.12001-04-06sds
Release 2.262001-05-23sds
Release 2.272001-07-17sds
Release 2.282002-03-03sds
Release 2.292002-07-25bruno
  • Bug-fix/portability: gcc 3.1 etc
Release 2.302002-09-15sds
Release 2.312003-09-01sds
Release 2.322003-12-29sds
Release 2.332004-03-17sds
Release 2.33.12004-05-22sds
  • Bug-fixes, portability: gcc 3.4
Release 2.33.22004-06-02sds
  • Portability: RedHat Fedora Linux/x86
Release 2.342005-07-20sds
Release 2.352005-08-29sds
Release 2.362005-12-04sds
Release 2.372006-01-02sds
Release 2.382006-01-24sds
Release 2.392006-07-16sds
  • Reliable stack overflow detection and recovery.
Release 2.402006-09-23sds
Release 2.412006-10-13sds
Release 2.422007-10-16sds
Release 2.432007-11-18sds
Release 2.43.12008-02-24bruno
Release 2.442008-02-02sds

Do not bundle GNU libffcall.

Release 2.44.12008-02-24bruno
Release 2.452008-05-15sds

Abstract

This document describes the GNU CLISP - an implementation of the [ANSI CL standard].

See the section called “Bugs” for instructions on how to report bugs (both in these notes and in CLISP itself).

See Q: A.1.1.5 for information on CLISP support.


Table of Contents

Overview
Conventions
I. Chapters or the Common Lisp HyperSpec
1. Introduction
1.1. Special Symbols
1.2. Error Terminology
1.3. Symbols in the Package COMMON-LISP
2. Syntax
2.1. Standard Characters
2.2. Reader Algorithm
2.3. Symbols as Tokens
2.4. Valid Patterns for Tokens
2.5. Backquote
2.6. Sharpsign
3. Evaluation and Compilation
3.1. Evaluation
3.2. Compilation
3.3. Declarations
3.4. Lambda Lists
4. Types and Classes
4.1. Types
4.2. Classes
4.3. Deviations from ANSI CL standard
4.4. Standard Metaclasses
4.5. Defining Classes
4.6. Redefining Classes
5. Data and Control Flow
5.1. Generalized Reference
5.2. Setf Expansions
5.3. Kinds of Places
5.4. Miscellaneous
5.5. Macro DEFCONSTANT
5.6. Macro EXT:FCASE
5.7. Function EXT:XOR
5.8. Function EQ
5.9. Special Operator FUNCTION
6. Iteration
6.1. The LOOP Facility
6.2. Miscellaneous
7. Objects
7.1. Standard Method Combination
8. Structures
8.1. The options for DEFSTRUCT
8.2. The structure Meta-Object Protocol
9. Conditions
9.1. Embedded Newlines in Condition Reports
9.2. Interfaces to Restarts
10. Symbols
11. Packages
11.1. Introduction to Packages
11.2. Constraints on the COMMON-LISP Package for Conforming Programs - package locking
11.3. The COMMON-LISP-USER Package
11.4. Implementation-Defined Packages
11.5. Package Case-Sensitivity
12. Numbers
12.1. Numeric Types
12.2. Number Concepts
13. Characters
13.1. Introduction to Characters
13.2. Character sets
13.3. Character Scripts
13.4. Character Attributes
13.5. Graphic Characters
13.6. Alphabetic Characters
13.7. Characters With Case
13.8. Numeric Characters
13.9. Ordering of Characters
13.10. Treatment of Newline during Input and Output
13.11. Character Encodings
13.12. Documentation of Implementation-Defined Scripts
13.13. Platform-Dependent Characters
13.14. Obsolete Constants
14. Conses
14.1. Conses as Lists
15. Arrays
15.1. Array Elements
16. Strings
16.1. Miscellaneous
17. Sequences
17.1. Additional Macros
17.2. Functions NREVERSE & NRECONC
17.3. Functions REMOVE & DELETE
17.4. Functions SORT & STABLE-SORT
18. Hash Tables
18.1. Function MAKE-HASH-TABLE
18.2. Macro EXT:DEFINE-HASH-TABLE-TEST
18.3. Function HASH-TABLE-TEST
18.4. Macro EXT:DOHASH
19. Filenames
19.1. Pathname Components
19.2. :UNSPECIFIC as a Component Value
19.3. External notation
19.4. Logical Pathnames
19.5. Miscellaneous
20. Files
21. Streams
21.1. Interactive Streams
21.2. Terminal interaction
21.3. Binary Input and Output
21.4. Bulk Input and Output
21.5. Non-Blocking Input and Output
21.6. Newline Convention
21.7. Function STREAM-ELEMENT-TYPE
21.8. Function EXT:MAKE-STREAM
21.9. Function FILE-POSITION
21.10. Function EXT:ELASTIC-NEWLINE
21.11. Function OPEN
21.12. Function CLOSE
21.13. Function OPEN-STREAM-P
21.14. Class BROADCAST-STREAM
21.15. Functions EXT:MAKE-BUFFERED-INPUT-STREAM and EXT:MAKE-BUFFERED-OUTPUT-STREAM
22. Printer
22.1. Multiple Possible Textual Representations
22.2. Printing Floats
22.3. Printing Characters
22.4. Package Prefixes for Symbols
22.5. Printing Other Vectors
22.6. Printing Other Arrays
22.7. The Lisp Pretty Printer
22.8. Formatted Output
22.9. Functions WRITE & WRITE-TO-STRING
22.10. Macro PRINT-UNREADABLE-OBJECT
22.11. Miscellaneous Issues
23. Reader
23.1. Effect of Readtable Case on the Lisp Reader
23.2. The recursive-p argument
24. System Construction
24.1. Function COMPILE-FILE
24.2. Function COMPILE-FILE-PATHNAME
24.3. Function REQUIRE
24.4. Function LOAD
24.5. Variable *FEATURES*
24.6. Function EXT:FEATUREP [CLRFI-1]
24.7. Function EXT:COMPILED-FILE-P [CLRFI-2]
25. Environment
25.1. Top Level Loop
25.2. Debugging Utilities
25.3. Environment Inquiry
25.4. Time
26. Glossary
27. Appendix
28. X3J13 Issue Index [CLHS-ic]
II. Common Portable Extensions
29. Meta-Object Protocol
29.1. Introduction
29.2. Overview
29.3. Classes
29.4. Slot Definitions
29.5. Generic Functions
29.6. Methods
29.7. Accessor Methods
29.8. Specializers
29.9. Method Combinations
29.10. Slot Access
29.11. Dependent Maintenance
29.12. Deviations from AMOP
30. Gray streams
30.1. Overview
30.2. Defined classes
30.3. General generic functions
30.4. Generic functions for character input
30.5. Generic functions for character output
30.6. Generic functions for binary input
30.7. Generic functions for binary output
30.8. Class EXT:FILL-STREAM
III. Extensions Specific to CLISP
31. Platform Independent Extensions
31.1. Customizing CLISP Process Initialization and Termination
31.2. Saving an Image
31.3. Quitting CLISP
31.4. Internationalization of CLISP
31.5. Encodings
31.6. Generic streams
31.7. Weak Objects
31.8. Finalization
31.9. The Prompt
31.10. Maximum ANSI CL compliance
31.11. Additional Fancy Macros and Functions
31.12. Customizing CLISP behavior
31.13. Code Walker
32. Platform Specific Extensions
32.1. Random Screen Access
32.2. External Modules
32.3. The Foreign Function Call Facility
32.4. Socket Streams
32.5. Quickstarting delivery with CLISP
32.6. Shell, Pipes and Printing
32.7. Operating System Environment
33. Extensions Implemented as Modules
33.1. System Calls
33.2. Internationalization of User Programs
33.3. POSIX Regular Expressions
33.4. Advanced Readline and History Functionality
33.5. GDBM - The GNU database manager
33.6. Berkeley DB access
33.7. Directory Access
33.8. PostgreSQL Database Access
33.9. Oracle Interface
33.10. LibSVM Interface
33.11. Computer Algebra System PARI
33.12. Matlab Interface
33.13. Netica Interface
33.14. Perl Compatible Regular Expressions
33.15. The Wildcard Module
33.16. Interface to zlib
33.17. Raw Socket Access
33.18. The FastCGI Interface
33.19. GTK Interface
IV. Internals of the CLISP Implementation
34. The source files of CLISP
34.1. File Types
34.2. Source Pre-Processing
34.3. Files
35. Overview of CLISP's Garbage Collection
35.1. Introduction
35.2. Lisp objects in CLISP
35.3. Object Pointer Representations
35.4. Memory Models
35.5. The burden of garbage-collection upon the rest of CLISP
35.6. Foreign Pointers
36. Extending CLISP
36.1. Adding a built-in function
36.2. Adding a built-in variable
36.3. Recompilation
37. The CLISP bytecode specification
37.1. Introduction
37.2. The virtual machine
37.3. The structure of compiled functions
37.4. The general structure of the instructions
37.5. The instruction set
37.6. Examining compiled closures
37.7. Bytecode Design
V. Appendices
A. Frequently Asked Questions (With Answers) about CLISP
B. GNU Free Documentation License
C. GNU General Public License
C.1. Preamble
C.2. TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
C.3. How to Apply These Terms to Your New Programs
Index
References

List of Figures

29.1. Inheritance structure of metaobject classes
29.2. Inheritance structure of class metaobject classes
29.3. Inheritance structure of slot definition metaobject classes
29.4. Inheritance structure of generic function metaobject classes
29.5. Inheritance structure of method metaobject classes
29.6. Inheritance structure of specializer metaobject classes
29.7. Inheritance structure of method combination metaobject classes

List of Tables

1. Mark-up conventions
3.1. Function call limits
12.1. Boolean operations
12.2. Fixnum limits
13.1. Number of characters
13.2. Standard characters
13.3. Semi-standard characters
13.4. Additional Named Characters
13.5. Additional syntax for characters with code from #x00 to #x1F:
13.6. Additional characters (Win32 platform only.)
13.7. Additional characters (UNIX platform only.)
13.8. Character bit constants (obsolete)
15.1. Array limits
19.1. The minimum filename syntax that may be used portably
25.1. Commands common to the main loop, the debugger and the stepper
25.2. Commands common to the debugger and the stepper
25.3. Commands common to the debugger and the stepper
25.4. Commands specific to EVAL/APPLY
25.5. Commands specific to the debugger
25.6. Commands specific to the stepper
25.7. Time granularity
29.1. Direct Superclass Relationships Among The Specified Metaobject Classes
29.2. Initialization arguments and accessors for class metaobjects
29.3. Initialization arguments and accessors for slot definition metaobjects
29.4. Initialization arguments and accessors for generic function metaobjects
29.5. Initialization arguments and accessors for method metaobjects
29.6. The correspondence between slot access function and underlying slot access generic function
35.1. Memory models with TYPECODES
35.2. Memory models with HEAPCODES

List of Examples

25.1. Identifying Individual Calls in TRACE
30.1. Example of EXT:FILL-STREAM usage
32.1. Create a module set with GNU libc bindings
32.2. Simple declarations and access
32.3. External C variable and some accesses
32.4. Calling an external function
32.5. Another example for calling an external function
32.6. Accessing cpp macros
32.7. Calling Lisp from C
32.8. Calling Lisp from C dynamically
32.9. Variable size arguments: calling gethostname from CLISP
32.10. Accessing variables in shared libraries
32.11. Controlling validity of resources
32.12. Float point array computations
32.13. Lisp read-eval-print loop server
32.14. Lisp HTTP client
33.1. REGEXP:MATCH
33.2. REGEXP:REGEXP-QUOTE
33.3. Count unix shell users

Overview

These notes discuss the CLISP implementation of Common Lisp by Bruno Haible and Michael Stoll. The current maintainers are Bruno Haible and Sam Steingold.

This implementation is mostly conforming to the [ANSI CL standard] available on-line as the [Common Lisp HyperSpec] (but the printed ANSI document remains the authoritative source of information). [ANSI CL standard] supersedes the earlier specifications [CLtL1] and [CLtL2].

The first part of these notes, Part I, “Chapters or the Common Lisp HyperSpec”, is indexed in parallel to the [Common Lisp HyperSpec] and documents how CLISP implements the [ANSI CL standard].

The second part, Part II, “Common Portable Extensions”, documents the common extensions to the [ANSI CL standard], specifically Meta-Object Protocol and GRAY STREAMs.

The third part, Part III, “Extensions Specific to CLISP, documents the CLISP-specific extensions, e.g., Section 32.4, “Socket Streams”.

The fourth part, Part IV, “Internals of the CLISP Implementation”, is intended mostly for developers as it documents the CLISP internals, e.g., garbage-collection, adding new built-ins, and the bytecodes generated by the compiler (i.e., what is printed by DISASSEMBLE).

Conventions

The following is the mark-up notations used in this document:

Table 1. Mark-up conventions

Object KindExample
FunctionCAR
VariableCUSTOM:*LOAD-PATHS*
Formal Argumentx
Keyword:EOF
Number0
Character#\Newline
Class, typeREGEXP:MATCH
Format instruction~A
Standard lambda list keyword&KEY
DeclarationFTYPE
PackageCOMMON-LISP-USER
Real fileconfig.lisp
Abstract file#P".c"
Code (you are likely to type it)(CONS 1 2)
Data (CLISP is likely to print it)#(1 2 3)
Program listing
(defun cycle-length (n &OPTIONAL (len 1) (top 0))
  (cond ((= n 1) (values len top))
        ((evenp n) (cycle-length (ash n -1) (1+ len) (max top n)))
        (t (let ((next (1+ (* 3 n))))
             (cycle-length next (1+ len) (max top next))))))
    
Bytecode instruction(STOREV k m)
First mention of an entityfirstterm
External modulelibsvm, bindings/glibc
Command line argument-x


Part I. Chapters or the [Common Lisp HyperSpec]

Table of Contents

1. Introduction
1.1. Special Symbols
1.2. Error Terminology
1.3. Symbols in the Package COMMON-LISP
2. Syntax
2.1. Standard Characters
2.2. Reader Algorithm
2.3. Symbols as Tokens
2.4. Valid Patterns for Tokens
2.5. Backquote
2.6. Sharpsign
2.6.1. Sharpsign Backslash
2.6.2. Sharpsign Less-Than-Sign
3. Evaluation and Compilation
3.1. Evaluation
3.1.1. Introduction to Environments
3.1.2. Symbols as Forms
3.1.3. Conses as Forms
3.1.4. Special Forms
3.1.5. Function Forms
3.1.6. Macros DEFUN & DEFMACRO
3.2. Compilation
3.2.1. Compiler Terminology
3.2.2. Compilation Semantics
3.2.3. Definition of Similarity
3.3. Declarations
3.3.1. Declaration SPECIAL
3.3.2. Declaration EXT:CONSTANT-NOTINLINE
3.3.3. Function CONSTANTP
3.3.4. Declaration SAFETY
3.3.5. Declaration (COMPILE)
3.3.6. Declaration SPACE
3.4. Lambda Lists
3.4.1. Boa Lambda Lists
4. Types and Classes
4.1. Types
4.1.1. Type Specifiers
4.2. Classes
4.3. Deviations from ANSI CL standard
4.4. Standard Metaclasses
4.5. Defining Classes
4.6. Redefining Classes
5. Data and Control Flow
5.1. Generalized Reference
5.2. Setf Expansions
5.3. Kinds of Places
5.4. Miscellaneous
5.5. Macro DEFCONSTANT
5.5.1. Variable CUSTOM:*SUPPRESS-SIMILAR-CONSTANT-REDEFINITION-WARNING*
5.6. Macro EXT:FCASE
5.7. Function EXT:XOR
5.8. Function EQ
5.9. Special Operator FUNCTION
6. Iteration
6.1. The LOOP Facility
6.1.1. Iteration variables in the loop epilogue
6.1.2. Backward Compatibility
6.2. Miscellaneous
7. Objects
7.1. Standard Method Combination
8. Structures
8.1. The options for DEFSTRUCT
8.1.1. The :PRINT-FUNCTION option
8.1.2. The :INHERIT option
8.2. The structure Meta-Object Protocol
9. Conditions
9.1. Embedded Newlines in Condition Reports
9.2. Interfaces to Restarts
10. Symbols
11. Packages
11.1. Introduction to Packages
11.1.1. Function MAKE-PACKAGE
11.1.2. Macro DEFPACKAGE
11.1.3. Function EXT:RE-EXPORT
11.1.4. Function EXT:PACKAGE-CASE-INVERTED-P
11.1.5. Function EXT:PACKAGE-CASE-SENSITIVE-P
11.2. Constraints on the COMMON-LISP Package for Conforming Programs - package locking
11.3. The COMMON-LISP-USER Package
11.4. Implementation-Defined Packages
11.5. Package Case-Sensitivity
11.5.1. User Package for the Case-sensitive World
11.5.2. Package Names
11.5.3. Gensyms and Keywords
11.5.4. Migration Tips
11.5.5. Using case-sensitive packages by default
12. Numbers
12.1. Numeric Types
12.2. Number Concepts
12.2.1. Numeric Operations
12.2.2. Implementation-Dependent Numeric Constants
12.2.3. Rule of Float Substitutability
12.2.4. Floating-point Computations
12.2.5. Complex Computations
12.2.6. Rule of Canonical Representation for Complex Rationals
12.2.7. Random-State Operations
13. Characters
13.1. Introduction to Characters
13.1.1. Function CHAR-CODE
13.1.2. Type BASE-CHAR
13.1.3. Function EXT:CHAR-WIDTH
13.2. Character sets
13.3. Character Scripts
13.4. Character Attributes
13.4.1. Input Characters
13.5. Graphic Characters
13.6. Alphabetic Characters
13.7. Characters With Case
13.7.1. Function EXT:CHAR-INVERTCASE
13.7.2. Case of Implementation-Defined Characters
13.8. Numeric Characters
13.9. Ordering of Characters
13.10. Treatment of Newline during Input and Output
13.11. Character Encodings
13.12. Documentation of Implementation-Defined Scripts
13.13. Platform-Dependent Characters
13.14. Obsolete Constants
14. Conses
14.1. Conses as Lists
14.1.1. Mapping Functions
15. Arrays
15.1. Array Elements
16. Strings
16.1. Miscellaneous
16.1.1. String Comparison
16.1.2. Function EXT:STRING-WIDTH
16.1.3. Functions EXT:STRING-INVERTCASE and EXT:NSTRING-INVERTCASE
17. Sequences
17.1. Additional Macros
17.1.1. Macro EXT:DOSEQ
17.2. Functions NREVERSE & NRECONC
17.3. Functions REMOVE & DELETE
17.4. Functions SORT & STABLE-SORT
18. Hash Tables
18.1. Function MAKE-HASH-TABLE
18.1.1. Interaction between HASH-TABLEs and garbage-collection
18.2. Macro EXT:DEFINE-HASH-TABLE-TEST
18.3. Function HASH-TABLE-TEST
18.4. Macro EXT:DOHASH
19. Filenames
19.1. Pathname Components
19.1.1. Directory canonicalization
19.1.2. Platform-specific issues
19.2. :UNSPECIFIC as a Component Value
19.3. External notation
19.4. Logical Pathnames
19.5. Miscellaneous
19.5.1. Function TRANSLATE-PATHNAME
19.5.2. Function TRANSLATE-LOGICAL-PATHNAME
19.5.3. Function PARSE-NAMESTRING
19.5.4. Function MERGE-PATHNAMES
19.5.5. Function LOAD-LOGICAL-PATHNAME-TRANSLATIONS
19.5.6. Function EXT:ABSOLUTE-PATHNAME
20. Files
21. Streams
21.1. Interactive Streams
21.2. Terminal interaction
21.2.1. Command line editing with GNU readline
21.2.2. Macro EXT:WITH-KEYBOARD