SubL is a computer language built by members of Cycorp. SubL was written to support the Cyc® application, allowing it to run both under Lisp environments and as a C application generated by a SubL-to-C translator. This document describes the primitive functions of SubL.
Due to the close similarities between SubL and Common Lisp, the Table of Contents and structure of this document intentionally mirror that of
"Common Lisp: The Language",making it easy to compare and contrast the two languages. For the most part, this document focuses only on the differences between SubL and Common Lisp.
2nd Edition,
Guy L. Steele Jr
An online version of "Common Lisp: The Language" can be found at
http://www.cs.cmu.edu/Groups/AI/html/cltl/clm/clm.html **not working**and an index to all Common Lisp functions can be found at
http://www.cs.cmu.edu/Groups/AI/html/cltl/clm/index.html **this is working**
Each section of this document contains a link labelled "CLtL2 Reference" to the corresponding sections of the above online Common Lisp reference. The reader is strongly encouraged to consult that reference in parallel with this document.
SubL is a programming language intended to be very similar to a simplified version of Common Lisp where those features that are either complex, rarely-used, or difficult to implement in a prodecural language have been excised.
Unlike Common Lisp, SubL is not a purely functional language. Several SubL constructs can only be used procedurally. In order to emphasize this difference, the following naming convention for SubL constructs is used:
A SubL function will have the same name as the analogous Common Lisp function if it is intended to have the exact same basic functionality. The argument list may be simplified, but the intent and use are likely to be the same.If there is a substantial behavioral difference between a SubL function and its Common Lisp counterpart, its name will be the Common Lisp name prepended with a single character -- either "c", "p" or "f".
"c" indicates a construct that is either only procedural or functional.
"p" indicates the procedural version of a Common Lisp construct.
"f" indicates the functional version of a Common Lisp construct.
A procedural construct in SubL is one which is suitable for evaluation
as either one form in an explicit PROGN
Here is a table of all the procedural constructs in SubL and the
Common Lisp analog:
A functional construct in SubL is one which returns a value. Here is
a table of all the functional constructs in SubL and the Common Lisp
analog:
The body of a function or macro definition is considered an implicit
progn, and so all forms in the body should be procedural. A function
call can be used as a procedural construct. In this case, the
returned value is simply ignored.
SubL has a flat type heirarchy. Each type is described in more detail
in the sections about the methods for that particular type.
SubL supports these built-in Common Lisp datatypes:
SubL does not support these Common Lisp datatypes:
SubL has only special-case support for these datatypes:
New data types can be introduced via DEFSTRUCT
Special variables in SubL are all (and only) those variables defined
globally with DEFVAR
Special variables have indefinite scope and dynamic extent. All other
variables have lexical scope and dynamic extent
Variables are introduced via:
When a local variable is introduced with the same name as a local
variable which is already within the current scope and extent, the new
variable shadows the outer variable.
The initialization of a local variable is considered to occur within
the scope of the new local variable. Consequently, a variable which
is shadowing an outer variable cannot be initialized in terms of the
outer value. For example, this is not allowed :
However, if the variable is a special variable, the CLET
The construct RET
SubL does not support type specifiers.
Program structure in SubL mirrors that of Common Lisp almost exactly.
All objects except lists and symbols are self-evaluating. This
includes numbers, characters, strings, vectors and hashtables. In
addition :
All functions in SubL must be named and therefore defined via the SubL
construct DEFINE
Argument lists for user-defined function can only be of this form:
In short, SubL supports &optional arguments for user-defined
functions but does not support &keyword, &aux
or &rest arguments for user-defined functions.
DEFVAR
SubL enforces an important distinction between these two constructs,
which is described in greater detail under WRITE-IMAGE
As with DEFVAR
The symbols NIL and T are used to represent the logical values "true"
and "false" in SubL and behave exactly as they do in Common Lisp.
For the most part, the following predicates which check for specific
data types behave exactly as they do in Common Lisp.
In SubL, FUNCTIONP
The SubL equality predicates behave exactly like their Common Lisp
counterparts.
SubL logical operations only return T or NIL. Otherwise, they
behave like their Common Lisp counterparts.
These SubL constructs behave exactly like their Common Lisp
counterparts.
Since CSETQ
These SubL functions for setting and unsetting symbol properties behave
like their Common Lisp counterparts.
CSETF
In the above table, defstruct-slot refers to any structure slot
accessor function which got defined via defstruct, and
set-defstruct-slot refers to the corresponding setter function
for the given accessor.
These functions behave like their Common Lisp counterparts.
The first argument to both APPLY
In SubL, PROGN
The SubL construct CLET
SubL has no counterpart to Common Lisp's LET construct.
CPROGV
PIF
FIF
PCOND
RET
In SubL, multiple values are governed the same way that they are in Common Lisp,
except that if ANY of the return statements in your
function are (values ...) then all of them must be.
SubL Macros are expanded at translation-time. Full Common Lisp macro
support is available. However, the macro-expander must use
RET
The IGNORE
SubL only supports fixnums and floats. Fixnums have at least 28 bits
of precision.
The above numeric comparison functions take exactly 2 arguments,
unlike their Common Lisp counterparts which take variable numbers of
arguments.
SubL does not currently support any irrational, transcendental or
trigonometric functions.
SubL does not currently support any logical operations on numbers.
SubL does not currently support any attributes for characters. A
character exists for each ASCII character code between 0 and 255
inclusive. Thus, the SubL equivalent of Common Lisp's
CHAR-CODE-LIMIT is 256.
SubL Procedural Construct
Common Lisp Equivalent
PROGN
progn
PIF
if
PWHEN
when
PUNLESS
unless
PCOND
cond
PCASE
case
CSETQ
setq
CSETF
setf
CINC
incf
CDEC
decf
CPUSH
push
CPUSHNEW
pushnew
CPOP
pop
CLET
let*
CMULTIPLE-VALUE-BIND
multiple-value-bind
CDO
do*
CDOLIST
dolist
CSOME
CDOTIMES
dotimes
CDOHASH
CCATCH
catch
CUNWIND-PROTECT
unwind-protect
RET
return-from
SubL Functional Construct
Common Lisp Equvalent
CAND
and
COR
or
CNOT
not
FIF
if
FWHEN
when
FUNLESS
unless
2 : Data Types
CLtL2 Reference
Numbers: fixnum float Symbols: symbol Lists: cons Arrays: vector Characters: character Strings: string Hashtables: eq hashtable eql hashtable equal hashtable equalp hashtable Streams: stream Functions: function
Multi-dimensional arrays
Packages
Pathnames
Random-states
Lambda-Expressions or Closures
Readtables: SubL only supports a single internal readtable
3 : Scope and Extent
CLtL2 Reference
(define foo (x)
(clet ((x (+ x 1)))
(print x))
(ret nil))
(defvar *some-var* 1)
(define foo (x)
(clet ((*some-var* (+ *some-var* x)))
(print *some-var*))
(ret nil))
4 : Type Specifiers
CLtL2 Reference
5 : Program Structure
CLtL2 Reference
5.3.1 : Defining Named Functions
CLtL2 Reference
macro DEFINE : (name arglist &body body)
( {var}* [&optional {var | ( var [initform [supplied-var]] ) }*] )
5.3.2 : Declaring Global Variables and Named Constants
CLtL2 Reference
macro DEFVAR : (variable &optional initialization documentation)
macro DEFPARAMETER : (variable initialization &optional documentation)
macro DEFCONSTANT : (variable initialization &optional documentation)
6 : Predicates
CLtL2 Reference
6.1 : Logical Values
CLtL2 Reference
6.2.2 : Specific Data Type Predicates
CLtL2 Reference
function NULL : (x)
function SYMBOLP : (x)
function ATOM : (x)
function CONSP : (x)
function LISTP : (x)
function NUMBERP : (x)
function INTEGERP : (x)
function FLOATP : (x)
function CHARACTERP : (x)
function STRINGP : (x)
function VECTORP : (x)
function FUNCTIONP : (x)
Follows the CLtL2 implementation
function FUNCTION-SPEC-P : (x)
Returns T IFF x is an object suitable for FUNCALL6.3 : Equality Predicates
CLtL2 Reference
function EQ : (x y)
function EQL : (x y)
function EQUAL : (x y)
function EQUALP : (x y)6.4 : Logical Operators
CLtL2 Reference
macro CNOT : (x)
macro CAND : (&rest args)
macro COR : (&rest args)
7 : Control Structure
CLtL2 Reference
7.1.1 : Reference
CLtL2 Reference
function QUOTE : (data)
macro FUNCTION : (fspec)
function SYMBOL-VALUE : (x)
function SYMBOL-FUNCTION : (x)
function BOUNDP : (x)
function FBOUNDP : (x)7.1.2 : Assignment
CLtL2 Reference
macro CSETQ : (var value &rest var-val-pairs)
function SET : (symbol value)
function MAKUNBOUND : (symbol)
function FMAKUNBOUND : (symbol)7.2 : Generalized Variables
CLtL2 Reference
macro CSETF : (place val)
CSETF form
Equivalent SubL expansion
(CSETF
(CSETQ
(CSETF
(SET-AREF
(CSETF
(SET-NTH
(CSETF
(RPLACA
(CSETF
(RPLACD
(CSETF
(PUT
(CSETF
(SETHASH
(CSETF
(SET
(CSETF
(set-defstruct-slot object value)
7.3 : Function Invocation
CLtL2 Reference
function APPLY : (function argument &rest arguments)
function FUNCALL : (function &rest args)7.4 : Simple Sequencing
CLtL2 Reference
macro PROGN : (&body body)7.5 : Establishing New Variable Bindings
CLtL2 Reference
macro CLET : (bindings &body body)
macro CPROGV : (special-vars bindings &body body)7.6 : Conditionals
CLtL2 Reference
macro PIF : (condition action else-action)
macro PWHEN : (condition &body body)
macro PUNLESS : (condition &body body)
macro FIF : (condition true-value false-value)
macro FWHEN : (condition true-value)
macro FUNLESS : (condition false-value)
macro PCOND : (&rest clauses)
macro PCASE : (test-object &body clauses)7.7 : Blocks and Exits
CLtL2 Reference
macro RET : (expression)
SubL functions must always return a value, since C functions must return values and all SubL functions must translate into C.
appears at the very end of each function.
(ret nil)
7.8.2 : General Iteration
CLtL2 Reference
macro CDO : (vars endtest &body body)
cdo is procedural. It binds its variables in sequence, as with CommonLisp do*7.8.3 : Simple Iteration Constructs
CLtL2 Reference
macro CDOLIST : ((var listform) &body body)
macro CSOME : ((var list endvar) &body body)
macro CDOTIMES : ((var integer) &body body)
macro CDOHASH : ((key val table) &body body)7.8.4 : Mapping
CLtL2 Reference
function MAPCAR : (function list &rest more-lists)
function MAPLIST : (function list &rest more-lists)
function MAPC : (function list &rest more-lists)
function MAPL : (function list &rest more-lists)
function MAPCAN : (function list &rest more-lists)
function MAPCON : (function list &rest more-lists)7.10.1 : Constructs for Handling Multiple Values
CLtL2 Reference
function VALUES : (value &rest more-values)
values returns its args such that they can be bound in a dynamically enclosing multiple-value-bind. The first value is returned as well, since all SubL functions must return a value.
variable *MULTIPLE-VALUES-LIMIT*
macro MULTIPLE-VALUE-LIST : (form)
macro CMULTIPLE-VALUE-BIND : (vars value &body body)7.10.2 : Rules Governing the Passing of Multiple Values
CLtL2 Reference
7.11 : Dynamic Non-Local Exits
CLtL2 Reference
macro CCATCH : (tag ans-var &body body)
ccatch is procedural, and so does not return values.
macro CUNWIND-PROTECT : (protected-form &body body)
function THROW : (tag result)
8 : Macros
CLtL2 Reference
8.1 : Macro Definition
CLtL2 Reference
macro DEFMACRO : (name pattern &body body)8.3 : Destructuring
CLtL2 Reference
macro CDESTRUCTURING-BIND : (pattern datum &body body)8.5 : Environments
CLtL2 Reference
function VARIABLE-INFORMATION : (variable)
function FUNCTION-INFORMATION : (function)
9 : Declarations
CLtL2 Reference
9.1 : Declaration Syntax
CLtL2 Reference
function DECLARE : (&rest ignore)
function PROCLAIM : (declaration-specifier)
macro DECLAIM : (&rest declaration-specifiers)9.2 : Declaration Specifiers
CLtL2 Reference
function IGNORE : (&rest values)
10 : Symbols
CLtL2 Reference
function SYMBOLP : (x)10.1 : The Property List
CLtL2 Reference
function GET : (symbol indicator &optional default)
function PUT : (symbol indicator new-value)
function REMPROP : (symbol indicator)
function SYMBOL-PLIST : (symbol)10.2 : The Print Name
CLtL2 Reference
function SYMBOL-NAME : (symbol)
Returns the string which is the name of SYMBOL. When called on a keyword, it returns the ":" prefix as part of the name10.3 : Creating Symbols
CLtL2 Reference
function MAKE-SYMBOL : (print-name)
function GENSYM : (&optional x)
GENSYM returns new, interned symbols, which are combinations of a string prefix and a numeric suffix. It guarantees that the new symbol was not previously interned.
If the argument X is a number, the gensym counter (used to generate the suffix) is set to X before the new symbol is generated.
if the argument X is a string, the gensym prefix is set to X before the new symbol is generated.
The initial gensym counter value is 1 and the initial gensym prefix is 'G'.
function GENTEMP : (&optional (prefix "T"))
function KEYWORDP : (x)
In SubL, which does not have packages, keywords are any symbol whose name begins with ":"
11 : Packages
CLtL2 Reference
macro IN-PACKAGE : (name)
function INTERN : (string)
Finds and returns a symbol whose name is STRING. INTERN will create the symbol if it does not exist. Unlike Common LISP intern, the SubL version does not allow an argument to specify the package, since SubL does not support packages.
function FIND-SYMBOL : (string)
Finds and returns a symbol whose name is STRING. Unlike Common LISP FIND-SYMBOL, the SubL version does not allow an argument to specify the package, since SubL does not support packages.
12 : Numbers
CLtL2 Reference
function NUMBERP : (x)
function FIXNUMP : (x)
function INTEGERP : (x)
function FLOATP : (x)12.2 : Predicates on Numbers
CLtL2 Reference
function ZEROP : (x)
function PLUSP : (x)
function MINUSP : (x)
function ODDP : (x)
function EVENP : (x)12.3 : Comparisons on Numbers
CLtL2 Reference
function = : (num1 num2)
function /= : (num1 num2)
function < : (num1 num2)
function > : (num1 num2)
function <= : (num1 num2)
function >= : (num1 num2)
function MAX : (num &rest numbers)
function MIN : (num &rest numbers)12.4 : Arithmetic Operations
CLtL2 Reference
function + : (&rest numbers)
function - : (num &rest numbers)
function * : (&rest numbers)
function / : (num &rest numbers)
function INT/ : (num1 num2)
macro CINC : (place &optional (delta 1))
macro CDEC : (place &optional (delta 1))12.5 : Irrational and Transcendental Functions
CLtL2 Reference
12.6 : Type Conversions and Component Extractions on Numbers
CLtL2 Reference
function FLOAT : (x)
function FLOOR : (x)
function CEILING : (x)
function TRUNCATE : (x)
function ROUND : (x)
function MOD : (number divisor)
function REM : (number divisor)
function SCALE-FLOAT : (float integer)
function INTEGER-DECODE-FLOAT : (float)12.7 : Logical Operations on Numbers
CLtL2 Reference
12.8 : Byte Manipulation Functions
CLtL2 Reference
macro BYTE : (size position)
function LDB : (bytespec integer)
function DPB : (newbyte bytespec integer)12.9 : Random Numbers
CLtL2 Reference
variable *RAND-MAX*
*rand-max* is the largest fixnum that the function random can accept.
function SEED-RANDOM : (&optional (seed-fixnum (mod (get-internal-real-time) *rand-max*)))
If seed-fixnum is omitted to seed-random, the internal clock is used
in an implementation specific manner.
function RANDOM : (number)12.10 : Implementation Parameters
CLtL2 Reference
variable *MOST-POSITIVE-FIXNUM*
variable *MOST-NEGATIVE-FIXNUM*
13 : Characters
CLtL2 Reference
function CHARACTERP : (x)13.1 : Character Attributes
CLtL2 Reference
13.2 : Predicates on Characters
CLtL2 Reference
function ALPHA-CHAR-P : (char)
function UPPER-CASE-P : (char)
function LOWER-CASE-P : (char)
function BOTH-CASE-P : (char)
function DIGIT-CHAR-P : (char)
function ALPHANUMERICP : (char)
function CHAR= : (char1 char2)
function CHAR/= : (char1 char2)
function CHAR< : (char1 char2)
function CHAR> : (char1 char2)
function CHAR<= : (char1 char2)
function CHAR>= : (char1 char2)
function CHAR-EQUAL : (char1 char2)
function CHAR-NOT-EQUAL : (char1 char2)
function CHAR-LESSP : (char1 char2)
function CHAR-GREATERP : (char1 char2)
function CHAR-NOT-GREATERP : (char1 char2)
function CHAR-NOT-LESSP : (char1 char2)13.3 : Character Construction and Selection
CLtL2 Reference
function CHAR-CODE : (char)
function CODE-CHAR : (code)13.4 : Character Conversions
CLtL2 Reference
function CHAR-DOWNCASE : (char)
function CHAR-UPCASE : (char)
14 : Sequences
CLtL2 Reference
function SEQUENCEP : (x)14.1 : Simple Sequence Functions
CLtL2 Reference
function ELT : (sequence index)
function SUBSEQ : (sequence start &optional end)
function COPY-SEQ : (sequence)
function LENGTH : (sequence)
function REVERSE : (sequence)
function NREVERSE : (sequence)14.2 : Concatenating, Mapping and Reducing Sequences
CLtL2 Reference
function CCONCATENATE : (seq &rest more-seqs)
function CREDUCE : (function sequence &optional (start 0) end (init-value :none))14.3 : Modifying Sequences
CLtL2 Reference
function FILL : (sequence item &optional (start 0) (end (length sequence)))
function REPLACE : (sequence1 sequence2 &optional (start1 0) end1 (start2 0) end2)
function REMOVE : (item sequence &optional (test #'eql) (key #'identity) (start 0) end count)
function REMOVE-IF : (test sequence &optional (key #'identity) (start 0) end count)
function DELETE : (item sequence &optional (test #'eql) (key #'identity) (start 0) end count)
function DELETE-IF : (test sequence &optional (key #'identity) (start 0) end count)
function REMOVE-DUPLICATES : (sequence &optional (test #'eql) (key #'identity) (start 0) end)
function DELETE-DUPLICATES : (sequence &optional (test #'eql) (key #'identity) (start 0) end)
function SUBSTITUTE : (new old sequence &optional (test #'eql) (key #'identity) (start 0) end count)
function SUBSTITUTE-IF : (new test sequence &optional (key #'identity) (start 0) end count)
function NSUBSTITUTE : (new old sequence &optional (test #'eql) (key #'identity) (start 0) end count)
function NSUBSTITUTE-IF : (new test sequence &optional (key #'identity) (start 0) end count)14.4 : Searching Sequences for Terms
CLtL2 Reference
function FIND : (item seq &optional (test #'eql) (key #'identity) (start 0) end)
function FIND-IF : (test seq &optional (key #'identity) (start 0) end)
function POSITION : (item seq &optional (test #'eql) (key #'identity) (start 0) end)
function POSITION-IF : (test seq &optional (key #'identity) (start 0) end)
function COUNT : (item seq &optional (test #'eql) (key #'identity) (start 0) end)
function COUNT-IF : (test seq &optional (key #'identity) (start 0) end)
function MISMATCH : (seq1 seq2 &optional (test #'eql) (key #'identity) (start1 0) end1 (start2 0) end2)
function