home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol148 / lisp.doc < prev    next >
Encoding:
Text File  |  1985-02-10  |  13.6 KB  |  373 lines

  1.                  LISP INTERPRETER APPLICATION NOTES
  2.  
  3.  
  4. 1. INTRODUCTION
  5.  
  6.      Thσá followinτá applicatioε note≤ givσ somσ oµá thσá detail≤ ì
  7. necessar∙á t∩á properl∙á operatσ thσ LIS╨á interprete≥á whicΦá i≤ ì
  8. implemented in the files named LISP.PAS/COM.
  9.      A≤á i⌠á ha≤á no⌠á beeε possiblσ t∩ addres≤á iεá thσá presen⌠ ì
  10. contex⌠ al∞ oµ thσ feature≤ whicΦ woulΣ bσ requireΣ t∩ maste≥ thσ ì
  11. subject¼ interesteΣ reader≤ arσ inviteΣ t∩ refe≥ t∩ thσ availablσ ì
  12. litterature for further details.
  13.      This author has found most useful the following textbooks :
  14.  
  15.           Laurent SIKLOSSY - "Let's talk LISP" -
  16.                     Prentice Hall, Inc., 1976
  17.  
  18.           Patrick H.WINSTON - Berthold K.P.HORN - "LISP" -
  19.                     Addison-Wensley Pub.Co., 1981
  20.  
  21.           John ALLEN - "Anatomy of LISP" -
  22.                     McGraw Hill Book Co., 1978.
  23.  
  24.      Thσá presen⌠á interprete≥á ha≤ beeε deriveΣá froφá thσá LIS╨ ì
  25. interpreter available in ZUG vol.# 14.
  26.      A≤á iε thσ origina∞ version¼á function≤ dealinτ witΦ number≤ ì
  27. are not supported. 
  28.  
  29.   
  30. 2. HOW TO RUN LISP
  31.  
  32.      Capita∞á letter≤á mus⌠ bσ useΣ fo≥ al∞ LIS╨á reserveΣá word≤ ì
  33. (essentiall∙á name≤á oµá functions)║áá becausσá oµá thi≤á i⌠áá i≤ ì
  34. recommended that capital letters be used throughout.
  35.  
  36.      To run the interpreter proceed as follows :
  37.  
  38.           1. Type LISP followed by a <cr>.
  39.           2. Wait for the message R E A D Y to appear : this
  40.              indicates that the interpreter is ready to eva-
  41.              luate a LISP expression.
  42.           3. Type the LISP expression to be evaluated on one
  43.              or more successive lines (additional blanks  do
  44.              not produce any effect).
  45.              The expression must be preceeded by a left  pa-
  46.              renthesis '(' and followed by a right parenthe-
  47.              sis ')'.
  48.              After having entered the LISP expression,  type
  49.              twice <cr> to initiate the evaluation.
  50.              (Ensure that the correct number of parentheses
  51.              is entered otherwise the interpreter will refu-
  52.              se to start the evaluation as it  expects  more
  53.              input data).
  54.           4. Once the evaluation is completed, the interpre-
  55.              ter will print out the resulting expression.è          5. After that, other evaluation cycles can be  in-
  56.              troduced by repeating sequentially steps 3 and
  57.              4.
  58.  
  59.      T∩á terminatσá thσá proces≤á anΣ returεá t∩á CP/═á typσá FI╬ ì
  60. followed by two <cr>'s.
  61.  
  62.  
  63. 3. INITLISP
  64.  
  65.      INITLIS╨á i≤á thσ namσ oµ ß filσ whicΦ mus⌠ bσ availablσá oε ì
  66. thσá samσá diskettσá a≤ thσ interprete≥ fo≥ thσá latte≥á t∩á worδ ì
  67. properly.
  68.      Upoε initiatioε oµ thσ interpreter¼ thσ content≤ oµ INITLIS╨ ì
  69. i≤á reaΣ anΣ useΣ t∩ alte≥ thσ LIS╨ environmen⌠ b∙ addinτá user'≤ ì
  70. defined variables (with their values) and/or functions.
  71.      INITLIS╨ actuall∙ contain≤ element≤ oµ ß prograφ writteεá iε ì
  72. LIS╨á anΣ an∙ oµ thσ character≤ employeΣ t∩ writσ ß LIS╨á prograφ ì
  73. ma∙áá bσá used«áá  Howeve≥á tab≤á (anΣá perhap≤á othe≥á key≤á no⌠ ì
  74. representinτ alphanumeriπ characters¼á dots¼ commas¼ spaces¼ etc⌐ ì
  75. shoulΣá bσá avoideΣá a≤á the∙á ma∙á producσá unexpecteΣá results« ì
  76. Further¼á INITLIS╨ mus⌠ bσ terminateΣ b∙ thσ atoφ FI╬ followeΣ b∙ ì
  77. two <cr>'s to avoid reading beyond the eof.
  78.      INITLIS╨ a≤ presenteΣ onl∙ contain≤ thσ atoφ FI╬ followeΣ b∙ ì
  79. tw∩á <cr>'s«á Iε othe≥ word≤ INITLIS╨ wil∞ no⌠ affec⌠ a⌠ al∞á thσ ì
  80. LISP environment upon activation of the interpreter.
  81.      Thσá filσá INITLISP.STB¼á als∩ includeΣ fo≥ thσá purposσá oµ ì
  82. demonstration¼ contain≤ ß numbe≥ oµ function≤ directl∙ writteε iε ì
  83. LISP«á Afte≥á renaminτ thi≤ filσ INITLIS╨ (afte≥ havinτ saveΣ thσ ì
  84. origina∞ INITLIS╨ fo≥ possiblσ re-use)¼á al∞ thesσ function≤ wil∞ ì
  85. becomσá integra∞ par⌠ oµ thσ LIS╨ environmen⌠ upoε initiatioεá oµ ì
  86. thσ interpreter«á  Hencσ the∙ caε bσ utilizeΣ a≤ the∙ werσ actua∞ ì
  87. intrinsiπ functioε (witΦ somσ los≤ oµ efficiency).
  88.  
  89.  
  90. 4. TERMINOLOGY
  91.  
  92.      The following terms apply :
  93.  
  94.      a. SEX
  95.         ┴á LISP-EXPRESSIO╬ o≥ SYMBOLIC-EXPRESSIO╬ (iε shor⌠á SEX⌐ ì
  96. consist≤ oµ aε atoφ o≥ ß dotted-pai≥ o≥ ß list (see further on).
  97.  
  98.      b. ATOM
  99.         Aεáá ATO═á consist≤á oµá ßá strinτá oµá u≡á t∩áá IDLENGT╚ ì
  100. consecutivσ character≤ witΦ thσ exclusioε oµ '('¼á '.'¼ ')'¼ º '¼ ì
  101. and <cr>.  (IDLENGTH is equal to 10).
  102.  
  103.      c. DOTTED-PAIR
  104.         ┴ DOTTED-PAI╥ consist≤ oµ ß lef⌠ parenthesi≤ followeΣá b∙ ì
  105. aεá atoφ o≥ anothe≥ dotted-pai≥ o≥ ß list¼á followeΣ b∙ ß period¼ ì
  106. followeΣá b∙ aε atoφ o≥ ß dotted-pai≥ o≥ ß list¼á followeΣá b∙á ß ì
  107. righ⌠ parenthesis.
  108.  
  109. è     d. LIST
  110.         ┴á LIS╘á consist≤ oµ ß lef⌠ parenthesis¼á followeΣá b∙á ß ì
  111. sequencσ oµ element≤ (atom≤ o≥ dotted-pair≤ o≥ list≤ separateΣ b∙ ì
  112. one or more blanks), followed by a right parenthesis.
  113.         ┴áá lis⌠á ma∙á contaiεá an∙á numbe≥á oµá element≤áá (zer∩ ì
  114. included).
  115.  
  116.      e. SPECIAL ATOMS
  117.         Atom T : denotes the truth value TRUE;
  118.         Atom NIL : denotes the truth value FALSE.
  119.      
  120.      Atom≤ arσ alway≤ takeε a≤ representinτ variable≤ unles≤ the∙ ì
  121. arσá preceedeΣá b∙á thσá atoφá QUOTE«áá Iεá thσá firs⌠á casσá thσ ì
  122. interprete≥á attempt≤ t∩ evaluatσ theφ (iε othe≥ word≤ look≤á fo≥ ì
  123. thσá valuσ associateΣ witΦ them⌐ whilσ iε thσ seconΣ casσ i⌠ doe≤ ì
  124. not do that.
  125.  
  126.  
  127. 5. INTRINSIC FUNCTION SUPPORTED
  128.  
  129.      Thσá lis⌠á oµá thσá functioεsá whicΦá arσá supporteΣá b∙á thσ ì
  130. interprete≥ anΣ ß brieµ descriptioε oµ wha⌠ eacΦ functioε doe≤ i≤ ì
  131. giveε iε thσ following« Iε al∞ thσ example≤ whicΦ arσ giveε i⌠ i≤ ì
  132. assumed that :
  133.                     the value of X is the list (A B C)
  134.                     the value of Y is the list (D E F)
  135.                     the value of Z is the atom K.
  136.      Iεá othe≥á word≤á i⌠á i≤ assumeΣ tha⌠á thσá followinτá threσ ì
  137. statements have been executed :
  138.                     (SETQ X (QUOTE(A B C)))
  139.                     (SETQ Y (QUOTE(D E F)))
  140.                     (SETQ Z (QUOTE K))
  141.  
  142.      Mos⌠á oµ thσ materia∞ whicΦ follow≤ ha≤ beeε takeε froφá thσ ì
  143. text of Siklossy mentioned in the introduction.
  144.  
  145.      AND
  146.           Number of arguments : any
  147.           Arguments : any SEXes
  148.           Value : NIL if the value of some argument is NIL,
  149.                   otherwise T
  150.           Example : (AND X Y) >>> T
  151.  
  152.      APPEND
  153.           Number of arguments : 2
  154.           Arguments : lists, when evaluated
  155.           Value : the list of the SEXes representing the values
  156.                   of the two arguments
  157.           Example : (APPEND X Y) >>> (A B C D E F)
  158.  
  159.      ATOM
  160.           Number of arguments : 1
  161.           Arguments : any SEX
  162.           Value : T if the arg is an atom; NIL otherwise
  163.           Examples : (ATOM X) >>> NIL; (ATOM Z) >>> Tè
  164.      CAR
  165.           Number of arguments : 1
  166.           Argument : nonempty list, when evaluated
  167.           Value : first element of the list
  168.           Example : (CAR X) >>> A
  169.  
  170.      CDR
  171.           Number of arguments : 1
  172.           Argument : nonempty list, when evaluated
  173.           Valuσ ║á remaining part of list with first element 
  174.                    deleted
  175.           Example : (CDR X) >>> (B C)
  176.  
  177.      CONS
  178.           Number of arguments : 2
  179.           Arguments : first, any SEX; second, any list (when
  180.                       evaluated)
  181.           Value : a list, such that its CAR is the first argu-
  182.                   ment and its CDR the second argument
  183.           Example : (CONS X Y) >>> ((A B C) D E F)
  184.  
  185.      COPY
  186.           Number of arguments : 1
  187.           Argument : any SEX
  188.           Value : the argument
  189.           Effec⌠ : a copy of the argument is added to the en-
  190.                    vironment
  191. ì
  192.      DEFEXP (DEFine EXPression)
  193.           Number of arguments : 1
  194.           Use : to define a function and modify the environment
  195.                 accordingly; any such function always evaluates
  196.                 its arguments 
  197.           Examples : refer to file INITLISP.STB
  198.  
  199.      DEFFEXP (DEFine F-EXPression)
  200.           Number of arguments : 1
  201.           Use : same as DEFEXP, however the function does not
  202.                 evaluate its arguments
  203.  
  204.      DEFMAC (DEFine MACro)
  205.           (NOT YET IMPLEMENTED)
  206.  
  207.      EQ
  208.           Number of arguments : 2
  209.           Arguments : two SEXes
  210.           Value : T if the values of the 2 arguments are atoms 
  211.                   with the same name or if they are lists con-
  212.                   tained in the same memory cells, 
  213.                   otherwise NIL
  214.           Example : (EQ X Y) >>> NIL
  215.  
  216.      EQUAL
  217.           Number of arguments : 2è          Arguments : two SEXes
  218.           Value : T if the values of the 2 arguments are equal, 
  219.                   otherwise NIL
  220.           Example : (EQUAL X Y) >>> NIL               
  221.  
  222.      EVAL
  223.           Number of arguments : 1
  224.           Argument : any SEX
  225.           Value : the value of the value of the argument
  226.  
  227.      LAST
  228.           Number of arguments : 1
  229.           Argument : a list, when evaluated
  230.           Value : the last SEX of the value of the argument
  231.           Example : (LAST X) >>> C
  232.  
  233.      LENGTH
  234.           Number of arguments : 1
  235.           Argument : a list, when evaluated
  236.           Value : the number of SEXes at the top level of the
  237.                   value of the argument list
  238.           Example : (LENGTH X) >>> 003
  239.  
  240.      LIST
  241.           Number of arguments : any
  242.           Arguments : any SEX
  243.           Value : a list of the values of the arguments
  244.           Example : (LIST X Y) >>> ((A B C)(D E F))
  245.  
  246.      NOT
  247.           Number of arguments : 1
  248.           Argument : any SEX
  249.           Value : T if SEX has value NIL, otherwise NIL
  250.           Example : (NOT X) >>> NIL
  251.  
  252.      NULL
  253.           Same as NOT
  254.  
  255.      OR
  256.           Number of arguments : any
  257.           Arguments : any SEXes
  258.           Value : NIL if no argument value is non-NIL, 
  259.                   otherwise T
  260.           Example : (OR X Y) >>> NIL
  261.      
  262.      PROG2
  263.           Number of arguments : 2
  264.           Arguments : any SEXes
  265.           Value : value of the second argument
  266.           Side effect : the arguments are evaluated left to right
  267.  
  268.      PROGN
  269.           Number of arguments : any
  270.           Arguments : any SEXes
  271.           Value : value of the last (rightmost argument)è          Side effect : the arguments are evaluated left to right
  272.  
  273.  
  274.      QUOTE
  275.           Number of arguments : 1
  276.           Argument : any SEX
  277.           Value : the argument
  278.           Example : (QUOTE X) >>> X
  279.  
  280.      REMOB (REMove OBject)
  281.           Number of arguments : 1
  282.           Argument : an atom
  283.           Value : NIL (but basically irrelevant)
  284.           Effect : the atom is permanently removed from the en-
  285.           vironment
  286.  
  287.      REPLACEH (REPLACE Head)
  288.           Number of arguments : 2
  289.           Arguments : first : any SEX other than an atom; 
  290.                       second : any SEX
  291.           Value : the value of the first argument with its CAR
  292.                   replaced by the value of the second argument
  293.           Side effect : the value of the first argument is modi-
  294.                         fied permanently
  295.           Example : (REPLACEH X Y) >>> ((D E F) B C)
  296.  
  297.      REPLACET (REPLACE Tail)
  298.           Number of arguments : 2
  299.           Arguments : as in REPLACEH
  300.           Value : the value of the first argument with its CDR
  301.                   replaced by the value of the second argument
  302.           Side effect : as in REPLACEH
  303.           Example : (REPLACET X Y) >>> (A D E F)
  304.  
  305.      REVERSE
  306.           Number of arguments : 1
  307.           Argument : a list, when evaluated
  308.           Value : the value of the argument with its elements 
  309.                   reversed
  310.           Example : (REVERSE X) >>> (C B A)
  311.  
  312.      SET
  313.           Number of arguments : 2
  314.           Arguments : first : must evaluate to an atom; 
  315.                       second : any SEX
  316.           Value : the value of the second argument; the value
  317.                   of the first argument has its value replaced 
  318.                   by this value of SET
  319.           Side effect : the environment is permanently modified
  320.  
  321.      SETQ (SET Quote)
  322.           Number of arguments : 2
  323.           Arguments : first : an atom; second : any SEX
  324.           Value : the value of the second argument; this value
  325.                   becomes the value of the first argumentè          Side effect : the environment is permanently modified
  326.  
  327.      TRACE
  328.           Number of arguments : 0
  329.           Value : NIL (but basically irrelevant)
  330.           Effect : all the functions will be traced
  331.  
  332.      UNTRACE
  333.           Number of arguments : 0
  334.           Value : NIL (but basically irrelevant)
  335.           Effect : the functions will no longer be traced
  336.  
  337.  
  338. 6. ADDITIONAL FEATURES
  339.  
  340.      The following additional features are included :
  341.           
  342.           PROG control structure, allowing iterative programming
  343.           style (limitations : GO and RETURN cannot be used to
  344.           jump outside PROG);
  345.  
  346.           CONDitional expressions;
  347.  
  348.           LABEL for temporary function definitions;
  349.  
  350.           LAMBDA, FLAMBDA to introduce un-named functions evalua-
  351.           ting (respectively non-evaluating) their arguments;
  352.  
  353.           FUNCTIO╬á construc⌠á t∩á dea∞á witΦá witΦá thσáá FUNAR╟ ì
  354.           problem.
  355.  
  356.  
  357.      Fo≥á al∞ oµ thσ abovσ feature≤ i⌠ i≤ recommendeΣ t∩ refe≥ t∩ ì
  358. the available litterature on LISP.
  359.  
  360.  
  361. 7. ...TO TERMINATE
  362.  
  363.      AlthougΦ quitσ somσ testinτ ha≤ beeε performeΣ i⌠ canno⌠á bσ ì
  364. excludeΣ tha⌠ thσ interprete≥ stil∞ contain≤ ß substantia∞ numbe≥ ì
  365. of bugs. So I wish you good luck with it !
  366.      ╔á wil∞á welcomσá an∙á querie≤ and/o≥á suggestion≤á iεá thi≤ ì
  367. or any other respect.
  368.  
  369.  
  370. Lanfranco EMILIANI
  371. Maurits de Brauwweg 11
  372. 2597 KD Den Haag
  373. The Netherlands