home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / answers / lisp-faq / part1 next >
Encoding:
Text File  |  1993-12-12  |  59.5 KB  |  1,350 lines

  1. Newsgroups: comp.lang.lisp,news.answers,comp.answers
  2. Path: senator-bedfellow.mit.edu!bloom-beacon.mit.edu!news.kei.com!eff!news.umbc.edu!europa.eng.gtefsd.com!fs7.ece.cmu.edu!honeydew.srv.cs.cmu.edu!crabapple.srv.cs.cmu.edu!mkant
  3. From: mkant+@cs.cmu.edu (Mark Kantrowitz)
  4. Subject: FAQ: Lisp Frequently Asked Questions 1/7 [Monthly posting]
  5. Message-ID: <lisp_1.faq_755769617@cs.cmu.edu>
  6. Followup-To: poster
  7. Summary: Introductory Matter and Bibliography of Introductions and References
  8. Sender: news@cs.cmu.edu (Usenet News System)
  9. Supersedes: <lisp_1.faq_753177621@cs.cmu.edu>
  10. Nntp-Posting-Host: a.gp.cs.cmu.edu
  11. Reply-To: lisp-faq@think.com
  12. Organization: School of Computer Science, Carnegie Mellon
  13. Date: Mon, 13 Dec 1993 08:01:40 GMT
  14. Approved: news-answers-request@MIT.Edu
  15. Expires: Mon, 24 Jan 1994 08:00:17 GMT
  16. Lines: 1331
  17. Xref: senator-bedfellow.mit.edu comp.lang.lisp:11524 news.answers:15716 comp.answers:2968
  18.  
  19. Archive-name: lisp-faq/part1
  20. Last-Modified: Mon Nov 15 15:58:45 1993 by Mark Kantrowitz
  21. Version: 1.40
  22.  
  23. ;;; ****************************************************************
  24. ;;; Answers to Frequently Asked Questions about Lisp ***************
  25. ;;; ****************************************************************
  26. ;;; Written by Mark Kantrowitz and Barry Margolin
  27. ;;; lisp_1.faq -- 60214 bytes
  28.  
  29. This post contains Part 1 of the Lisp FAQ.
  30.  
  31. If you think of questions that are appropriate for this FAQ, or would
  32. like to improve an answer, please send email to us at lisp-faq@think.com.
  33.  
  34. Note that the lisp-faq mailing list is for discussion of the content
  35. of the FAQ posting only.  It is not the place to ask questions about Lisp;
  36. use either the common-lisp@ai.sri.com mailing list or the
  37. comp.lang.lisp newsgroup for that.  If a question appears frequently
  38. in one of those forums, it will get added to the FAQ list.
  39.  
  40. There are currently seven parts to the Lisp FAQ:
  41.    1. Introductory Matter and Bibliography of Introductions and References
  42.    2. General Questions
  43.    3. Common Programming Pitfalls
  44.    4. Lisp Implementations and Mailing Lists
  45.    5. Object-oriented Programming in Lisp
  46.    6. FTP Archives and Resources
  47.    7. Lisp Window Systems and GUIs
  48. All parts are posted to comp.lang.lisp. Part 5 is cross-posted to the
  49. comp.lang.clos newsgroup. 
  50.  
  51. Topics Covered (Part 1):
  52.  
  53.   [1-0]      What is the purpose of this newsgroup?
  54.   [1-1]      What is the difference between Scheme and Common Lisp?
  55.   [1-2]      What documentation is available on Lisp? How can I learn Lisp?
  56.   [1-3]      How can I improve my Lisp programming style and coding efficiency?
  57.   [1-4]      Where can I learn about implementing Lisp interpreters and compilers?
  58.   [1-5]      What does CLOS, PCL, X3J13, CAR, CDR, ... mean? 
  59.   [1-6]      Lisp Job Postings
  60.  
  61. Topics Covered (Part 2):
  62.  
  63.   [2-1]      Is there a GNU-Emacs interface to Lisp?
  64.   [2-2]      When should I use a hash table instead of an association list?
  65.   [2-3]      What is the equivalent of EXPLODE and IMPLODE in Common Lisp?
  66.   [2-4]      Is Lisp inherently slower than more conventional languages such as C?
  67.   [2-5]      Why does Common Lisp have "#'"?
  68.   [2-6]      How do I call non-Lisp functions from Lisp?
  69.   [2-7]      Can I call Lisp functions from other languages?
  70.   [2-8]      I want to call a function in a package that might not exist at
  71.       compile time. How do I do this?  
  72.   [2-9]      What is CDR-coding?
  73.   [2-10]  What is garbage collection?
  74.   [2-11]  How do I save an executable image of my loaded Lisp system?
  75.       How do I run a Unix command in my Lisp?
  76.       How do I get the current directory name from within a Lisp program?
  77.   [2-12]  I'm porting some code from a Symbolics Lisp machine to some
  78.       other platform, and there are strange characters in the code.
  79.       What do they mean?  
  80.   [2-13]  History: Where did Lisp come from?
  81.   [2-14]  How do I find the argument list of a function?
  82.       How do I get the function name from a function object?
  83.   [2-15]  How can I have two Lisp processes communicate via unix sockets?
  84.   [2-16]  How can I create a stream that acts like UNIX's /dev/null
  85.       (i.e., gobbles any output and immediately signals EOF on
  86.       input operations)?
  87.   [2-17]  Read-time conditionalization of code (#+ #- and *features*)
  88.   [2-18]  What reader macro characters are used in major Lisp systems?
  89.  
  90. Common Pitfalls (Part 3):
  91.  
  92.   [3-0]     Why does (READ-FROM-STRING "foobar" :START 3) return FOOBAR
  93.      instead of BAR?  
  94.   [3-1]     Why can't it deduce from (READ-FROM-STRING "foobar" :START 3)
  95.      that the intent is to specify the START keyword parameter
  96.      rather than the EOF-ERROR-P and EOF-VALUE optional parameters?      
  97.   [3-2]     Why can't I apply #'AND and #'OR?
  98.   [3-3]     I used a destructive function (e.g. DELETE, SORT), but it
  99.      didn't seem to work.  Why? 
  100.   [3-4]     After I NREVERSE a list, it's only one element long.  After I
  101.      SORT a list, it's missing things.  What happened? 
  102.   [3-5]     Why does (READ-LINE) return "" immediately instead of waiting
  103.      for me to type a line?     
  104.   [3-6]     I typed a form to the read-eval-print loop, but nothing happened. Why?
  105.   [3-7]     DEFMACRO doesn't seem to work.
  106.      When I compile my file, LISP warns me that my macros are undefined
  107.      functions, or complains "Attempt to call <function> which is 
  108.      defined as a macro.
  109.   [3-8]     Name conflict errors are driving me crazy! (EXPORT, packages)
  110.   [3-9]     Closures don't seem to work properly when referring to the
  111.      iteration variable in DOLIST, DOTIMES, DO and LOOP.
  112.   [3-10] What is the difference between FUNCALL and APPLY?
  113.   [3-11] Miscellaneous things to consider when debugging code.
  114.   [3-12] When is it right to use EVAL?
  115.   [3-13] Why does my program's behavior change each time I use it?
  116.   [3-14] When producing formatted output in Lisp, where should you put the
  117.      newlines (e.g., before or after the line, FRESH-LINE vs TERPRI,
  118.      ~& vs ~% in FORMAT)?
  119.   [3-15] I'm using DO to do some iteration, but it doesn't terminate. 
  120.   [3-16] My program works when interpreted but not when compiled!
  121.  
  122. Lisp Implementations and Mailing Lists (Part 4):
  123.  
  124.   [4-0]      Free Common Lisp implementations.
  125.   [4-1]      Commercial Common Lisp implementations.
  126.   [4-1a]  Lisp-to-C translators
  127.   [4-2]      Scheme Implementations
  128.   [4-4]      Free Implementations of Other Lisp Dialects
  129.   [4-5]      Commercial Implementations of Other Lisp Dialects
  130.   [4-6]      What is Dylan?
  131.   [4-7]      What is Pearl Common Lisp?
  132.   [4-9]      What Lisp-related discussion groups and mailing lists exist?
  133.   [4-10]  ANSI Common Lisp -- Where can I get a copy of the draft standard?
  134.  
  135. Object-oriented Programming in Lisp (Part 5):
  136.  
  137.   [5-0]      What is CLOS (PCL) and where can I get it?
  138.       How do you pronounce CLOS?
  139.   [5-1]      What documentation is available about object-oriented
  140.       programming in Lisp?    
  141.   [5-2]      How do I write a function that can access defstruct slots by
  142.       name?     I would like to write something like 
  143.       (STRUCTURE-SLOT <object> '<slot-name>).   
  144.   [5-3]      How can I list all the CLOS instances in a class?
  145.   [5-4]      How can I store data and CLOS instances (with possibly circular
  146.       references) on disk so that they may be retrieved at some later
  147.       time?
  148.   [5-5]      Given the name of a class, how can I get the names of its slots?
  149.   [5-6]      Free CLOS software.
  150.  
  151. FTP Resources (Part 6):
  152.  
  153.   [6-0] General information about FTP Resources for Lisp
  154.   [6-1] Repositories of Lisp Software
  155.   [6-3] Publicly Redistributable Lisp Software
  156.   [6-6] Formatting code in LaTeX
  157.   [6-7] Where can I get an implementation of Prolog in Lisp?
  158.  
  159. Lisp Window Systems and GUIs (Part 7):
  160.   [7-1] How can I use the X Window System or other GUIs from Lisp?
  161.   [7-2] What Graphers/Browsers are available?
  162.  
  163. Search for \[#\] to get to question number # quickly.
  164.  
  165. Recent Changes:
  166.  
  167. ;;; 1.39:
  168. ;;; 13-OCT-93 mk    Updated Blackboard Technology phone and address.
  169. ;;; 13-OCT-93 mk    Acknowledge Xerox PARC's contribution in the CLIM entry in
  170. ;;;                 [7-1].
  171. ;;; 13-OCT-93 mk    Added [2-18] about dispatching macro characters.
  172. ;;; 20-OCT-93 mk    Added clarification to [3-0].
  173. ;;; 26-OCT-93 mk    Added entry on Powerlisp (shareware Lisp for Mac) to [4-0].
  174. ;;; 28-OCT-93 mk    Added note about rehash-after-gc to [2-2].
  175. ;;;
  176. ;;; 1.40:
  177. ;;; 15-NOV-93 mk    Updated FOCL entry in part 6.
  178.  
  179.  
  180. Introduction:
  181.  
  182. Certain questions and topics come up frequently in the various network
  183. discussion groups devoted to and related to Lisp.  This file/article is
  184. an attempt to gather these questions and their answers into a convenient
  185. reference for Lisp programmers.     It (or a reference to it) is posted
  186. periodically.  The hope is that this will cut down on the user time and
  187. network bandwidth used to post, read and respond to the same questions
  188. over and over, as well as providing education by answering questions
  189. some readers may not even have thought to ask.
  190.  
  191. This is not a Lisp tutorial, nor is it an exhaustive list of all Lisp
  192. intricacies.  Lisp is a very powerful and expressive language, but with
  193. that power comes many complexities.  This list attempts to address the
  194. ones that average Lisp programmers are likely to encounter.  If you are
  195. new to Lisp, see the answer to the question "How can I learn Lisp?".
  196.  
  197. The latest version of this file is available via anonymous FTP from CMU
  198. and Thinking Machines: 
  199.  
  200.    To obtain the files from CMU, connect by anonymous ftp to any CMU CS
  201.    machine (e.g., ftp.cs.cmu.edu [128.2.206.173]), using username
  202.    "anonymous" and password "name@host". The files lisp_1.faq,
  203.    lisp_2.faq, lisp_3.faq, lisp_4.faq, lisp_5.faq, lisp_6.faq and
  204.    lisp_7.faq are located in the directory 
  205.        /afs/cs.cmu.edu/project/ai-repository/ai/pubs/faqs/lisp/
  206.    [Note: You must cd to this directory in one atomic operation, as
  207.    some of the superior directories on the path are protected from
  208.    access by anonymous ftp.] If your site runs the Andrew File System,
  209.    you can just cp the files directly without bothering with FTP.
  210.  
  211.    To obtain the files from Thinking Machines, ftp them from ftp.think.com,
  212.    in the directory /public/think/lisp/. The file faq.text contains all the
  213.    parts of the FAQ in one file. In addition, specific versions of the FAQ
  214.    are available as faq-<version>.text.
  215.  
  216. The FAQ postings are also archived in the periodic posting archive on
  217. rtfm.mit.edu [18.70.0.209]. Look in the anonymous ftp directory
  218. /pub/usenet/news.answers/ in the subdirectory lisp-faq/. If you do not
  219. have anonymous ftp access, you can access the archive by mail server
  220. as well.  Send an E-mail message to mail-server@rtfm.mit.edu
  221. with "help" and "index" in the body on separate lines for more
  222. information.
  223.  
  224. Unless otherwise specified, the Lisp dialect referred to is Common Lisp,
  225. as defined by "Common Lisp: the Language" (aka "CLtL1") as well as
  226. corrections (but not enhancements) from "Common Lisp: the Language, 2nd
  227. Edition" (aka "CLtL2"), both by Guy L. Steele, Jr. and published by
  228. Digital Press. Note that CLtL2 is NOT an official specification for
  229. the language; ANSI Committee X3J13 is preparing such a specification.
  230. See question [4-10] for information on the status of the ANSI
  231. specification for Common Lisp. Enhancements such as CLOS, conditions,
  232. and the LOOP macro will be referred to separately.
  233.  
  234. ----------------------------------------------------------------
  235. Subject: [1-0] What is the purpose of this newsgroup?
  236.  
  237. The newsgroup comp.lang.lisp exists for general discussion of
  238. topics related to the programming language Lisp. For example, possible
  239. topics can include (but are not necessarily limited to):
  240.    announcements of Lisp books and products
  241.    discussion of programs and utilities written in Lisp
  242.    discussion of portability issues
  243.    questions about possible bugs in Lisp implementations
  244.    problems porting an implementation to some architecture
  245. Postings should be of general interest to the Lisp community. See also
  246. question [4-9]. Postings asking for solutions to homework problems are
  247. inappropriate. 
  248.  
  249. Every so often, somebody posts an inflammatory message, such as
  250.    My programming language is better than yours (Lisp vs. C/Prolog/Scheme). 
  251.    Loop (or Series) should/shouldn't be part of the language.
  252. These "religious" issues serve no real purpose other than to waste
  253. bandwidth. If you feel the urge to respond to such a post, please do
  254. so through a private e-mail message. 
  255.  
  256. Questions about object oriented programming in Lisp should be directed
  257. to the newsgroup comp.lang.clos. Similarly, questions about the
  258. programming language Scheme should be directed to the newsgroup
  259. comp.lang.scheme. Discussion of functional programming language issues
  260. should be directed to the newsgroup comp.lang.functional. Discussion
  261. of AI programs implemented in Lisp should sometimes be cross-posted to
  262. the newsgroup comp.ai.
  263.  
  264. ----------------------------------------------------------------
  265. Subject: [1-1] What is the difference between Scheme and Common Lisp?
  266.  
  267. Scheme is a dialect of Lisp that stresses conceptual elegance and
  268. simplicity. It is specified in R4RS and IEEE standard P1178. (See
  269. the Scheme FAQ for details on standards for Scheme.) Scheme is much
  270. smaller than Common Lisp; the specification is about 50 pages,
  271. compared to Common Lisp's 1300 page draft standard. (See question
  272. [4-10] for details on standards for Common Lisp.) Advocates of Scheme
  273. often find it amusing that the Scheme standard is shorter than the
  274. index to CLtL2. 
  275.  
  276. Scheme is often used in computer science curricula and programming
  277. language research, due to its ability to represent many programming
  278. abstractions with its simple primitives. Common Lisp is often used for
  279. real world programming because of its large library of utility
  280. functions, a standard object-oriented programming facility (CLOS), and
  281. a sophisticated condition handling system.
  282.  
  283. See the Scheme FAQ for information about object-oriented programming
  284. in Scheme. 
  285.  
  286. In Common Lisp, a simple program would look something like the
  287. following:
  288.  
  289.    (defun fact (n)
  290.      (if (< n 2)
  291.      1
  292.      (* n (fact (1- n)))))
  293.  
  294. In Scheme, the equivalent program would like like this:
  295.  
  296.    (define fact
  297.      (lambda (n)
  298.        (if (< n 2)
  299.        1
  300.      (* n (fact (- n 1))))))
  301.  
  302. Experienced Lisp programmers might write this program as follows in order
  303. to allow it to run in constant space:
  304.  
  305.    (defun fact (n)
  306.      (labels ((tail-recursive-fact (counter accumulator)
  307.         (if (> counter n)
  308.             accumulator
  309.             (tail-recursive-fact (1+ counter)
  310.                      (* counter accumulator)))))
  311.        (tail-recursive-fact 1 1)))
  312.  
  313. Whereas in Scheme the same computation could be written as follows:
  314.  
  315.    (define fact
  316.      (lambda (n)
  317.        (letrec ((tail-recursive-fact
  318.          (lambda (counter accumulator)
  319.            (if (> counter n)
  320.                accumulator
  321.              (tail-recursive-fact (+ counter 1)
  322.                       (* counter accumulator))))))
  323.            (tail-recursive-fact 1 1))))
  324.  
  325. or perhaps (using IEEE named LETs):
  326.  
  327.    (define fact
  328.      (lambda (n)
  329.        (let loop ((counter n)
  330.           (accumulator 1))
  331.         (if (< counter 2)
  332.         accumulator
  333.           (loop (- counter 1)
  334.             (* accumulator counter))))))
  335.  
  336. Some Schemes allow one to use the syntax (define (fact n) ...) instead
  337. of (define fact (lambda (n) ...)).
  338.  
  339. ----------------------------------------------------------------
  340. Subject: [1-2] What documentation is available on Lisp? 
  341.            How can I learn Lisp?
  342.  
  343. There are several good Lisp introductions and tutorials:
  344.  
  345.    1. David S. Touretzky
  346.       "Common Lisp: A Gentle Introduction to Symbolic Computation"
  347.       Benjamin/Cummings Publishers, Redwood City, CA, 1990. 592 pages.
  348.       ISBN 0-8053-0492-4. 
  349.        Perhaps the best tutorial introduction to the language. It has
  350.        clear and correct explanations, and covers some fairly advanced
  351.        topics. The book is an updated Common Lisp version of the 1984
  352.        edition published by Harper and Row Publishers. 
  353.  
  354.        Three free Lisp educational tools which were used in the book --
  355.        Evaltrace, DTRACE and SDRAW -- are available by anonymous ftp from
  356.        b.gp.cs.cmu.edu:/usr/dst/public/{lisp,evaltrace}. Evaltrace is a
  357.        graphical notation for explaining how evaluation works and is
  358.        described in "Visualizing Evaluation in Applicative Languages" by
  359.        David S. Touretzky and Peter Lee, CACM 45-59, October 1992. DTRACE
  360.        is a "detailed trace" which provides more information than the 
  361.        tracing tools provided with most Common Lisp implementations. SDRAW
  362.        is a read-eval-draw loop that evaluates Lisp expressions
  363.        and draws the result as a cons cell diagram (for both X11 and ascii
  364.        terminals). Also available is PPMX, a tool for pretty printing
  365.        macro expansions.
  366.  
  367.    2. Robert Wilensky
  368.       "Common LISPcraft"
  369.       W. W. Norton, 1986. 500 pages. ISBN 0-393-95544-3.
  370.  
  371.    3. Wade L. Hennessey 
  372.       "Common Lisp"
  373.       McGraw-Hill, 1989. 395 pages.
  374.        Fairly good, but jumps back and forth from the simple to the
  375.        complex rather quickly, with no clear progression in difficulty.
  376.  
  377.    4. Laurent Siklossy
  378.       "Let's Talk LISP"
  379.       Prentice-Hall, NJ, 1976. 237 pages.
  380.        Good introduction, but quite out of date.
  381.  
  382.    5. Stuart C. Shapiro
  383.       "Common Lisp: An Interactive Approach"
  384.       Computer Science Press/W.H. Freeman, New York, 1992.
  385.       ISBN 0-7167-8218-9
  386.  
  387.    6. Paul Grahm
  388.       On Lisp: Advanced Techniques for Common Lisp
  389.       Prentice Hall, 1993.
  390.  
  391. Other introductions to Lisp include:
  392.  
  393.    1. A. A. Berk.
  394.       "LISP, The Language of Artificial Intelligence"
  395.       Van Nostrand Reinhold, 1985. 160 pages.
  396.  
  397.    2. Paul Y. Gloess.
  398.       "An Alfred handy guide to Understanding LISP"
  399.       Alfred Publishers (Sherman Oaks, CA), 1982. 64 pages.
  400.  
  401.    3. Ward D. Maurer.
  402.       "The Programmer's Introduction to LISP"
  403.       American Elsevier, 1972. 112 pages.
  404.  
  405.    4. Hank Bromley and Richard Lamson.
  406.       "LISP Lore: A Guide to Programming the LISP Machine"
  407.       Kluwer Academic (Boston), 1987. 337 pages.
  408.  
  409.    5. Sharam Hekmatpour.
  410.       "Introduction to LISP and Symbol Manipulation"
  411.       Prentice Hall (New York), 1988. 303 pages.
  412.  
  413.    6. Deborah G. Tatar
  414.       "A programmer's guide to Common Lisp"
  415.       Digital Press, 1987. 327 pages. ISBN 0-932376-87-8.
  416.        Good introduction on Common Lisp for programmers familiar
  417.        with other programming languages, such as FORTRAN, PASCAL, or C.
  418.  
  419.    7. Timothy Koschmann
  420.       "The Common Lisp Companion"
  421.       John Wiley & Sons, 1990. ISBN 0-471-503-8-8.
  422.        Targeted for those with some programming experience who wish to 
  423.        learn draft-ANSI Common Lisp, including CLOS and the CL condition 
  424.        system. Examples progress incrementally from simple numerical 
  425.        calculation all the way to a logic-programming extension to CL.
  426.   
  427. More advanced introductions to Lisp and its use in Artificial
  428. Intelligence include:
  429.  
  430.    1. Peter Norvig.
  431.       "Paradigms of AI Programming: Case Studies in Common Lisp"
  432.       Morgan Kaufmann, 1992. 946 pages. ISBN 1-55860-191-0.
  433.  
  434.     Provides an in-depth exposition of advanced AI programming techniques
  435.     and includes large-scale detailed examples. The book is the most
  436.     advanced AI/Common-Lisp programming text and reference currently
  437.     available, and hence is not for the complete novice.  It focuses on the
  438.     programming techniques necessary for building large AI systems,
  439.     including object-oriented programming, and has a strong performance
  440.     orientation.
  441.  
  442.     The text is marked by its use of "non-toy" examples to illustrate the
  443.     techniques. All of the examples are written in Common Lisp, and copies
  444.     of the source code are available by anonymous ftp from
  445.     unix.sri.com:pub/norvig and on disk in Macintosh or DOS format from
  446.     the publisher. Some of the techniques described include rule-based
  447.     pattern matching (GPS, Eliza, a subset of Macsyma, the Emycin expert
  448.     system shell), constraint propagation and backtracking (Waltz
  449.     line-labelling), alpha-beta search (Othello), natural language
  450.     processing (top-down, bottom-up and chart parsing), logic-programming
  451.     (unification and Prolog), interpreters and compilers for Scheme, and
  452.     object-oriented programming (CLOS).
  453.  
  454.     The examples are also used to illustrate good programming style and
  455.     efficiency. There is a guide to trouble-shooting and debugging Lisp
  456.     programs, a style guide, and a discussion of portability problems.
  457.     Some of the efficiency techniques described include memoization,
  458.     data indexing, compilation, delaying computation, proper use of
  459.     declarations, avoiding garbage collection, and choosing and using the
  460.     correct data structure.
  461.  
  462.     The book also serves as an advanced introduction to Common Lisp, with
  463.     sections on the Loop macro, CLOS and sequences, and some coverage of 
  464.     error handling, series, and the package facility.
  465.  
  466.    2. Eugene Charniak, Christopher K. Riesbeck, Drew V. McDermott
  467.       and James R. Meehan.
  468.       "Artificial Intelligence Programming", 2nd edition.
  469.       Lawrence Erlbaum Associates (Hillsdale, NJ), 1987. 533 pages.
  470.        Provides many nice code fragments, all of which are written
  471.        in Common Lisp. The first half of the book covers topics
  472.        like macros, the reader, data structures, control structures,
  473.        and defstructs. The second half of the book describes
  474.        programming techniques specific to AI, such as
  475.        discrimination nets, production systems, deductive database
  476.        retrieval, logic programming, and truth maintenance.
  477.  
  478.    3. Patrick H. Winston and Berthold K. P. Horn.
  479.       "LISP", 3rd edition.
  480.       Addison-Wesley (Reading, MA), 1989. 611 pages. ISBN 0-201-08319-1
  481.        Covers the basic concepts of the language, but also gives a lot
  482.        of detail about programming AI topics such as rule-based expert
  483.        systems, forward chaining, interpreting transition trees, 
  484.        compiling transition trees, object oriented programming,
  485.        and finding patterns in images. Not a tutorial. Has many
  486.        good examples. Source code for the examples is available by
  487.        anonymous ftp from ftp.ai.mit.edu:/pub/lisp3/. More
  488.        detailed versions are in /pub/ai3/. (The code runs in
  489.        Lucid, Allegro, KCL, GCLisp, MCL, Symbolics Genera. Send mail
  490.        with subject line "help" to ai3@ai.mit.edu for more information.)
  491.  
  492.    4. John R. Anderson, Albert T. Corbett, and Brian J. Reiser.
  493.       "Essential LISP"
  494.       Addison-Wesley (Reading, MA), 1987. 352 pages.
  495.        Concentrates on how to use Lisp with iteration and recursion.
  496.  
  497.    5. Robert D. Cameron and Anthony H. Dixon
  498.       "Symbolic Computing with Lisp"
  499.       Prentice-Hall, 1992, 326 pages. ISBN 0-13-877846-9.
  500.        The book is intended primarily as a third-year computer science
  501.        text. In terms of programming techniques, it emphasizes recursion
  502.        and induction, data abstraction, grammar-based definition of Lisp
  503.        data structures and functional programming style. It uses
  504.        two Lisp languages: 
  505.         (1) a purely functional subset of Lisp called Small Lisp and
  506.         (2) Common Lisp.
  507.        An MS-DOS interpreter for Small Lisp (including source) is
  508.        provided with the book.  It considers applications of Lisp
  509.        to formal symbolic data domains: algebraic expressions,
  510.        logical formulas, grammars and programming languages. 
  511.  
  512.    6. Hasemer and Domingue.
  513.       "Common Lisp Programming for Artificial Intelligence"
  514.       Addison-Wesley, 1989.
  515.  
  516.    7. Steven Tanimoto
  517.       "The Elements of Artificial Intelligence: An Introduction Using Lisp"
  518.       Computer Science Press, Rockville, MD, 1987, 530 pages.
  519.  
  520.    8. Patrick R. Harrison
  521.       "Common Lisp and Artificial Intelligence"
  522.       Prentice Hall, Englewood Clifs, NJ, 1990. 244 pages. ISBN 0-13-155243.
  523.  
  524. General Lisp reference books include:
  525.  
  526.    1. Guy L. Steele
  527.       "Common Lisp: The Language" [CLtL1]
  528.       Digital Press, 1984. 465 pages. ISBN 0-932376-41-X.
  529.  
  530.    2. Guy L. Steele
  531.       "Common Lisp: The Language, 2nd Edition" [CLtL2]
  532.       Digital Press, 1990. 1029 pages. ISBN 1-55558-041-6.
  533.  
  534.    3. Franz Inc. 
  535.       "Common Lisp: The Reference"
  536.       Addison-Wesley, Reading, MA 1988. ISBN 0-201-11458-5
  537.        Entries on Lisp (CLtL1) functions in alphabetical order.
  538.  
  539. Lisp periodicals include:
  540.     
  541.    1. LISP Pointers.
  542.       Published by ACM SIGPLAN six times a year. Volume 1, Number 1
  543.       was April-May 1987. 
  544.       Subscriptions: ACM Members $12; ACM Student Members $7; Non-ACM
  545.       members $25. Mail checks payable to the ACM to ACM Inc., PO Box
  546.       12115, Church Street Station, New York, NY 10249.
  547.  
  548.    2. LISP and Symbolic Computation, Kluwer Academic Press. Volume 1
  549.       was published in 1989. (jlz@lucid.com is the editor).  ISSN 0892-4635.
  550.       Subscriptions: Institutions $169; Individuals $80. Add $8 for
  551.       air mail. Kluwer Academic Publishers, PO Box 322, 3300 AH Dordrecht, 
  552.       The Netherlands, or Kluwer Academic Publishers, PO Box 358, Accord
  553.       Station, Hingham, MA 02018-0358. 
  554.  
  555.       A full table of contents of all published issues, aims and scope, and
  556.       instructions for authors are available by anonymous ftp from
  557.       world.std.com in the files Kluwer/journals/lisp.toc and
  558.       Kluwer/journals/lisp.inf.
  559.  
  560.    3. Proceedings of the biannual ACM Lisp and Functional Programming
  561.       Conference. (First one was in 1980.)
  562.  
  563.    4. Proceedings of the annual Lisp Users and Vendors Conference.
  564.  
  565. Implementation-specific questions:
  566.  
  567.    1. Lucid. See the wizards.doc file that comes with the Lucid
  568.       release. It describes functions, macros, variables and constants that
  569.       are not official parts of the product and are not supported.
  570.       Constructs described in this file include: the interrupt facility, the
  571.       source file recording facility, the resource facility, multitasking,
  572.       writing your own streams, lisp pipes, i/o buffers, the compiler,
  573.       floating-point functions, memory management, debugger information, the
  574.       window tool kit, extensions to the editor, the foreign function
  575.       interface, clos information, delivery toolkit information, and Lucid
  576.       lisp training classes. The wizards.doc file also covers i/o
  577.       constructs, functions for dealing with DEFSTRUCT, functions and
  578.       constants for dealing with procedure objects, functions and constants
  579.       for dealing with code objects, function for mapping objects,
  580.       additional keyword argument to DISKSAVE, function used in the
  581.       implementation of arrays, function for monitor-specific behavior for a
  582.       process, additional keyword argument to RUN-PROGRAM, and load-time
  583.       evaluation.
  584.  
  585. Many books on Scheme are worth reading even if you use Common Lisp,
  586. because many of the issues are similar. Scheme is a simpler language
  587. to learn, so it is often used in introductory computer science
  588. classes.  See the Scheme FAQ for a list of introductions and
  589. references for Scheme. The two key introductions are Abelson and
  590. Sussman's "Structure and Interpretation of Computer Programs" and 
  591. Friedman and Felleisen's "The Little LISPer". 
  592.  
  593. Special Topics:
  594.  
  595.    Garbage Collection:
  596.  
  597.       Wilson, Paul R., "Uniprocessor Garbage Collection Techniques"
  598.       Proceedings of the 1992 International Workshop on Memory Management.
  599.       Springer Lecture Notes #637. Surveys garbage collection techniques. 
  600.       Includes an excellent bibliography. Available by anonymous ftp from
  601.      cs.utexas.edu:pub/garbage/gcsurvey.ps.
  602.       The BibTeX format of the bibliography is also available in this
  603.       directory, along with several other papers. Contact wilson@cs.utexas.edu
  604.       for more info.
  605.  
  606. ----------------------------------------------------------------
  607. Subject: [1-3] How can I improve my Lisp programming style and 
  608.            coding efficiency?
  609.  
  610. There are several books about Lisp programming style, including:
  611.    
  612.    1. Molly M. Miller and Eric Benson
  613.       "Lisp Style and Design"
  614.       Digital Press, 1990. 214 pages. ISBN 1-55558-044-0.
  615.        How to write large Lisp programs and improve Lisp programming 
  616.        style. Uses the development of Lucid CL as an example. 
  617.  
  618.    2. Robin Jones, Clive Maynard, and Ian Stewart.
  619.       "The Art of Lisp Programming"
  620.       Springer-Verlag, 1989. 169 pages.
  621.  
  622.    3. W. Richard Stark.
  623.       "LISP, Lore, and Logic: an algebraic view of LISP
  624.        programming, foundations, and applications"
  625.       Springer-Verlag, 1990. 278 pages. ISBN 0-387-97072-X
  626.        Self-modifying code, self-reproducing programs, etc.
  627.  
  628.    4. CMU CL User's Manual, Chapter 7, (talks about writing
  629.       efficient code). It is available by anonymous ftp from any CMU CS 
  630.       machine (e.g., ftp.cs.cmu.edu [128.2.206.173]) as the file
  631.     /afs/cs.cmu.edu/project/clisp/docs/cmu-user/cmu-user.ps 
  632.       [when getting this file by anonymous ftp, one must cd to 
  633.       the directory in one atomic operation, as some of the superior
  634.       directories on the path are protected from access by anonymous ftp.]
  635.  
  636.    5. See also Norvig's book, SICP (Abelson & Sussman), SAP
  637.       (Springer and Friedman).
  638.  
  639.    6. Hallvard Tretteberg's Lisp Style Guide is available by anonymous
  640.       ftp in ftp.think.com:/public/think/lisp/style-guide.text. There is
  641.       a fair bit of overlap between Hallvard's style guide and the notes
  642.       below and in part 3 of this FAQ.
  643.  
  644.    7. Rajeev Sangal
  645.       "Programming Paradigms in Lisp"
  646.       McGraw-Hill, 1991. ISBN 0-07-054666-5.
  647.  
  648.    8. Rodney A. Brooks.
  649.       "Programming in Common Lisp"
  650.       John Wiley & Sons, New York, 1985. 303 pages. ISBN 0-471-81888-7.
  651.       Chapter 5 discusses Lisp programming style.
  652.  
  653. Here are some general suggestions/notes about improving Lisp
  654. programming style, readability, correctness and efficiency:
  655.  
  656.    General Programming Style Rules:
  657.  
  658.       - Write short functions, where each function provides a single,
  659.     well-defined operation. Small functions are easier to
  660.     read, write, test, debug, and understand.
  661.  
  662.       - Use descriptive variable and function names. If it isn't clear
  663.     from the name of a function or variable what its purpose is,
  664.     document it with a documentation string and a comment. In fact,
  665.     even if the purpose is evident from the name, it is still worth
  666.     documenting your code.
  667.  
  668.       - Don't write Pascal (or C) code in Lisp. Use the appropriate
  669.     predefined functions -- look in the index to CLtL2, or use the
  670.     APROPOS and DESCRIBE functions. Don't put a close parenthesis
  671.     on a line by itself -- this can really aggravate programmers
  672.     who grew up on Lisp. Lisp-oriented text editors include tools
  673.     for ensuring balanced parentheses and for moving across 
  674.     pairs of balanced parentheses. You don't need to stick
  675.     comments on close parentheses to mark which expression they close.
  676.  
  677.       - Use proper indentation -- you should be able to understand
  678.     the structure of your definitions without noticing the parentheses. 
  679.     In general, the way one indents a form is controlled by the
  680.     first symbol of the form. In DEFUNs, for example, one puts the
  681.     symbol DEFUN, the function name, and the argument list all on
  682.     the same line. If the argument list is too long, one can break
  683.     it at one of the lambda keywords. Following the argument list,
  684.     one inserts a carriage return and lists the expressions in the
  685.     body of the definition, with each form starting on its own
  686.     line indented three spaces relative to the open parenthesis of
  687.     the parent (in this case the DEFUN). This general style -- of
  688.     putting all the significant elements of a form on a single
  689.     line, followed by a carriage return and the indented body --
  690.     holds for many Lisp constructs. There are, of course, variations,
  691.     such as keeping the first clause on the same line as the COND
  692.     or CASE symbol, and the rules are relaxed in different ways to
  693.     keep line lengths to a manageable size. If you find yourself having
  694.     trouble fitting everything in even with line breaking and
  695.     relaxing the rules, either your function names are too long or your
  696.     code isn't very modular. You should perceive this as a signal that
  697.     you need to break up your big definitions into smaller chunks, each
  698.     with a clearly defined purpose, and possibly replace long function
  699.     names with concise but apt shorter ones.
  700.  
  701.       - Use whitespace appropriately. Use whitespace to separate
  702.     semantically distinct code segments, but don't use too much
  703.     whitespace. For example,
  704.        GOOD: 
  705.           (defun foo (x y)
  706.         (let ((z (+ x y 10)))
  707.           (* z z)))
  708.  
  709.        BAD: 
  710.           (defun foo(x y)(let((z(+ x y 10)))(* z z)))
  711.  
  712.           (defun foo ( x  y )
  713.         (let ( ( z (+ x y 10) ) )
  714.           ( * z z )
  715.           )
  716.         )    
  717.      Although the Lisp reader and compiler don't care which you
  718.      use, most experienced Lisp programs find the first example much easier
  719.      to read than the last two.
  720.  
  721.        - Don't use line lengths greater than 80 characters. People who
  722.      write code using Zmacs on Symbolics Lisp Machines are notoriously
  723.      guilty of violating this rule, because the CPT6 font allows
  724.      one to squeeze a tremendous amount of code on the display,
  725.      especially if one spreads the code out horizontally. This
  726.      makes it more difficult to read when printed out or read on
  727.      an 80x24 xterm window. In fact, use a line length of 72 characters
  728.      because it leaves a strip of white space at the edge of the window.
  729.  
  730.    The following functions often abused or misunderstood by novices. 
  731.    Think twice before using any of these functions.
  732.  
  733.       - EVAL. Novices almost always misuse EVAL. When experts use
  734.     EVAL, they often would be better off using APPLY, FUNCALL, or
  735.     SYMBOL-VALUE. Use of EVAL when defining a macro should set off
  736.     a warning bell -- macro definitions are already evaluated
  737.     during expansion. See also the answer to question 3-12.
  738.     The general rule of thumb about EVAL is: if you think you need
  739.     to use EVAL, you're probably wrong.
  740.  
  741.       - PROGV. PROGV binds dynamic variables and is often misused in
  742.     conjunction with EVAL, which uses the dynamic environment. 
  743.     In general, avoid unnecessary use of special variables.
  744.     PROGV is mainly for writing interpreters for languages embedded
  745.     in Lisp. If you want to bind a list of values to a list of
  746.     lexical variables, use
  747.         (MULTIPLE-VALUE-BIND (..) (VALUES-LIST ..) ..)
  748.     or
  749.         (MULTIPLE-VALUE-SETQ (..) (VALUES-LIST ..))
  750.     instead. Most decent compilers can optimize this expression. 
  751.     However, use of this idiom is not to be encouraged unless absolutely
  752.     necessary.
  753.  
  754.       - CATCH and THROW. Often a named BLOCK and RETURN-FROM are
  755.     more appropriate. Use UNWIND-PROTECT when necessary.
  756.  
  757.       - Destructive operations, such as NCONC, SORT, DELETE,
  758.     RPLACA, and RPLACD, should be used carefully and sparingly.
  759.     In general, trust the garbage collector: allocate new
  760.     data structures when you need them.
  761.  
  762.    To improve the readability of your code,
  763.  
  764.       - Don't use any C{A,D}R functions with more than two
  765.     letters between the C and the R. When nested, they become
  766.     hard to read. If you have complex data structures, you
  767.     are often better off describing them with a DEFSTRUCT,
  768.     even if the type is LIST. The data abstraction afforded by
  769.     DEFSTRUCT makes the code much more readable and its purpose
  770.     clearer. If you must use C{A,D}R, try to use
  771.     DESTRUCTURING-BIND instead, or at least SECOND, THIRD, 
  772.     NTH, NTHCDR, etc.
  773.  
  774.       - Use COND instead of IF and PROGN. In general, don't use PROGN if
  775.     there is a way to write the code within an implicit
  776.     PROGN. For example, 
  777.        (IF (FOO X)
  778.            (PROGN (PRINT "hi there") 23)
  779.            34)
  780.     should be written using COND instead.
  781.  
  782.       - Never use a 2-argument IF or a 3-argument IF with a second
  783.     argument of NIL unless you want to emphasize the return value;
  784.     use WHEN and UNLESS instead. You will want to emphasize the
  785.     return value when the IF clause is embedded within a SETQ,
  786.     such as (SETQ X (IF (EQ Y Z) 2 NIL)). If the second argument 
  787.     to IF is the same as the first, use OR instead: (OR P Q) rather
  788.     than (IF P P Q). Use UNLESS instead of (WHEN (NOT ..) ..)
  789.     but not instead of (WHEN (NULL ..) ..).
  790.  
  791.       - Use COND instead of nested IF statements. Be sure to check for
  792.     unreachable cases, and eliminate those cond-clauses.
  793.  
  794.       - Use backquote, rather than explicit calls to LIST, CONS, and
  795.     APPEND, whenever writing a form which produces a Lisp form, but
  796.     not as a general substitute for LIST, CONS and APPEND. LIST, 
  797.     CONS and APPEND usually allocate new storage, but lists produced
  798.     by backquote may involve destructive modification (e.g., ,.).
  799.  
  800.       - Make the names of special (global) variables begin and end
  801.     with an asterisk (*): (DEFVAR *GLOBAL-VARIABLE*)   
  802.     Some programmers will mark the beginning and end of an internal
  803.     global variable with a percent (%) or a period (.).
  804.     Make the names of constants begin and end with a plus (+):
  805.     (DEFCONSTANT +E+ 2.7182818)
  806.     This helps distinguish them from lexical variables. Some people
  807.     prefer to use macros to define constants, since this avoids
  808.     the problem of accidentally trying to bind a symbol declared
  809.     with defconstant.
  810.  
  811.       - If your program is built upon an underlying substrate which is
  812.     implementation-dependent, consider naming those functions and
  813.     macros in a way that visually identifies them, either by placing
  814.     them in their own package, or prepending a character like a %, ., 
  815.     or ! to the function name. Note that many programmers use the
  816.     $ as a macro character for slot access, so it should be avoided
  817.     unless you're using it for that purpose.
  818.  
  819.       - Don't use property lists. Instead, use an explicit hash table.
  820.     This helps avoid problems caused by the symbol being in the wrong
  821.     package, accidental reuse of property keys from other
  822.     programs, and allows you to customize the structure of the table. 
  823.  
  824.       - Use the most specific construct that does the job. This lets
  825.     readers of the code see what you intended when writing the code.
  826.     For example, don't use SETF if SETQ will do (e.g., for lexical
  827.     variables). Use the most specific predicate to test your conditions.
  828.     If you intend for a function to be a predicate, have it return T
  829.     for true, not just non-NIL. 
  830.  
  831.       - When NIL is used as an empty list, use () in your code. When NIL
  832.     is used as a boolean, use NIL. Similarly, use NULL to test for an
  833.     empty list, NOT to test a logical value. Use ENDP to test for the
  834.     end of a list, not NULL.
  835.  
  836.       - Don't use the &AUX lambda-list keyword. It is always clearer to
  837.     define local variables using LET or LET*.
  838.  
  839.       - When using RETURN and RETURN-FROM to exit from a block, don't
  840.     use (VALUES ..) when returning only one value, except if you
  841.     are using it to suppress extra multiple values from the first
  842.     argument. 
  843.  
  844.       - If you want a function to return no values (i.e., equivalent to
  845.     VOID in C), use (VALUES) to return zero values. This signals
  846.     to the reader that the function is used mainly for side-effects.
  847.  
  848.       - (VALUES (VALUES 1 2 3)) returns only the first value, 1.
  849.     You can use (VALUES (some-multiple-value-function ..)) to suppress
  850.     the extra multiple values from the function. Use MULTIPLE-VALUE-PROG1
  851.     instead of PROG1 when the multiple values are significant.
  852.  
  853.       - When using MULTIPLE-VALUE-BIND and DESTRUCTURING-BIND, don't rely
  854.     on the fact that NIL is used when values are missing. This is
  855.     an error in some implementations of DESTRUCTURING-BIND. Instead,
  856.     make sure that your function always returns the proper number of
  857.     values.
  858.  
  859.       - Type the name of external symbols, functions, and variables
  860.     from the COMMON-LISP package in uppercase. This will allow your
  861.     code to work properly in a case-sensitive version of Common Lisp,
  862.     since the print-names of symbols in the COMMON-LISP package
  863.     are uppercase internally. (However, not everybody feels that
  864.     being nice to case-sensitive Lisps is a requirement, so this
  865.     isn't an absolute style rule, just a suggestion.)
  866.  
  867.     Lisp Idioms:
  868.  
  869.       - MAPCAN is used with a function to return a variable number of
  870.     items to be included in an output list. When the function returns zero
  871.     or one items, the function serves as a filter. For example,
  872.        (mapcan #'(lambda (x) (when (and (numberp x) (evenp x)) (list x)))
  873.            '(1 2 3 4 x 5 y 6 z 7))
  874.  
  875.     Documentation:
  876.  
  877.       - Comment your code. Use three semicolons in the left margin before
  878.     the definition for major explanations. Use two semicolons that
  879.     float with the code to explain the routine that follows. Two
  880.     semicolons may also be used to explain the following line when the
  881.     comment is too long for the single semicolon treatment. Use
  882.     a single semicolon to the right of the code to explain a particular
  883.     line with a short comment. The number of semicolons used roughly
  884.     corresponds with the length of the comment. Put at least one blank
  885.     line before and after top-level expressions.
  886.  
  887.       - Include documentation strings in your code. This lets users
  888.     get help while running your program without having to resort to
  889.     the source code or printed documentation. 
  890.  
  891.    Issues related to macros:
  892.  
  893.       - Never use a macro instead of a function for efficiency reasons.
  894.     Declaim the function as inline -- for example, 
  895.       (DECLAIM (INLINE ..))
  896.     This is *not* a magic bullet -- be forewarned that inline
  897.     expansions can often increase the code size dramatically. INLINE
  898.     should be used only for short functions where the tradeoff is
  899.     likely to be worthwhile: inner loops, types that the compiler
  900.     might do something smart with, and so on.
  901.  
  902.       - When defining a macro that provides an implicit PROGN, use the
  903.     &BODY lambda-list keyword instead of &REST.
  904.  
  905.       - Use gensyms for bindings within a macro, unless the macro lets
  906.     the user explicitly specify the variable. For example:
  907.         (defmacro foo ((iter-var list) body-form &body body)
  908.           (let ((result (gensym "RESULT")))
  909.         `(let ((,result nil))
  910.            (dolist (,iter-var ,list ,result)
  911.              (setq ,result ,body-form)
  912.              (when ,result
  913.             ,@body)))))       
  914.     This avoids errors caused by collisions during macro expansion
  915.     between variable names used in the macro definition and in the
  916.     supplied body.
  917.  
  918.       - Use a DO- prefix in the name of a macro that does some kind of
  919.     iteration, WITH- when the macro establishes bindings, and
  920.     DEFINE- or DEF- when the macro creates some definitions. Don't
  921.     use the prefix MAP- in macro names, only in function names.
  922.  
  923.       - Don't create a new iteration macro when an existing function
  924.     or macro will do.
  925.  
  926.       - Don't define a macro where a function definition will work just
  927.     as well -- remember, you can FUNCALL or MAPCAR a function but 
  928.     not a macro.
  929.  
  930.       - The LOOP and SERIES macros generate efficient code. If you're
  931.     writing a new iteration macro, consider learning to use one
  932.     of them instead.
  933.   
  934.    File Modularization:
  935.  
  936.       - If your program involves macros that are used in more than one
  937.     file, it is generally a good idea to put such macros in a separate
  938.     file that gets loaded before the other files. The same things applies
  939.     to primitive functions. If a macro is complicated, the code that
  940.     defines the macro should be put into a file by itself. In general, if
  941.     a set of definitions form a cohesive and "independent" whole, they
  942.     should be put in a file by themselves, and maybe even in their own
  943.     package. It isn't unusual for a large Lisp program to have files named
  944.     "site-dependent-code", "primitives.lisp", and "macros.lisp". If a file
  945.     contains primarily macros, put "-macros" in the name of the file.
  946.  
  947.    Stylistic preferences:
  948.  
  949.       - Use (SETF (CAR ..) ..) and (SETF (CDR ..) ..) in preference to
  950.     RPLACA and RPLACD. Likewise (SETF (GET ..) ..) instead of PUT.
  951.  
  952.       - Use INCF, DECF, PUSH and POP instead instead of the corresponding
  953.     SETF forms.
  954.  
  955.       - Many programmers religiously avoid using CATCH, THROW, BLOCK,
  956.     PROG, GO and TAGBODY.  Tags and go-forms should only be necessary
  957.     to create extremely unusual and complicated iteration constructs. In
  958.     almost every circumstance, a ready-made iteration construct or
  959.     recursive implementation is more appropriate.
  960.  
  961.       - Don't use LET* where LET will do. Don't use LABELS where FLET
  962.     will do. Don't use DO* where DO will do.
  963.  
  964.       - Don't use DO where DOTIMES or DOLIST will do.
  965.  
  966.       - If you like using MAPCAR instead of DO/DOLIST, use MAPC when
  967.     no result is needed -- it's more efficient, since it doesn't
  968.     cons up a list. If a single cumulative value is required, use
  969.     REDUCE. If you are seeking a particular element, use FIND,
  970.     POSITION, or MEMBER.
  971.  
  972.       - If using REMOVE and DELETE to filter a sequence, don't use the
  973.     :test-not keyword or the REMOVE-IF-NOT or DELETE-IF-NOT functions.
  974.     Use COMPLEMENT to complement the predicate and the REMOVE-IF
  975.     or DELETE-IF functions instead.
  976.  
  977.       - Use complex numbers to represent points in a plane.
  978.  
  979.       - Don't use lists where vectors are more appropriate. Accessing the
  980.     nth element of a vector is faster than finding the nth element
  981.     of a list, since the latter requires pointer chasing while the
  982.     former requires simple addition. Vectors also take up less space
  983.     than lists. Use adjustable vectors with fill-pointers to
  984.     implement a stack, instead of a list -- using a list continually
  985.     conses and then throws away the conses.
  986.  
  987.       - When adding an entry to an association list, use ACONS, not
  988.     two calls to CONS. This makes it clear that you're using an alist.
  989.  
  990.       - If your association list has more than about 10 entries in it,
  991.     consider using a hash table. Hash tables are often more efficient.
  992.         (See also [2-2].)
  993.  
  994.       - When you don't need the full power of CLOS, consider using
  995.     structures instead. They are often faster, take up less space, and
  996.     easier to use.
  997.  
  998.       - Use PRINT-UNREADABLE-OBJECT when writing a print-function.
  999.  
  1000.       - Use WITH-OPEN-FILE instead of OPEN and CLOSE.
  1001.  
  1002.       - When a HANDLER-CASE clause is executed, the stack has already
  1003.     unwound, so dynamic bindings that existed when the error
  1004.     occured may no longer exist when the handler is run. Use
  1005.     HANDLER-BIND if you need this. 
  1006.  
  1007.       - When using CASE and TYPECASE forms, if you intend for the form
  1008.     to return NIL when all cases fail, include an explicit OTHERWISE
  1009.     clause. If it would be an error to return NIL when all cases
  1010.     fail, use ECASE, CCASE, ETYPECASE or CTYPECASE instead.
  1011.  
  1012.       - Use local variables in preference to global variables whenever
  1013.     possible. Do not use global variables in lieu of parameter passing.
  1014.     Global variables can be used in the following circumstances:
  1015.       *  When one function needs to affect the operation of
  1016.          another, but the second function isn't called by the first.
  1017.          (For example, *load-pathname* and *break-on-warnings*.)
  1018.       *  When a called function needs to affect the current or future
  1019.          operation of the caller, but it doesn't make sense to accomplish
  1020.          this by returning multiple values.
  1021.       *  To provide hooks into the mechanisms of the program.
  1022.          (For example, *evalhook*, *, /, and +.)
  1023.       *  Parameters which, when their value is changed, represent a
  1024.          major change to the program.
  1025.          (For example, *print-level* and *print-readably*.)
  1026.       *  For state that persists between invocations of the program.
  1027.          Also, for state which is used by more than one major program.
  1028.          (For example, *package*, *readtable*, *gensym-counter*.)
  1029.       *  To provide convenient information to the user.
  1030.          (For example, *version* and *features*.)
  1031.       *  To provide customizable defaults. 
  1032.          (For example, *default-pathname-defaults*.)
  1033.       *  When a value affects major portions of a program, and passing
  1034.          this value around would be extremely awkward. (The example
  1035.          here is output and input streams for a program. Even when
  1036.          the program passes the stream around as an argument, if you
  1037.          want to redirect all output from the program to a different
  1038.          stream, it is much easier to just rebind the global variable.)
  1039.  
  1040.       - Beginning students, especially ones accustomed to programming
  1041.     in C, Pascal, or Fortran, tend to use global variables to hold or pass
  1042.     information in their programs. This style is considered ugly by
  1043.     experienced Lisp programmers. Although assignment statements can't
  1044.     always be avoided in production code, good programmers take advantage
  1045.     of Lisp's functional programming style before resorting to SETF and
  1046.     SETQ. For example, they will nest function calls instead of using a
  1047.     temporary variable and use the stack to pass multiple values. When
  1048.     first learning to program in Lisp, try to avoid SETF/SETQ and their
  1049.     cousins as much as possible. And if a temporary variable is necessary,
  1050.     bind it to its first value in a LET statement, instead of letting it
  1051.     become a global variable by default. (If you see lots of compiler
  1052.     warnings about declaring variables to be special, you're probably
  1053.     making this mistake. If you intend a variable to be global, it should
  1054.     be defined with a DEFVAR or DEFPARAMETER statement, not left to the
  1055.     compiler to fix.)
  1056.  
  1057.    Correctness and efficiency issues:
  1058.  
  1059.       - In CLtL2, IN-PACKAGE does not evaluate its argument. Use defpackage
  1060.     to define a package and declare the external (exported)
  1061.     symbols from the package. 
  1062.  
  1063.       - The ARRAY-TOTAL-SIZE-LIMIT may be as small as 1024, and the
  1064.     CALL-ARGUMENTS-LIMIT may be as small as 50. 
  1065.  
  1066.       - Novices often mistakenly quote the conditions of a CASE form.
  1067.     For example, (case x ('a 3) ..) is incorrect. It would return
  1068.     3 if x were the symbol QUOTE. Use (case x (a 3) ..) instead.
  1069.  
  1070.       - Avoid using APPLY to flatten lists. (apply #'append list-of-lists)
  1071.     is compiled into a function call, and can run into problems with
  1072.     the CALL-ARGUMENTS-LIMIT. Use REDUCE or MAPCAR instead:
  1073.        (reduce #'append list-of-lists :from-end t)
  1074.        (mapcan #'copy-list list-of-lists)
  1075.     The second will often be more efficient (see note below about choosing
  1076.     the right algorithm). Beware of calls like (apply f (mapcar ..)).
  1077.  
  1078.       - NTH must cdr down the list to reach the elements you are
  1079.     interested in. If you don't need the structural flexibility of
  1080.     lists, try using vectors and the ELT function instead.
  1081.  
  1082.       - CASE statements can be vectorized if the keys are consecutive
  1083.     numbers. Such CASE statements can still have OTHERWISE clauses.
  1084.     To take advantage of this without losing readability, use #. with 
  1085.     symbolic constants:
  1086.  
  1087.         (eval-when (compile load eval)
  1088.            (defconstant RED 1)
  1089.            (defconstant GREEN 2)
  1090.            (defconstant BLUE 3))
  1091.  
  1092.         (case color
  1093.           (#.RED   ...)
  1094.           (#.GREEN ...)
  1095.           (#.BLUE  ...)
  1096.           ...)
  1097.  
  1098.       - Don't use quoted constants where you might later destructively
  1099.     modify them. For example, instead of writing '(c d) in
  1100.        (defun foo ()
  1101.          (let ((var '(c d)))
  1102.            ..))
  1103.     write (list 'c 'd) instead. Using a quote here can lead to
  1104.     unexpected results later. If you later destructively modify the 
  1105.     value of var, this is self-modifying code! Some Lisp compilers
  1106.     will complain about this, since they like to make constants
  1107.     read-only. Modifying constants has undefined results in ANSI CL.
  1108.     See also the answer to question [3-13].
  1109.  
  1110.     Similarly, beware of shared list structure arising from the use
  1111.     of backquote. Any sublist in a backquoted expression that doesn't
  1112.     contain any commas can share with the original source structure.
  1113.  
  1114.       - Don't proclaim unsafe optimizations, such as
  1115.        (proclaim '(optimize (safety 0) (speed 3) (space 1))) 
  1116.     since this yields a global effect. Instead, add the
  1117.     optimizations as local declarations to small pieces of
  1118.     well-tested, performance-critical code:
  1119.        (defun well-tested-function ()
  1120.           (declare (optimize (safety 0) (speed 3) (space 1)))
  1121.          ..)
  1122.     Such optimizations can remove run-time type-checking; type-checking
  1123.     is necessary unless you've very carefully checked your code
  1124.     and added all the appropriate type declarations.
  1125.  
  1126.       - Some programmers feel that you shouldn't add declarations to
  1127.     code until it is fully debugged, because incorrect
  1128.     declarations can be an annoying source of errors. They recommend
  1129.     using CHECK-TYPE liberally instead while you are developing the code.
  1130.     On the other hand, if you add declarations to tell the
  1131.     compiler what you think your code is doing, the compiler can
  1132.     then tell you when your assumptions are incorrect.
  1133.     Declarations also make it easier for another programmer to read
  1134.     your code. 
  1135.  
  1136.       - Declaring the type of variables to be FIXNUM does not
  1137.     necessarily mean that the results of arithmetic involving the 
  1138.     fixnums will be a fixnum; it could be a BIGNUM. For example,
  1139.        (declare (type fixnum x y))
  1140.        (setq z (+ (* x x) (* y y)))
  1141.     could result in z being a BIGNUM. If you know the limits of your
  1142.     numbers, use a declaration like
  1143.        (declare (type (integer 0 100) x y))
  1144.     instead, since most compilers can then do the appropriate type
  1145.     inference, leading to much faster code.
  1146.  
  1147.       - Don't change the compiler optimization with an OPTIMIZE
  1148.     proclamation or declaration until the code is fully debugged
  1149.     and profiled.  When first writing code you should say 
  1150.     (declare (optimize (safety 3))) regardless of the speed setting.
  1151.  
  1152.       - Depending on the optimization level of the compiler, type
  1153.     declarations are interpreted either as (1) a guarantee from
  1154.     you that the variable is always bound to values of that type,
  1155.     or (2) a desire that the compiler check that the variable is
  1156.     always bound to values of that type. Use CHECK-TYPE if (2) is
  1157.     your intention.
  1158.  
  1159.       - If you get warnings about unused variables, add IGNORE
  1160.     declarations if appropriate or fix the problem. Letting such
  1161.     warnings stand is a sloppy coding practice.
  1162.  
  1163.    To produce efficient code,
  1164.  
  1165.       - choose the right algorithm. For example, consider seven possible
  1166.     implementations of COPY-LIST:
  1167.  
  1168.        (defun copy-list (list)
  1169.          (let ((result nil))
  1170.            (dolist (item list result)
  1171.          (setf result (append result (list item))))))
  1172.  
  1173.        (defun copy-list (list)
  1174.          (let ((result nil))
  1175.            (dolist (item list (nreverse result))
  1176.          (push item result))))
  1177.  
  1178.        (defun copy-list (list)
  1179.          (mapcar #'identity list))
  1180.  
  1181.        (defun copy-list (list)
  1182.          (let ((result (make-list (length list))))
  1183.            (do ((original list (cdr original))
  1184.             (new result (cdr new)))
  1185.            ((null original) result)
  1186.          (setf (car new) (car original)))))
  1187.  
  1188.        (defun copy-list (list)
  1189.          (when list
  1190.            (let* ((result (list (car list)))
  1191.               (tail-ptr result))
  1192.          (dolist (item (cdr list) result)
  1193.            (setf (cdr tail-ptr) (list item))
  1194.            (setf tail-ptr (cdr tail-ptr))))))
  1195.     
  1196.         (defun copy-list (list)
  1197.           (loop for item in list collect item))
  1198.  
  1199.         (defun copy-list (list)
  1200.           (if (consp list) 
  1201.           (cons (car list)
  1202.             (copy-list (cdr list)))
  1203.           list))
  1204.  
  1205.     The first uses APPEND to tack the elements onto the end of the list.
  1206.     Since APPEND must traverse the entire partial list at each step, this
  1207.     yields a quadratic running time for the algorithm.  The second
  1208.     implementation improves on this by iterating down the list twice; once
  1209.     to build up the list in reverse order, and the second time to reverse
  1210.     it. The efficiency of the third depends on the Lisp implementation,
  1211.     but it is usually similar to the second, as is the fourth.  The fifth
  1212.     algorithm, however, iterates down the list only once. It avoids the
  1213.     extra work by keeping a pointer (reference) to the last cons of the 
  1214.     list and RPLACDing onto the end of that. Use of the fifth algorithm 
  1215.     may yield a speedup. Note that this contradicts the earlier dictum to
  1216.     avoid destructive functions. To make more efficient code one might
  1217.     selectively introduce destructive operations in critical sections of
  1218.     code. Nevertheless, the fifth implementation may be less efficient in
  1219.     Lisps with cdr-coding, since it is more expensive to RPLACD cdr-coded
  1220.     lists. Depending on the implementation of nreverse, however,
  1221.     the fifth and second implementations may be doing the same
  1222.     amount of work. The sixth example uses the Loop macro, which usually
  1223.     expands into code similar to the third. The seventh example copies
  1224.     dotted lists, and runs in linear time, but isn't tail-recursive. 
  1225.  
  1226.       - use type declarations liberally in time-critical code, but
  1227.     only if you are a seasoned Lisp programmer. Appropriate type
  1228.     declarations help the compiler generate more specific and
  1229.     optimized code. It also lets the reader know what assumptions
  1230.     were made. For example, if you only use fixnum arithmetic,
  1231.     adding declarations can lead to a significant speedup. If you
  1232.     are a novice Lisp programmer, you should use type declarations
  1233.     sparingly, as there may be no checking to see if the
  1234.     declarations are correct, and optimized code can be harder to
  1235.     debug. Wrong declarations can lead to errors in otherwise
  1236.     correct code, and can limit the reuse of code in other
  1237.     contexts. Depending on the Lisp compiler, it may also 
  1238.     be necessary to declare the type of results using THE, since
  1239.     some compilers don't deduce the result type from the inputs.
  1240.  
  1241.       - check the code produced by the compiler by using the
  1242.     disassemble function
  1243.  
  1244. ----------------------------------------------------------------
  1245. Subject: [1-4] Where can I learn about implementing Lisp interpreters 
  1246.            and compilers?
  1247.  
  1248. Books about Lisp implementation include:
  1249.  
  1250.    1. John Allen
  1251.       "Anatomy of Lisp"
  1252.       McGraw-Hill, 1978. 446 pages. ISBN 0-07-001115-X
  1253.  
  1254.    2. Samuel Kamin
  1255.       "Programming Languages, An Interpreter-Based Approach"
  1256.       Addison-Wesley, Reading, Mass., 1990. ISBN 0-201-06824-9
  1257.        Includes sources to several interpreters for Lisp-like
  1258.        languages, and a pointer to sources via anonymous ftp.
  1259.  
  1260.    3. Sharam Hekmatpour
  1261.       "Lisp: A Portable Implementation"
  1262.       Prentice Hall, 1985. ISBN 0-13-537490-X.
  1263.        Describes a portable implementation of a small dynamic
  1264.        Lisp interpreter (including C source code). 
  1265.  
  1266.    4. Peter Henderson
  1267.       "Functional Programming: Application and Implementation"
  1268.       Prentice-Hall (Englewood Cliffs, NJ), 1980. 355 pages.
  1269.  
  1270.    5. Peter M. Kogge
  1271.       "The Architecture of Symbolic Computers"
  1272.       McGraw-Hill, 1991. ISBN 0-07-035596-7.
  1273.        Includes sections on memory management, the SECD and
  1274.        Warren Abstract Machines, and overviews of the various
  1275.        Lisp Machine architectures.
  1276.    
  1277.    6. Daniel P. Friedman, Mitchell Wand, and Christopher T. Haynes
  1278.       "Essentials of Programming Languages"
  1279.       MIT Press, 1992, 536 pages. ISBN 0-262-06145-7.
  1280.        Teaches fundamental concepts of programming language
  1281.        design by using small interpreters as examples. Covers
  1282.        most of the features of Scheme. Includes a discussion
  1283.        of parameter passing techniques, object oriented languages,
  1284.        and techniques for transforming interpreters to allow
  1285.        their implementation in terms of any low-level language.
  1286.        Also discusses scanners, parsers, and the derivation of
  1287.        a compiler and virtual machine from an interpreter.
  1288.        Source files available by anonymous ftp from cs.indiana.edu
  1289.        in the directory /pub/eopl (129.79.254.191).
  1290.  
  1291.    7. Peter Lee, editor, "Topics in Advanced Language Implementation",
  1292.       The MIT Press, Cambridge, Mass., 1991.
  1293.        Articles relevant to the implementation of functional
  1294.        programming languages.
  1295.  
  1296.    8. Also see the proceedings of the biannual ACM Lisp and Functional
  1297.       Programming conferences, the implementation notes for CMU Common Lisp,
  1298.       Norvig's book, and SICP (Abelson & Sussman).
  1299.  
  1300. ----------------------------------------------------------------
  1301. Subject: [1-5]    What does CLOS, PCL, X3J13, CAR, CDR, ... mean? 
  1302.  
  1303. Glossary of acronyms:
  1304.    CAR           Originally meant "Contents of Address portion of Register",
  1305.            which is what CAR actually did on the IBM 704.
  1306.    CDR           Originally meant "Contents of Decrement portion of 
  1307.            Register", which is what CDR actually did
  1308.            on the IBM 704. Pronounced "Cudder".
  1309.    LISP           Originally from "LISt Processing"
  1310.    GUI           Graphical User Interface
  1311.    CLOS           Common Lisp Object System. The object oriented
  1312.            programming standard for Common Lisp. Based on
  1313.            Symbolics FLAVORS and Xerox LOOPS, among others.
  1314.            Pronounced either as "See-Loss" or "Closs". See also PCL.
  1315.    PCL           Portable Common Loops. A portable CLOS implementation.
  1316.            Available by anonymous ftp from parcftp.xerox.com:pcl/.
  1317.    LOOPS       Lisp Object Oriented Programming System. A predecessor
  1318.            to CLOS on Xerox Lisp machines.
  1319.    X3J13       Subcommittee of the ANSI committee X3 which is
  1320.            working on the ANSI Standardization of Common Lisp.
  1321.    ANSI           American National Standards Institute
  1322.    CL           Common Lisp
  1323.    SC22/WG16       The full name is ISO/IEC JTC 1/SC 22/WG 16. It stands
  1324.            for International Organization for
  1325.            Standardization/International Electronics(?)     
  1326.            Congress(?) Joint Technical Committee 1, Subcommittee 22,
  1327.            Working Group 16.  This long-winded name is the ISO
  1328.            working group working on an international Lisp standard,
  1329.            (i.e., the ISO analogue to X3J13).
  1330.    CLtL1       First edition of Guy Steele's book, 
  1331.            "Common Lisp the Language". 
  1332.    CLtL2       Second edition of Guy Steele's book,
  1333.            "Common Lisp the Language". 
  1334.  
  1335. ----------------------------------------------------------------
  1336. Subject: [1-6] Lisp Job Postings
  1337.  
  1338. The LISP-JOBS mailing list exists to help programmers find Lisp
  1339. programming positions, and to help companies with Lisp programming
  1340. positions find capable Lisp programmers. (Lisp here means Lisp-like
  1341. languages, including Scheme.)
  1342.  
  1343. Material appropriate for the list includes Lisp job announcements and
  1344. should be sent to lisp-jobs@anzus.com.  Administrative requests (e.g.,
  1345. to be added to the list) should be sent to lisp-jobs-request@anzus.com.
  1346.  
  1347. ----------------------------------------------------------------
  1348.  
  1349. ;;; *EOF*
  1350.