home *** CD-ROM | disk | FTP | other *** search
- LISP INTERPRETER APPLICATION NOTES
-
-
- 1. INTRODUCTION
-
- Thσá followinτá applicatioε note≤ givσ somσ oµá thσá detail≤ ì
- necessar∙á t∩á properl∙á operatσ thσ LIS╨á interprete≥á whicΦá i≤ ì
- implemented in the files named LISP.PAS/COM.
- A≤á i⌠á ha≤á no⌠á beeε possiblσ t∩ addres≤á iεá thσá presen⌠ ì
- contex⌠ al∞ oµ thσ feature≤ whicΦ woulΣ bσ requireΣ t∩ maste≥ thσ ì
- subject¼ interesteΣ reader≤ arσ inviteΣ t∩ refe≥ t∩ thσ availablσ ì
- litterature for further details.
- This author has found most useful the following textbooks :
-
- Laurent SIKLOSSY - "Let's talk LISP" -
- Prentice Hall, Inc., 1976
-
- Patrick H.WINSTON - Berthold K.P.HORN - "LISP" -
- Addison-Wensley Pub.Co., 1981
-
- John ALLEN - "Anatomy of LISP" -
- McGraw Hill Book Co., 1978.
-
- Thσá presen⌠á interprete≥á ha≤ beeε deriveΣá froφá thσá LIS╨ ì
- interpreter available in ZUG vol.# 14.
- A≤á iε thσ origina∞ version¼á function≤ dealinτ witΦ number≤ ì
- are not supported.
-
-
- 2. HOW TO RUN LISP
-
- Capita∞á letter≤á mus⌠ bσ useΣ fo≥ al∞ LIS╨á reserveΣá word≤ ì
- (essentiall∙á name≤á oµá functions)║áá becausσá oµá thi≤á i⌠áá i≤ ì
- recommended that capital letters be used throughout.
-
- To run the interpreter proceed as follows :
-
- 1. Type LISP followed by a <cr>.
- 2. Wait for the message R E A D Y to appear : this
- indicates that the interpreter is ready to eva-
- luate a LISP expression.
- 3. Type the LISP expression to be evaluated on one
- or more successive lines (additional blanks do
- not produce any effect).
- The expression must be preceeded by a left pa-
- renthesis '(' and followed by a right parenthe-
- sis ')'.
- After having entered the LISP expression, type
- twice <cr> to initiate the evaluation.
- (Ensure that the correct number of parentheses
- is entered otherwise the interpreter will refu-
- se to start the evaluation as it expects more
- input data).
- 4. Once the evaluation is completed, the interpre-
- ter will print out the resulting expression.è 5. After that, other evaluation cycles can be in-
- troduced by repeating sequentially steps 3 and
- 4.
-
- T∩á terminatσá thσá proces≤á anΣ returεá t∩á CP/═á typσá FI╬ ì
- followed by two <cr>'s.
-
-
- 3. INITLISP
-
- INITLIS╨á i≤á thσ namσ oµ ß filσ whicΦ mus⌠ bσ availablσá oε ì
- thσá samσá diskettσá a≤ thσ interprete≥ fo≥ thσá latte≥á t∩á worδ ì
- properly.
- Upoε initiatioε oµ thσ interpreter¼ thσ content≤ oµ INITLIS╨ ì
- i≤á reaΣ anΣ useΣ t∩ alte≥ thσ LIS╨ environmen⌠ b∙ addinτá user'≤ ì
- defined variables (with their values) and/or functions.
- INITLIS╨ actuall∙ contain≤ element≤ oµ ß prograφ writteεá iε ì
- LIS╨á anΣ an∙ oµ thσ character≤ employeΣ t∩ writσ ß LIS╨á prograφ ì
- ma∙áá bσá used«áá Howeve≥á tab≤á (anΣá perhap≤á othe≥á key≤á no⌠ ì
- representinτ alphanumeriπ characters¼á dots¼ commas¼ spaces¼ etc⌐ ì
- shoulΣá bσá avoideΣá a≤á the∙á ma∙á producσá unexpecteΣá results« ì
- Further¼á INITLIS╨ mus⌠ bσ terminateΣ b∙ thσ atoφ FI╬ followeΣ b∙ ì
- two <cr>'s to avoid reading beyond the eof.
- INITLIS╨ a≤ presenteΣ onl∙ contain≤ thσ atoφ FI╬ followeΣ b∙ ì
- tw∩á <cr>'s«á Iε othe≥ word≤ INITLIS╨ wil∞ no⌠ affec⌠ a⌠ al∞á thσ ì
- LISP environment upon activation of the interpreter.
- Thσá filσá INITLISP.STB¼á als∩ includeΣ fo≥ thσá purposσá oµ ì
- demonstration¼ contain≤ ß numbe≥ oµ function≤ directl∙ writteε iε ì
- LISP«á Afte≥á renaminτ thi≤ filσ INITLIS╨ (afte≥ havinτ saveΣ thσ ì
- origina∞ INITLIS╨ fo≥ possiblσ re-use)¼á al∞ thesσ function≤ wil∞ ì
- becomσá integra∞ par⌠ oµ thσ LIS╨ environmen⌠ upoε initiatioεá oµ ì
- thσ interpreter«á Hencσ the∙ caε bσ utilizeΣ a≤ the∙ werσ actua∞ ì
- intrinsiπ functioε (witΦ somσ los≤ oµ efficiency).
-
-
- 4. TERMINOLOGY
-
- The following terms apply :
-
- a. SEX
- ┴á LISP-EXPRESSIO╬ o≥ SYMBOLIC-EXPRESSIO╬ (iε shor⌠á SEX⌐ ì
- consist≤ oµ aε atoφ o≥ ß dotted-pai≥ o≥ ß list (see further on).
-
- b. ATOM
- Aεáá ATO═á consist≤á oµá ßá strinτá oµá u≡á t∩áá IDLENGT╚ ì
- consecutivσ character≤ witΦ thσ exclusioε oµ '('¼á '.'¼ ')'¼ º '¼ ì
- and <cr>. (IDLENGTH is equal to 10).
-
- c. DOTTED-PAIR
- ┴ DOTTED-PAI╥ consist≤ oµ ß lef⌠ parenthesi≤ followeΣá b∙ ì
- aεá atoφ o≥ anothe≥ dotted-pai≥ o≥ ß list¼á followeΣ b∙ ß period¼ ì
- followeΣá b∙ aε atoφ o≥ ß dotted-pai≥ o≥ ß list¼á followeΣá b∙á ß ì
- righ⌠ parenthesis.
-
- è d. LIST
- ┴á LIS╘á consist≤ oµ ß lef⌠ parenthesis¼á followeΣá b∙á ß ì
- sequencσ oµ element≤ (atom≤ o≥ dotted-pair≤ o≥ list≤ separateΣ b∙ ì
- one or more blanks), followed by a right parenthesis.
- ┴áá lis⌠á ma∙á contaiεá an∙á numbe≥á oµá element≤áá (zer∩ ì
- included).
-
- e. SPECIAL ATOMS
- Atom T : denotes the truth value TRUE;
- Atom NIL : denotes the truth value FALSE.
-
- Atom≤ arσ alway≤ takeε a≤ representinτ variable≤ unles≤ the∙ ì
- arσá preceedeΣá b∙á thσá atoφá QUOTE«áá Iεá thσá firs⌠á casσá thσ ì
- interprete≥á attempt≤ t∩ evaluatσ theφ (iε othe≥ word≤ look≤á fo≥ ì
- thσá valuσ associateΣ witΦ them⌐ whilσ iε thσ seconΣ casσ i⌠ doe≤ ì
- not do that.
-
-
- 5. INTRINSIC FUNCTION SUPPORTED
-
- Thσá lis⌠á oµá thσá functioεsá whicΦá arσá supporteΣá b∙á thσ ì
- interprete≥ anΣ ß brieµ descriptioε oµ wha⌠ eacΦ functioε doe≤ i≤ ì
- giveε iε thσ following« Iε al∞ thσ example≤ whicΦ arσ giveε i⌠ i≤ ì
- assumed that :
- the value of X is the list (A B C)
- the value of Y is the list (D E F)
- the value of Z is the atom K.
- Iεá othe≥á word≤á i⌠á i≤ assumeΣ tha⌠á thσá followinτá threσ ì
- statements have been executed :
- (SETQ X (QUOTE(A B C)))
- (SETQ Y (QUOTE(D E F)))
- (SETQ Z (QUOTE K))
-
- Mos⌠á oµ thσ materia∞ whicΦ follow≤ ha≤ beeε takeε froφá thσ ì
- text of Siklossy mentioned in the introduction.
-
- AND
- Number of arguments : any
- Arguments : any SEXes
- Value : NIL if the value of some argument is NIL,
- otherwise T
- Example : (AND X Y) >>> T
-
- APPEND
- Number of arguments : 2
- Arguments : lists, when evaluated
- Value : the list of the SEXes representing the values
- of the two arguments
- Example : (APPEND X Y) >>> (A B C D E F)
-
- ATOM
- Number of arguments : 1
- Arguments : any SEX
- Value : T if the arg is an atom; NIL otherwise
- Examples : (ATOM X) >>> NIL; (ATOM Z) >>> Tè
- CAR
- Number of arguments : 1
- Argument : nonempty list, when evaluated
- Value : first element of the list
- Example : (CAR X) >>> A
-
- CDR
- Number of arguments : 1
- Argument : nonempty list, when evaluated
- Valuσ ║á remaining part of list with first element
- deleted
- Example : (CDR X) >>> (B C)
-
- CONS
- Number of arguments : 2
- Arguments : first, any SEX; second, any list (when
- evaluated)
- Value : a list, such that its CAR is the first argu-
- ment and its CDR the second argument
- Example : (CONS X Y) >>> ((A B C) D E F)
-
- COPY
- Number of arguments : 1
- Argument : any SEX
- Value : the argument
- Effec⌠ : a copy of the argument is added to the en-
- vironment
- ì
- DEFEXP (DEFine EXPression)
- Number of arguments : 1
- Use : to define a function and modify the environment
- accordingly; any such function always evaluates
- its arguments
- Examples : refer to file INITLISP.STB
-
- DEFFEXP (DEFine F-EXPression)
- Number of arguments : 1
- Use : same as DEFEXP, however the function does not
- evaluate its arguments
-
- DEFMAC (DEFine MACro)
- (NOT YET IMPLEMENTED)
-
- EQ
- Number of arguments : 2
- Arguments : two SEXes
- Value : T if the values of the 2 arguments are atoms
- with the same name or if they are lists con-
- tained in the same memory cells,
- otherwise NIL
- Example : (EQ X Y) >>> NIL
-
- EQUAL
- Number of arguments : 2è Arguments : two SEXes
- Value : T if the values of the 2 arguments are equal,
- otherwise NIL
- Example : (EQUAL X Y) >>> NIL
-
- EVAL
- Number of arguments : 1
- Argument : any SEX
- Value : the value of the value of the argument
-
- LAST
- Number of arguments : 1
- Argument : a list, when evaluated
- Value : the last SEX of the value of the argument
- Example : (LAST X) >>> C
-
- LENGTH
- Number of arguments : 1
- Argument : a list, when evaluated
- Value : the number of SEXes at the top level of the
- value of the argument list
- Example : (LENGTH X) >>> 003
-
- LIST
- Number of arguments : any
- Arguments : any SEX
- Value : a list of the values of the arguments
- Example : (LIST X Y) >>> ((A B C)(D E F))
-
- NOT
- Number of arguments : 1
- Argument : any SEX
- Value : T if SEX has value NIL, otherwise NIL
- Example : (NOT X) >>> NIL
-
- NULL
- Same as NOT
-
- OR
- Number of arguments : any
- Arguments : any SEXes
- Value : NIL if no argument value is non-NIL,
- otherwise T
- Example : (OR X Y) >>> NIL
-
- PROG2
- Number of arguments : 2
- Arguments : any SEXes
- Value : value of the second argument
- Side effect : the arguments are evaluated left to right
-
- PROGN
- Number of arguments : any
- Arguments : any SEXes
- Value : value of the last (rightmost argument)è Side effect : the arguments are evaluated left to right
-
-
- QUOTE
- Number of arguments : 1
- Argument : any SEX
- Value : the argument
- Example : (QUOTE X) >>> X
-
- REMOB (REMove OBject)
- Number of arguments : 1
- Argument : an atom
- Value : NIL (but basically irrelevant)
- Effect : the atom is permanently removed from the en-
- vironment
-
- REPLACEH (REPLACE Head)
- Number of arguments : 2
- Arguments : first : any SEX other than an atom;
- second : any SEX
- Value : the value of the first argument with its CAR
- replaced by the value of the second argument
- Side effect : the value of the first argument is modi-
- fied permanently
- Example : (REPLACEH X Y) >>> ((D E F) B C)
-
- REPLACET (REPLACE Tail)
- Number of arguments : 2
- Arguments : as in REPLACEH
- Value : the value of the first argument with its CDR
- replaced by the value of the second argument
- Side effect : as in REPLACEH
- Example : (REPLACET X Y) >>> (A D E F)
-
- REVERSE
- Number of arguments : 1
- Argument : a list, when evaluated
- Value : the value of the argument with its elements
- reversed
- Example : (REVERSE X) >>> (C B A)
-
- SET
- Number of arguments : 2
- Arguments : first : must evaluate to an atom;
- second : any SEX
- Value : the value of the second argument; the value
- of the first argument has its value replaced
- by this value of SET
- Side effect : the environment is permanently modified
-
- SETQ (SET Quote)
- Number of arguments : 2
- Arguments : first : an atom; second : any SEX
- Value : the value of the second argument; this value
- becomes the value of the first argumentè Side effect : the environment is permanently modified
-
- TRACE
- Number of arguments : 0
- Value : NIL (but basically irrelevant)
- Effect : all the functions will be traced
-
- UNTRACE
- Number of arguments : 0
- Value : NIL (but basically irrelevant)
- Effect : the functions will no longer be traced
-
-
- 6. ADDITIONAL FEATURES
-
- The following additional features are included :
-
- PROG control structure, allowing iterative programming
- style (limitations : GO and RETURN cannot be used to
- jump outside PROG);
-
- CONDitional expressions;
-
- LABEL for temporary function definitions;
-
- LAMBDA, FLAMBDA to introduce un-named functions evalua-
- ting (respectively non-evaluating) their arguments;
-
- FUNCTIO╬á construc⌠á t∩á dea∞á witΦá witΦá thσáá FUNAR╟ ì
- problem.
-
-
- Fo≥á al∞ oµ thσ abovσ feature≤ i⌠ i≤ recommendeΣ t∩ refe≥ t∩ ì
- the available litterature on LISP.
-
-
- 7. ...TO TERMINATE
-
- AlthougΦ quitσ somσ testinτ ha≤ beeε performeΣ i⌠ canno⌠á bσ ì
- excludeΣ tha⌠ thσ interprete≥ stil∞ contain≤ ß substantia∞ numbe≥ ì
- of bugs. So I wish you good luck with it !
- ╔á wil∞á welcomσá an∙á querie≤ and/o≥á suggestion≤á iεá thi≤ ì
- or any other respect.
-
-
- Lanfranco EMILIANI
- Maurits de Brauwweg 11
- 2597 KD Den Haag
- The Netherlands