home *** CD-ROM | disk | FTP | other *** search
/ Current Shareware 1994 January / SHAR194.ISO / cad_util / alsps.zip / ALSP1.DOC next >
Text File  |  1993-11-04  |  4KB  |  137 lines

  1. This is Lesson 1 of a series of AutoLISP training exercises given
  2. on the CompuServe ADESK Forum by the Autodesk, Inc. Training
  3. Department.
  4.  
  5. THE NAME OF THE LANGUAGE
  6.  
  7. Lisp stands for "list processing" or "list programming".  In
  8. Lisp, processing generally means "finding the value of an
  9. object"; that is, processing is the method by which Lisp
  10. determines the value of any expression, complex object, or simple
  11. object.
  12.  
  13. OBJECTS
  14.  
  15. There are two general types of objects in AutoLISP - ATOMS and
  16. LISTS.  Atoms are simple objects; lists are complex objects.
  17.  
  18. Atoms and lists are mutually exclusive.  Anything that is an
  19. atom cannot be a list, and vice versa (there is one exception
  20. that proves this rule, the object NIL; we'll examine it later).
  21.  
  22. ATOMS
  23.  
  24. Atoms can be integers, real numbers, text strings, AutoLISP
  25. functions, symbols, or special objects that correspond to AutoCAD
  26. entities, selection-sets, and files.
  27.  
  28. These are all atoms:
  29.  
  30.           1                             ;the integer 1
  31.           4.5                           ;the real number 4.5
  32.           "A String of Pearls"          ;a text string
  33.           setq                          ;an AutoLISP function
  34.           ename                         ;a user-defined symbol
  35.  
  36. See Section 1.4, "Lexical Conventions", of the R10 APR for more
  37. information.
  38.  
  39. VALUES OF ATOMS
  40.  
  41. The value of any atom, except AutoLISP functions and user-defined
  42. symbols, is itself.  For example, the atom 1 has a value of 1;
  43. the atom 4.5 has a value of 4.5; the atom "A String of Pearls"
  44. has a value of "A String of Pearls".
  45.  
  46. You can determine the value of any atom at the AutoCAD command
  47. prompt.  Type an exclamation point "!" followed by the atom.
  48. AutoLISP will find and return the value of the atom in the
  49. command prompt area.  For example, this expression finds the
  50. value of the atom (and real number) 4.5:
  51.  
  52.           Command: !4.5
  53.           4.5
  54.  
  55. LISTS
  56.  
  57. Lists are complex objects, referred to in some texts as symbolic
  58. expressions, or "s-expressions".  Lists are built out of atoms
  59. and/or other lists.  A list is syntactically simple; it must be
  60. bounded by matching parentheses, and objects within the list must
  61. be separated from one another by a space.
  62.  
  63. These are examples of lists:
  64.  
  65.           (+ 1 3)             ;add 1 and 3
  66.           (- 9 5)             ;subtract 5 from 9
  67.           (+ 1 (+ 2 3))       ;add 1 to the result of adding 2 and 3
  68.  
  69. Anything bounded by matching parentheses must be a list; anything
  70. not bounded by matching parentheses must be an atom.
  71.  
  72. ELEMENTS OF LISTS
  73.  
  74. The individual members of a list are known as its elements.  This
  75. is an example of a list with three elements, each an atom:
  76.  
  77.           (+ 1 2)
  78.  
  79. Elements of lists may be either atoms or other lists.  This is an
  80. example of a list with three elements; two are atoms, one is
  81. itself a list of three elements:
  82.  
  83.           (+ 1 (+ 2 3))
  84.            | |  \   /
  85.            | |   \ /
  86.            | |    |
  87.            elements
  88.  
  89. Elements of a list must be separated from one another by at least
  90. one space.  There is no limit on the number of spaces separating
  91. elements, but there must be at least one.  This is a perfectly
  92. valid list:
  93.  
  94.           (+          1         (+     1     3))
  95.  
  96. THE EMPTY LIST
  97.  
  98. There is one object in AutoLISP that is both an atom and a list.
  99. It is the empty list; that is, a list of no elements, commonly
  100. referred to as NIL.
  101.  
  102.           ()   or   nil
  103.  
  104. Nil (the empty list) in AutoLISP is "no value".  When an object
  105. in AutoLISP has no value, then the value of the object is nil.
  106.  
  107. EXERCISE
  108.  
  109. Which of these objects are atoms and which are lists?
  110.  
  111. 1.        73.5
  112. 2.        "0,0"
  113. 3.        (1.0 2.0 3.0)  
  114. 4.        "String"
  115. 5.        ("String")
  116. 6.        ()
  117.  
  118. Find the values of these atoms at the AutoCAD command prompt.
  119.  
  120. 1.        4.5
  121. 2.        "text"
  122. 3.        17
  123. 4.        setq
  124. 5.        xyz
  125. 6.        nil
  126.  
  127. How many elements are contained within each list?
  128.  
  129. 1.        (1.0  2.0  3.0)
  130. 2.        (+  1  2)
  131. 3.        (+  1  (+  2  3))
  132. 4.        (+  1  2  (+  3  4)  5)
  133. 5.        (+  1  (+  2  (+  3  4))  5)
  134. 6.        ()
  135.  
  136. Next week: Lists and Evaluation
  137.