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