Harish Karnick: 1 See Resonance, Vol.19, No.4, pp.345-367, 2013
Harish Karnick: 1 See Resonance, Vol.19, No.4, pp.345-367, 2013
LISP
Harish Karnick
Example 1.
Example 2.
(¸x:y)E1 ! y
¯
(¸x:((¸y:x (y y))E1))E2
!(¸y:E2 (y y))E1
¯
!E2 (E1 E1 )
¯
(¸x:x x)(¸y:y y)
!(¸y:y y)(¸z:z z) renamed y with z
¯
:::
:::
Example 5.
Example 6.
Example 7.
(cond
((null L) L)
(T (revfn L NIL)))
)
;;;;revfn does all the work
(defun revfn (L R)
(cond
((null L) R)
(T (revfn (cdr L) (cons (car L) R)))
)
)
many dialects that did not inter-operate came into exis- templates or types for a group of
objects. An object is some en-
tence. The two major dialects were MACLISP and IN- capsulated data along with func-
TERLISP. Consequently, in 1984 Guy Steele with help tions (often called methods) that
from a large number of Lispers created the book Com- define the behaviour of the ob-
mon Lisp. The Language. A second edition came out ject. Good examples are com-
mon data structures like stack,
in 1990 [7]. In 1994 Common Lisp was standardized as
queue and binary tree. Many
an ANSI standard. Objects have been added to LISP older languages have acquired
through CLOS (the Common Lisp Object System) and OO features – for example C (as
this is also part of the ANSI standard. CLOS di®ers C++), Python, Lisp, Fortran (For-
from standard Object Oriented (OO) languages3 like tran95 and later).
LISP was the first collector. Garbage is the name given to memory that
functional was once used by the program but cannot be accessed
programming from the running program anymore. Since lists are con-
language and as tinuously created and destroyed in LISP programs it is
such is a necessary to reclaim memory that is garbage. Other-
precursor of more wise, it is quite possible that the program will run out
recent functional of memory and thereby crash. OO programs also be-
languages like have in the same way where objects are created and then
SML and Haskell. become inaccessible. Most modern functional and OO
languages have garbage collectors (e.g., Java, Smalltalk,
SML, Haskell), but C++ (also C) is an exception. It
expects the programmer to manage the memory by ex-
plicitly deleting objects that will not be required any
longer. This is the single major source of bugs in C++
programs { the memory leak. While garbage is being
collected the program does not do useful work. So a lot
of e®ort has been expended in designing e±cient garbage
collection algorithms and in identifying garbage at the
point at which it is created so that it is cheaply collected.
Much of this research was done in the context of LISP
since it was the ¯rst mainstream language with garbage
collection.
LISP was the ¯rst functional programming language
and as such is a precursor of more recent functional
languages like SML and Haskell. These languages are
strongly typed with a type inference system unlike LISP.
However, they are largely functional languages and lack
the multi-paradigm dimension of LISP.
4 EMACS is a very versatile ed- LISP is still used in AI research though it is not the dom-
iting system that has ELISP (or inant language in that area. It is also the base language
EMACSLISP) as its scripting
language. This makes it pos-
of the EMACS editing system4 . While it is unlikely
sible to customize EMACS to do that it will achieve the prominence it had in its earlier
some very complex things like years, modern LISP is a standardized, multi-paradigm
create an integrated program language that has many good quality implementations
development environment. An- (some of them free) that are actively maintained. It has
other widely used program that
uses a dialect of LISP as a script-
many books and good documentation support and re-
ing language is AutoCAD. mains a language that one can pro¯tably choose to write
Suggested Reading