LISP - as well as FORTH,
etc. - are very interesting programming languages of - as we say - 'artificial
intelligence':
You may improve them adding new terms and structures simply by means
of the existing language kernel!
LISP stands out due to an absolutely simple language structure!
On the one hand there are the so-called atoms, which are names of variables or procedures, or they are numbers or strings.
And then there are on the other hand what we are calling the lists. – They are consisting of an opening parenthesis, followed bay some atoms or lists, followed by a closing parenthesis.
This is, as we said already, a very simple and – besides a recursive – language structure! – There is nothing else.
But you can work great with it! - Anything is possible, just like it is with FORTH!
And you will - even with LISP - be unable to rein in your creative power!...
The Book I read: Die Programmiersprache Lisp, written by
Dr. Georg Schoffa, ISBN 3-7723-8361-0.
And now let's make an example of what I just told to you in !
We define a new structure called BLOCK which has the following format:
(BLOCK (name1 ...
namek)
e1
.
.
.
en
)
where:
name1 ... namek are names of variables
local
to this block (k >= 0)
e1 ... en are any LISP expressions
(n >= 1).
The 'statements' e1 through en are
evaluated in order using the local variables name1 ...
namek.
The result of the structure is the result of the evaluation of en.
Here's the program!
(DEFUN BLOCK st,p
(SETQ
st,p
(CAT
(LIST
'LAMBDA ()
(COND
((LISTP (CAR st,p))
(CONS 'PROG
(CAR st,p)
)
)
)
)
(CDR
st,p)
)
)
(st,p)
)
Note: Do not use st,p within the statements e1 ... en!
And now, we difine a new structure called WITH. It has the format:
(WITH (x1 ... xk)
(arg1 ... argk)
[(LEVEL [lname])]
[(PROG name1
... namem)]
e1
.
.
.
en
)
where:
x1 ... xk are actual parameters
assigned to the formal parameters arg1 ... argk
(k >= 0)
lname is the name of the structure body
name1 ... namem are variables local
to the structure
e1 ... en are any LISP expressions
(n >= 1)
parts enclosed in [] are optional.
First the actual parameters are evaluated and assigned to the corresponding
formal parameters.
Then the 'statements' e1 ... en
are evaluated in order.
The result of the structure is the result of the evaluation of en.
Within e1 ... en you may recall the structure body recursively simply by saing
(lname x1 ...xk)
where x1 ... xk is a new actual parameter set!
Of course, a recursive call has its own local variable set name1 ... namem, too.
And here is the program:
(DEFUN WITH st,w
(EVAL
(BLOCK (lname body)
(SETQ
body
(COND
( (AND
(LISTP (CADDR st,w))
(EQ
(CAR (CADDR st,w))
'LEVEL
)
)
(SETQ lname
(COND
( (NULL(CDR(CADDR st,w)))
'RECURSE
)
( T
(CADR(CADDR st,w))
)
)
)
(CDDDR st,w)
)
( T
(SETQ lname 'RECURSE)
(CDDR st,w)
)
)
)
(LIST
'BLOCK
(LIST lname)
(LIST 'SETQ lname
(LIT
(CONS 'LAMBDA
(CONS (CADR st,w)
body
)
)
)
)
(CONS lname (CAR st,w))
)
)
)
)
(DEFUN LIT (X)
(LIST 'QUOTE X)
)
PS: I am a hard working man and life is quite short but may
be, once you will find here a for download.
So, have a look at this location, say, once or twice a year...