LISP Programming: Function Arg Arg Arg Arg
LISP Programming: Function Arg Arg Arg Arg
LISP Programming: Function Arg Arg Arg Arg
LISP is one of the simplest computer languages in terms of syntax and semantics, and also one of the
most powerful. It was developed in the mid-1950’s by John McCarthy at M.I.T. as a “LISt Processing
language”. Today, it is used for virtually all Artificial Intelligence programs and is the environment of
choice for applications which require a powerful interactive working environment. LISP presents a
very different way to think about programming from the “algorithmic” languages, such as BASIC,
Fortran and Pascal.
As its name implies, the basis of LISP is a list. One constructs a list by enumerating elements inside a
pair of parentheses. For example, here is a list with four elements (the second element is also a list):
(23 (this is easy) hello 821)
All statements in LISP are function calls with the following syntax: (function arg1 arg2 arg3 … argn). To
evaluate a LISP statement, each of the arguments (possibly functions themselves) are evaluated, and
then the function is invoked with the arguments. For example, (MULT (ADD 2 3) (ADD 1 4 2)) has a
value of 35, since (ADD 2 3) has a value of 5, (ADD 1 4 2) has a value of 7, and (MULT 5 7) has a
value of 35. Some functions have an arbitrary number of arguments; others require a fixed number.
All statements return a value, which is either an atom or a list.
FUNCTION RESULT
(ADD x1 x2 …) sum of all arguments
(MULT x1 x2 …) product of all arguments
(SUB a b) a-b
(DIV a b) a/b
(SQUARE a) a*a
(EXP a n) an
(EQ a b) true if a and b are equal, NIL otherwise
(POS a) true if a is positive, NIL otherwise
(NEG a) true if a is negative, NIL otherwise
STATEMENT VALUE
(ADD (EXP 2 3) (SUB 4 1) (DIV 54 4)) 24.5
(SUB (MULT 3 2) (SUB 12 (ADD 2 2))) -2
(ADD (SQUARE 3) (SQUARE 4)) 25
STEMPIA
LISP Programming - Worksheet
STEMPIA