------------------------------------------------------------------------------
MC logo
Toms Lisp Functions
[^] Tom's Lisp
------------------------------------------------------------------------------
[Basic Input Format] [Lists, Pairs and Related Operations] [Conditional Evaluation] [Basic Function Definition] [Definitions and Scope] [Functions Which Take Functions] [String Functions] [Exception Handling] [Quoting And Evaluation] [Variable-Length Parameter Lists] [Macro Definitions] [Printing] [The Tomslsp command and its switches] [Index of Standard Functions]

This document contains a list of all the standard Tom's Lisp functions.

 
Integer Operations
Call Where Defined More Info Description
(+ i1 . . .) Builtin Basic Input Add integer values.
(- i1 i2) Builtin Basic Input Subtract integer values.
(* i1 . . .) Builtin Basic Input Multiply integer values.
(/ i1 i2) Builtin Basic Input Divide integer values. Integer result with no fractional part
(% i1 i2) Builtin Basic Input Modulus.
(< i1 i2) Builtin Conditionals Less than.
(> i1 i2) Builtin Conditionals Greater than.
(<= i1 i2) Builtin Conditionals Less than or equal.
(>= i1 i2) Builtin Conditionals Greater than or equal.
(= i1 i2) Builtin Conditionals Equal.
(!= i1 i2) Builtin Conditionals Not equal.
 
List Operations
Call Where Defined More Info Description
(car lis) Builtin Lists Return the first element of list (or pair) lis.
(cdr lis) Builtin Lists Return the remainder of the list lis after the first element. If lis is a pair, return the second part.
(cons x1 x2) Builtin Lists Combine x1 and x2 as a pair, or add x1 to the front of list x2.
(length lis) Init File Lists Return the length of list lis.
(first n lis) Init File Lists Return the first n items from lis.
(last n lis) Init File Lists Return the last n items from lis.
(first-but n lis) Init File Lists Return the list lis absent its last n elements.
(last-but n lis) Init File Lists Return the list lis absent its first n elements.
(nth n lis) Init File Lists Return the n-th element (zero-based) of list lis.
 
Type Identification
Call Where Defined More Info Description
(null? x) Builtin Conditionals Tell if the argument is nil (empty list).
(pair? x) Builtin Conditionals Tell if the argument is a pair (result of cons, most often a non-empty list.)
(id? x) Builtin Conditionals Tells if the argument is an identifier.
(int? x) Builtin Conditionals Tells if the argument is an integer.
(str? x) Builtin Conditionals Tells if the argument is a string.
(builtin? x) Builtin Conditionals Tells if the argument is a builtin function.
(lambda? x) Builtin Conditionals Tells if the argument is a function (result of the lambda operator
(macro? x) Builtin Conditionals Tells if the argument is a macro (result of the macro operator
(functional? x) Init File Conditionals Tells if the argument is something that can be called with a parameter list as a function is. These are any of the last three types.
 
Comparison and Boolean Operations
Call Where Defined More Info Description
(eq? x1 x2) Builtin Conditionals Compare the physical locations of the objects x1 and x2. Return true if they are the same (i.e., are the same physical object.) Objects having the same value will not be considered eq? if they are stored in different places. Use equal? instead.
(equal? x1 x2) Builtin Conditionals Tells if x1 and x2 have the same type and value.
(not x) Init File Conditionals Return the logical inverse of x.
(and x1 . . . xn) Init File Conditionals Return true if all xi values are true. The xi's are evaluated left-to-right, short-circuit.
(or x1 . . . xn) Builtin Conditionals Evaluate the xi values from left to right and return the first one which is not nil, otherwise return nil.
(nand x1 . . . xn) Init File Conditionals Return the not of the and.
(nor x1 . . . xn) Init File Conditionals Return the not of the or.
 
Controlling Evaluation
Call Where Defined More Info Description
(quote x) Builtin Quoting & Evaluation Return x without evaluation.
(eval x) Builtin Quoting & Evaluation Evaluate x and return.
(apply f lis ) Init File Quoting & Evaluation Run the function f with the parameters lis.
(if cond x1 x2) Init File Conditionals Evaluate cond. If it yields a true value, evaluate and return x1, else evaluate and return x2.
(cond ( p1 x1 ) . . . ( pn xn )) Builtin Conditionals Evaluate each pi in order until one is true. Then evaluate and return the corresponding xi. If no pi is true, return nil.
(begin x1 x2 . . . xn) Builtin Conditionals Evaluate each of x1 through xn in order, and return the result from xn.
 
Definitions and Scope
Call Where Defined More Info Description
(set id x) Builtin Definitions Set the identifier id to the value x in the current context.
(setq id x) Init File Definitions Same as set, but the identifier is automatically quoted.
(define ( id p1 . . . ) expr) Init File Functions Define a function id with parameters p1 dots and body expr.
(define id x) Init File Definitions Same as setq.
(scope expr1 . . . exprn) Builtin Definitions Evaluate the expressions expr1 . . . exprn, in a new scope, and return the value of exprn.
(let ( ( i1 x1 ) . . . ( in xn ) ) expr) Init File Definitions Evaluate expr in a new scope after sequentially evaluating each xk and assigning it to ik.
 
Functions And Macros
Call Where Defined More Info Description
(lambda parms expr) Builtin Functions Create a function with the parameter list given by parms and the body given by expr. The parms may be a list of identifiers or a single identifier. In the first case, the function must be called with a list of arguments of the same length as parms and each argument is bound to each parameter in the same order. If parms is a single identifier, the entire list of arguments is bound to it. Arguments are evaluated, the body is run, and its value returned.
(macro parms expr) Builtin Macros Create a macro closure. The parms may take the same forms as for lambda. When called, arguments are not evaluated, but the result of the body is.
 
String Operations
Call Where Defined More Info Description
(strlen x) Builtin Strings Returns the length of string x.
(string-length x) Init File Strings Returns the length of string x (an alias for strlen).
(concat x1 x2) Init File Strings Concatinate strings x1 and x2.
(string-append x1 x2) Init File Strings Concatinate strings x1 and x2 (an alias for concat).
(substr x i1 i2) Init File Strings Return the substring of string x starting at i1 (zero-based) and of length i2.
(chr i) Builtin Strings Returns a string containing the single character with the ascii value of i.
(ord x) Builtin Strings Return the ascii value of the first character of the string x.
(shatter x) Builtin Strings Return a list of single-character strings, each being the characters of string x, in the same order.
(collect x) Builtin Strings Take a list of string x and return their concatination.
 
Errors and Exceptions
Call Where Defined More Info Description
(error code descr) Builtin Exceptions Create and return an error object containing the integer code code and string description descr. This is essentially a throw operation.
(catch x1 x2 . . . xn) Builtin Exceptions Evaluate x1 through xn in order. If there is no exception, return the pair consisting of #t and the value of xn. If not, return (nil . (code. descr)), where code and descr are the integer and string contents of the excpetion.
(succeeds x1 x2 . . . xn) Init File Exceptions Evaluate x1 through xn in order. If there is no exception, return #t, otherwise return nil.
(fails x1 x2 . . . xn) Init File Exceptions Evaluate x1 through xn in order. If there is no exception, return nil, otherwise return #f.
(try expr (e1 x1) (e2 x2) . . . (en xn)) Init File Exceptions Evaluate expr. If no exception is thrown, return the result. Otherwise, scan the ek values left to right for a match. If one is found, evaluate xk and return its value. Otherwise, rethrow the original exception. An ek matches if it is the atom #t, if it is an atom which evalutes to the integer code of the thrown exception, or if it is a pair which evaluates to true. During evaluation of any ek or xk, the symbols ERROR and MESSAGE are bound to the code and message part, respectively, of the thrown exception.
 
Miscellaneous
Call Where Defined More Info Description
(exit i) Builtin Basic Input Immediately exit the interpreter passing the indicated exit code to the O/S.
(quit ) Init File Basic Input Immediately exit the interpreter with code 0.