home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / lisp / 2215 < prev    next >
Encoding:
Internet Message Format  |  1992-08-13  |  33.9 KB

  1. Xref: sparky comp.lang.lisp:2215 news.answers:2476
  2. Path: sparky!uunet!elroy.jpl.nasa.gov!usc!rpi!uwm.edu!ogicse!das-news.harvard.edu!cantaloupe.srv.cs.cmu.edu!crabapple.srv.cs.cmu.edu!mkant
  3. From: mkant+@cs.cmu.edu (Mark Kantrowitz)
  4. Newsgroups: comp.lang.lisp,news.answers
  5. Subject: FAQ: Lisp Frequently Asked Questions 1/5 [Monthly posting]
  6. Summary: Introductory Matter and Bibliography of Introductions and References
  7. Message-ID: <lisp-faq-1.text_713752615@cs.cmu.edu>
  8. Date: 14 Aug 92 00:37:11 GMT
  9. Article-I.D.: cs.lisp-faq-1.text_713752615
  10. Expires: Sun, 27 Sep 1992 00:36:55 GMT
  11. Sender: news@cs.cmu.edu (Usenet News System)
  12. Reply-To: lisp-faq@think.com
  13. Followup-To: poster
  14. Organization: School of Computer Science, Carnegie Mellon
  15. Lines: 769
  16. Approved: news-answers-request@MIT.Edu
  17. Supersedes: <lisp-faq-1.text_711014458@cs.cmu.edu>
  18. Nntp-Posting-Host: a.gp.cs.cmu.edu
  19.  
  20. Archive-name: lisp-faq/part1
  21. Last-Modified: Thu Aug  6 11:54:55 1992 by Mark Kantrowitz
  22. Version: 1.23
  23.  
  24. ;;; ****************************************************************
  25. ;;; Answers to Frequently Asked Questions about Lisp ***************
  26. ;;; ****************************************************************
  27. ;;; Written by Mark Kantrowitz and Barry Margolin
  28. ;;; lisp-faq-1.text -- 34247 bytes
  29.  
  30. This post contains Part 1 of the Lisp FAQ.
  31.  
  32. If you think of questions that are appropriate for this FAQ, or would
  33. like to improve an answer, please send email to us at lisp-faq@think.com.
  34.  
  35. Note that the lisp-faq mailing list is for discussion of the content
  36. of the FAQ posting.  It is not the place to ask questions about Lisp;
  37. use either the common-lisp@ai.sri.com mailing list or the
  38. comp.lang.lisp newsgroup for that.  If a question appears frequently
  39. in one of those forums, it will get added to the FAQ list.
  40.  
  41. There are currently five parts to the Lisp FAQ:
  42.    1. Introductory Matter and Bibliography of Introductions and References
  43.    2. General Questions
  44.    3. Common Pitfalls
  45.    4. Lisp/Scheme Implementations and Mailing Lists
  46.    5. CLOS and PCL Questions
  47. Part 4 is cross-posted to the comp.lang.scheme newsgroup. Part 5 is
  48. cross-posted to the comp.lang.clos newsgroup.
  49.  
  50. Topics Covered (Part 1):
  51.  
  52.   [1-0]      What is the purpose of this newsgroup?
  53.   [1-1]      What documentation is available on Lisp? How can I learn Lisp?
  54.   [1-2]      How can I improve my Lisp programming style and coding efficiency?
  55.   [1-3]      Where can I learn about implementing Lisp interpreters and compilers?
  56.   [1-4]      What does CLOS, PCL, X3J13, CAR, CDR, ... mean? 
  57.  
  58. Topics Covered (Part 2):
  59.  
  60.   [2-0]   What FTP resources are available?
  61.   [2-1]   Is there a GNU-Emacs interface to Lisp?
  62.   [2-2]   How can I use the X Window System or other GUIs from Lisp?
  63.   [2-3]   When is it right to use EVAL?
  64.   [2-4]   What is the equivalent of EXPLODE and IMPLODE in Common Lisp?
  65.   [2-5]   Is Lisp inherently slower than more conventional languages such as C?
  66.   [2-6]   Why does my program's behavior change each time I use it?
  67.   [2-7]   Why does Common Lisp have "#'"?
  68.   [2-8]   How do I call non-Lisp functions from Lisp?
  69.   [2-9]   Can I call Lisp functions from other languages?
  70.   [2-10]  I want to call a function in a package that might not exist at
  71.           compile time. How do I do this?  
  72.   [2-11]  What is CDR-coding?
  73.   [2-12]  What is garbage collection?
  74.   [2-13]  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-14]  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-15]  History: Where did Lisp come from?
  81.   [2-16]  How do I find the argument list of a function?
  82.   [2-17]  How can I have two Lisp processes communicate via unix sockets?
  83.   [2-18]  When producing formatted output in Lisp, where should you put the
  84.           newlines (e.g., before or after the line, FRESH-LINE vs TERPRI,
  85.           ~& vs ~% in FORMAT)?
  86.  
  87. Common Pitfalls (Part 3):
  88.  
  89.   [3-0]     Why does (READ-FROM-STRING "foobar" :START 3) return FOOBAR
  90.      instead of BAR?  
  91.   [3-1]     Why can't it deduce from (READ-FROM-STRING "foobar" :START 3)
  92.      that the intent is to specify the START keyword parameter
  93.      rather than the EOF-ERROR-P and EOF-VALUE optional parameters?      
  94.   [3-2]     Why can't I apply #'AND and #'OR?
  95.   [3-3]     I used a destructive function (e.g. DELETE, SORT), but it
  96.      didn't seem to work.  Why? 
  97.   [3-4]     After I NREVERSE a list, it's only one element long.  After I
  98.      SORT a list, it's missing things.  What happened? 
  99.   [3-5]     Why does (READ-LINE) return "" immediately instead of waiting
  100.      for me to type a line?     
  101.   [3-6]     I typed a form to the read-eval-print loop, but nothing happened. Why?
  102.   [3-7]     DEFMACRO doesn't seem to work.
  103.      When I compile my file, LISP warns me that my macros are undefined
  104.      functions, or complains "Attempt to call <function> which is 
  105.      defined as a macro.
  106.   [3-8]     Name conflict errors are driving me crazy! (EXPORT, packages)
  107.   [3-9]     Closures don't seem to work properly when referring to the
  108.      iteration variable in DOLIST, DOTIMES and DO.
  109.   [3-10] What is the difference between FUNCALL and APPLY?
  110.   [3-11] Miscellaneous things to consider when debugging code.
  111.  
  112. Lisp/Scheme Implementations and Mailing Lists (Part 4):
  113.  
  114.   [4-0]      Where can I get/buy Lisp and Scheme for the ... architecture?
  115.   [4-1]      Where can I get an implementation of Prolog in Lisp?
  116.   [4-2]   What is Dylan?
  117.   [4-3]      What Lisp-related discussion groups and mailing lists exist?
  118.  
  119. CLOS Questions (Part 5):
  120.  
  121.   [5-0]      What is CLOS (PCL) and where can I get it?
  122.       How do you pronounce CLOS?
  123.   [5-1]      What documentation is available about object-oriented
  124.       programming in Lisp?    
  125.   [5-2]      How I write a function that can access defstruct slots by
  126.       name?     I would like to write something like 
  127.       (STRUCTURE-SLOT <object> '<slot-name>).   
  128.   [5-3]      How can I list all the CLOS instances in a class?
  129.   [5-4]   How can I store data and CLOS instances (with possibly circular
  130.       references) on disk so that they may be retrieved at some later
  131.       time?
  132.   [5-5]   Given the name of a class, how can I get the names of its slots?
  133.  
  134.  
  135. Search for [#] to get to question number # quickly.
  136.  
  137.  
  138. Introduction:
  139.  
  140. Certain questions and topics come up frequently in the various network
  141. discussion groups devoted to and related to Lisp.  This file/article is
  142. an attempt to gather these questions and their answers into a convenient
  143. reference for Lisp programmers.     It (or a reference to it) is posted
  144. periodically.  The hope is that this will cut down on the user time and
  145. network bandwidth used to post, read and respond to the same questions
  146. over and over, as well as providing education by answering questions
  147. some readers may not even have thought to ask.
  148.  
  149. This is not a Lisp tutorial, nor is it an exhaustive list of all Lisp
  150. intricacies.  Lisp is a very powerful and expressive language, but with
  151. that power comes many complexities.  This list attempts to address the
  152. ones that average Lisp programmers are likely to encounter.  If you are
  153. new to Lisp, see the answer to the question "How can I learn Lisp?".
  154.  
  155. The latest version of this file is available via anonymous FTP from CMU
  156. and Thinking Machines: 
  157.  
  158.    To obtain the files from CMU, connect by anonymous ftp to any CMU CS
  159.    machine (e.g., ftp.cs.cmu.edu [128.2.206.173]), using username
  160.    "anonymous" and password "name@host". The files lisp-faq-1.text,
  161.    lisp-faq-2.text, lisp-faq-3.text, lisp-faq-4.text and lisp-faq-5.text
  162.    are located in the directory
  163.        /afs/cs.cmu.edu/user/mkant/Public/Lisp-Utilities/
  164.    [Note: You must cd to this directory in one atomic operation, as
  165.    some of the superior directories on the path are protected from
  166.    access by anonymous ftp.] If your site runs the Andrew File System,
  167.    you can just cp the files directly without bothering with FTP.
  168.  
  169.    To obtain the files from Thinking Machines, ftp them from ftp.think.com,
  170.    in the directory /public/think/lisp/. The file faq.text contains all the
  171.    parts of the FAQ in one file. In addition, specific versions of the FAQ
  172.    are available as faq-<version>.text.
  173.  
  174. Unless otherwise specified, the Lisp dialect referred to is Common Lisp,
  175. as defined by "Common Lisp: the Language" (aka "CLtL") as well as
  176. corrections (but not enhancements) from "Common Lisp: the Language, 2nd
  177. Edition" (aka "CLtL2"), both by Guy L. Steele, Jr. and published by
  178. Digital Press. Enhancements such as CLOS, conditions, and the LOOP
  179. macro will be referred to separately.
  180.  
  181. ----------------------------------------------------------------
  182. [1-0] What is the purpose of this newsgroup?
  183.  
  184. The newsgroup comp.lang.lisp exists for general discussion of
  185. topics related to the programming language Lisp. For example, possible
  186. topics can include (but are not necessarily limited to):
  187.    announcements of Lisp books and products
  188.    discussion of programs and utilities written in Lisp
  189.    discussion of portability issues
  190.    questions about possible bugs in Lisp implementations
  191.    problems porting an implementation to some architecture
  192. Postings should be of general interest to the Lisp community. See also
  193. question [4-2].
  194.  
  195. Questions about object oriented programming in Lisp should be directed
  196. to the newsgroup comp.lang.clos. Similarly, questions about the
  197. programming language Scheme should be directed to the newsgroup
  198. comp.lang.scheme. Discussion of AI programs implemented in Lisp should
  199. sometimes be cross-posted to the newsgroup comp.ai.
  200.  
  201. ----------------------------------------------------------------
  202. [1-1] What documentation is available on Lisp? 
  203.       How can I learn Lisp?
  204.  
  205. There are several good Lisp introductions and tutorials:
  206.  
  207.    1. David S. Touretzky
  208.       "Common Lisp: A Gentle Introduction to Symbolic Computation"
  209.       Benjamin/Cummings Publishers, 1990. 384 pages.
  210.        Perhaps the best tutorial introduction to the language. It has
  211.        clear and correct explanations, and covers some fairly advanced
  212.        topics. The book is an updated Common Lisp version of the 1984
  213.        edition published by Harper and Row Publishers.
  214.  
  215.    2. Robert Wilensky
  216.       "Common LISPcraft"
  217.       W. W. Norton, 1986. 385 pages.
  218.  
  219.    3. Wade L. Hennessey 
  220.       "Common Lisp"
  221.       McGraw-Hill, 1989. 395 pages.
  222.        Fairly good, but jumps back and forth from the simple to the
  223.        complex rather quickly, with no clear progression in difficulty.
  224.  
  225.    4. Laurent Siklossy
  226.       "Let's Talk LISP"
  227.       Prentice-Hall, NJ, 1976. 237 pages.
  228.        Good introduction, but quite out of date.
  229.  
  230.    5. Stuart C. Shapiro
  231.       "Common Lisp: An Interactive Approach"
  232.       Computer Science Press/W.H. Freeman, New York, 1992.
  233.       ISBN 0-7167-8218-9
  234.  
  235. Other introductions to Lisp include:
  236.  
  237.    1. A. A. Berk.
  238.       "LISP, The Language of Artificial Intelligence"
  239.       Van Nostrand Reinhold, 1985. 160 pages.
  240.  
  241.    2. Paul Y. Gloess.
  242.       "An Alfred handy guide to Understanding LISP"
  243.       Alfred Publishers (Sherman Oaks, CA), 1982. 64 pages.
  244.  
  245.    3. Ward D. Maurer.
  246.       "The Programmer's Introduction to LISP"
  247.       American Elsevier, 1972. 112 pages.
  248.  
  249.    4. Hank Bromley and Richard Lamson.
  250.       "LISP Lore: A Guide to Programming the LISP Machine"
  251.       Kluwer Academic (Boston), 1987. 337 pages.
  252.  
  253.    5. Sharam Hekmatpour.
  254.       "Introduction to LISP and Symbol Manipulation"
  255.       Prentice Hall (New York), 1988. 303 pages.
  256.  
  257.    6. Deborah G. Tatar
  258.       "A programmer's guide to Common Lisp"
  259.       Digital Press, 1987. 327 pages. ISBN 0-932376-87-8.
  260.        Good introduction on Common Lisp.
  261.  
  262. More advanced introductions to Lisp and its use in Artificial
  263. Intelligence include:
  264.  
  265.    1. Peter Norvig.
  266.       "Paradigms of AI Programming: Case Studies in Common Lisp"
  267.       Morgan Kaufmann, 1992. 946 pages. ISBN 1-55860-191-0.
  268.  
  269.     Provides an in-depth exposition of advanced AI programming techniques
  270.     and includes large-scale detailed examples. The book is the most
  271.     advanced AI/Common-Lisp programming text and reference currently
  272.     available, and hence is not for the complete novice.  It focuses on the
  273.     programming techniques necessary for building large AI systems,
  274.     including object-oriented programming, and has a strong performance
  275.     orientation.
  276.  
  277.     The text is marked by its use of "non-toy" examples to illustrate the
  278.     techniques. All of the examples are written in Common Lisp, and copies
  279.     of the source code are available by anonymous ftp from
  280.     unix.sri.com:pub/norvig and on disk in Macintosh or DOS format from
  281.     the publisher. Some of the techniques described include rule-based
  282.     pattern matching (GPS, Eliza, a subset of Macsyma, the Emycin expert
  283.     system shell), constraint propagation and backtracking (Waltz
  284.     line-labelling), alpha-beta search (Othello), natural language
  285.     processing (top-down, bottom-up and chart parsing), logic-programming
  286.     (unification and Prolog), interpreters and compilers for Scheme, and
  287.     object-oriented programming (CLOS).
  288.  
  289.     The examples are also used to illustrate good programming style and
  290.     efficiency. There is a guide to trouble-shooting and debugging Lisp
  291.     programs, a style guide, and a discussion of portability problems.
  292.     Some of the efficiency techniques described include memoization,
  293.     data indexing, compilation, delaying computation, proper use of
  294.     declarations, avoiding garbage collection, and choosing and using the
  295.     correct data structure.
  296.  
  297.     The book also serves as an advanced introduction to Common Lisp, with
  298.     sections on the Loop macro, CLOS and sequences, and some coverage of 
  299.     error handling, series, and the package facility.
  300.  
  301.    2. Eugene Charniak, Christopher K. Riesbeck, Drew V. McDermott
  302.       and James R. Meehan.
  303.       "Artificial Intelligence Programming", 2nd edition.
  304.       Lawrence Erlbaum Associates (Hillsdale, NJ), 1987. 533 pages.
  305.        Provides many nice code fragments, all of which are written
  306.        in Common Lisp. The first half of the book covers topics
  307.        like macros, the reader, data structures, control structures,
  308.        and defstructs. The second half of the book describes
  309.        programming techniques specific to AI, such as
  310.        discrimination nets, production systems, deductive database
  311.        retrieval, logic programming, and truth maintenance.
  312.  
  313.    3. Patrick H. Winston and Berthold K. P. Horn.
  314.       "LISP", 3rd edition.
  315.       Addison-Wesley (Reading, MA), 1989. 611 pages. ISBN 0-201-08319-1
  316.        Covers the basic concepts of the language, but also gives a lot
  317.        of detail about programming AI topics such as rule-based expert
  318.        systems, forward chaining, interpreting transition trees, 
  319.        compiling transition trees and finding patterns in images. Not 
  320.        a tutorial. Has many good examples.
  321.  
  322.    4. Rodney A. Brooks.
  323.       "Programming in Common Lisp"
  324.       Wiley, 1985. 303 pages.
  325.  
  326.    5. John R. Anderson, Albert T. Corbett, and Brian J. Reiser.
  327.       "Essential LISP"
  328.       Addison-Wesley (Reading, MA), 1987. 352 pages.
  329.        Concentrates on how to use Lisp with iteration and recursion.
  330.  
  331.    6. Robert D. Cameron and Anthony H. Dixon
  332.       "Symbolic Computing with Lisp"
  333.       Prentice-Hall, 1992, 326 pages. ISBN 0-13-877846-9.
  334.        The book is intended primarily as a third-year computer science
  335.        text. In terms of programming techniques, it emphasizes recursion
  336.        and induction, data abstraction, grammar-based definition of Lisp
  337.        data structures and functional programming style. It uses
  338.        two Lisp languages: 
  339.         (1) a purely functional subset of Lisp called Small Lisp and
  340.         (2) Common Lisp.
  341.        An MS-DOS interpreter for Small Lisp (including source) is
  342.        provided with the book.  It considers applications of Lisp
  343.        to formal symbolic data domains: algebraic expressions,
  344.        logical formulas, grammars and programming languages. 
  345.  
  346.    7. Hasemer and Domingue.
  347.       "Common Lisp Programming for Artificial Intelligence"
  348.       Addison-Wesley, 1989.
  349.  
  350. General Lisp reference books include:
  351.  
  352.    1. Guy L. Steele
  353.       "Common Lisp: The Language" [CLtL1]
  354.       Digital Press, 1984. 465 pages. ISBN 0-932376-41-X.
  355.  
  356.    2. Guy L. Steele
  357.       "Common Lisp: The Language, 2nd Edition" [CLtL2]
  358.       Digital Press, 1990. 1029 pages. ISBN 1-55558-041-6.
  359.  
  360.    3. Franz Inc. 
  361.       "Common Lisp: The Reference"
  362.       Addison-Wesley, Reading, MA 1988. ISBN 0-201-11458-5
  363.        Entries on lisp functions in alphabetical order.
  364.  
  365.    4. K. Dybvig. 
  366.       "The Scheme programming language"
  367.       Prentice Hall, 1987.
  368.      Good reference for Scheme.
  369.  
  370. Lisp periodicals include:
  371.     
  372.    1. LISP Pointers.
  373.       Published by ACM SIGPLAN six times a year. Volume 1, Number 1
  374.       was April-May 1987. 
  375.  
  376.    2. LISP and Symbolic Computation, Kluwer Academic Press. Volume 1
  377.       was published in 1989. (jlz@lucid.com is the editor).
  378.  
  379.    3. Proceedings of the biannual ACM Lisp and Functional Programming
  380.       Conference. (First one was in 1980.)
  381.  
  382.    4. Proceedings of the annual Lisp Users and Vendors Conference.
  383.  
  384. Introductions to Scheme (Many books on Scheme are worth reading
  385. even if you use Common Lisp, because many of the issues are similar):
  386.  
  387.    1. Harold Abelson and Gerald Jay Sussman, with Julie Sussman.
  388.       "Structure and Interpretation of Computer Programs"
  389.       MIT Press (Cambridge, MA) and McGraw-Hill (New York), 1985.
  390.       542 pages. ISBN 0-262-01077-1
  391.        Starts off introductory, but rapidly gets into powerful
  392.        Lisp-particular constructs, such as using closures and
  393.        engines, building interpreters, compilers and
  394.        object-oriented systems.  
  395.  
  396.    2. Daniel P. Friedman and M. Felleisen.
  397.       "The Little LISPer"
  398.       Science Research Associates (Chicago), 1974. 58 pages.
  399.       MIT Press (Cambridge, MA), 1987. ISBN 0-262-56038-0.
  400.        Good for a quick introduction. Uses Scheme instead of
  401.        Common Lisp.     (SRA edition uses a dialect of Scheme with
  402.        footnotes about translating to Scheme or Common Lisp. The
  403.        MIT Press edition is in Scheme without the footnotes.)
  404.  
  405.    3. George Springer and Daniel P. Friedman
  406.       "Scheme and the Art of Programming" 
  407.       MIT Press and McGraw Hill, 1989, 400 pages.
  408.       MIT Press and McGraw Hill, 1990, 596 pages.
  409.        Introduces basic concepts of programming in Scheme. Also deals 
  410.        with object oriented programming, co-routining, continuations. 
  411.  
  412.    4. Wolfgang Kreutzer and Bruce McKenzie
  413.       "Programming for Artificial Intelligence: 
  414.        Methods, Tools and Applications"
  415.       Addison-Wesley (Reading, MA), 1990. 682 pages. 
  416.       ISBN 0-201-41621-2.
  417.        Discusses Scheme, Prolog, and Smalltalk, gives an overview of
  418.        the history and philosophy of AI, surveys three major
  419.        programming paradigms (procedural, declarative, and
  420.        object-oriented), and metaphors to AI programming.
  421.  
  422.    5. Smith
  423.       "Introduction to Scheme"
  424.        1988.
  425.        Focuses on PC Scheme.
  426.  
  427.    6. Michael Eisenberg 
  428.       "Programming in Scheme"
  429.       Scientific Press (Redwood City, CA), 1988. 304 pages.
  430.  
  431. ----------------------------------------------------------------
  432. [1-2] How can I improve my Lisp programming style and coding efficiency?
  433.  
  434. There are several books about Lisp programming style, including:
  435.    
  436.    1. Molly M. Miller and Eric Benson
  437.       "Lisp Style and Design"
  438.       Digital Press, 1990. 214 pages. ISBN 1-55558-044-0.
  439.        How to write large Lisp programs and improve Lisp programming 
  440.        style. Uses the development of Lucid CL as an example. 
  441.  
  442.    2. Robin Jones, Clive Maynard, and Ian Stewart.
  443.       "The Art of Lisp Programming"
  444.       Springer-Verlag, 1989. 169 pages.
  445.  
  446.    3. W. Richard Stark.
  447.       "LISP, Lore, and Logic: an algebraic view of LISP
  448.        programming, foundations, and applications"
  449.       Springer-Verlag, 1990. 278 pages. ISBN 0-387-97072-X
  450.        Self-modifying code, self-reproducing programs, etc.
  451.  
  452.    4. CMU CL User's Manual, Chapter 7, (talks about writing
  453.       efficient code). It is available by anonymous ftp from any CMU CS 
  454.       machine (e.g., ftp.cs.cmu.edu [128.2.206.173]) as the file
  455.     /afs/cs.cmu.edu/project/clisp/docs/cmu-user/cmu-user.ps 
  456.       [when getting this file by anonymous ftp, one must cd to 
  457.       the directory in one atomic operation, as some of the superior
  458.       directories on the path are protected from access by anonymous ftp.]
  459.  
  460.    5. See also Norvig's book, SICP (Abelson & Sussman), SAP
  461.       (Springer and Friedman).
  462.  
  463. Here are some general suggestions/notes about improving Lisp
  464. programming style, readability, correctness and efficiency:
  465.  
  466.    Functions often abused or misunderstood by novices: 
  467.  
  468.       - EVAL
  469.  
  470.       - PROGV. PROGV modifies the dynamic bindings of variables and
  471.     is often misused in conjunction with EVAL, which uses the
  472.     dynamic environment. In general, avoid unnecessary use of
  473.     special variables.
  474.  
  475.       - CATCH and THROW. Often a named BLOCK and RETURN-FROM are
  476.     more appropriate.
  477.  
  478.       - Destructive operations, such as NCONC, SORT, DELETE,
  479.     RPLACA, and RPLACD, should be used carefully and sparingly.
  480.     In general, trust the garbage collector: allocate new
  481.     data structures when you need them.
  482.  
  483.    Think twice before using any of these functions.
  484.  
  485.    To improve the readability of your code,
  486.  
  487.       - Don't use any C{A,D}R functions with more than two
  488.     letters between the C and the R. When nested, they become
  489.     hard to read. If you have complex data structures, you
  490.     are often better off describing them with a DEFSTRUCT,
  491.     even if the type is LIST. If you must use C{A,D}R, try to
  492.     use destructuring-bind instead, or at least SECOND, THIRD,
  493.     NTH, NTHCDR, etc.
  494.  
  495.       - Use COND instead of IF and PROGN. In general, don't use PROGN if
  496.     there is a way to write the code within an implicit
  497.     progn. For example, 
  498.        (if (foo x)
  499.            (progn (print "hi there") 23)
  500.            34)
  501.     should be written using COND instead.
  502.  
  503.       - Never use a 2-argument IF or a 3-argument IF with second
  504.     argument NIL unless you want to emphasize the return value;
  505.     use WHEN and UNLESS instead.
  506.  
  507.       - Use backquote, rather than explicit calls to LIST, CONS, and
  508.     APPEND, whenever writing a form which produces a Lisp form.
  509.  
  510.       - Make the names of special (global) variables start and end
  511.     with an asterisk (*).
  512.  
  513.    Stylistic preferences:
  514.  
  515.       - Use (SETF (CAR ..) ..) and (SETF (CDR ..) ..) in preference to
  516.     RPLACA and RPLACD.
  517.  
  518.       - Many programmers religiously avoid using CATCH, THROW, BLOCK,
  519.     PROG, and TAGBODY.  
  520.  
  521.    Correctness and efficiency issues:
  522.  
  523.       - The ARRAY-TOTAL-SIZE-LIMIT may be as small as 1024, and the
  524.         CALL-ARGUMENTS-LIMIT may be as small as 50.
  525.  
  526.       - Avoid using APPLY to flatten lists. (apply #'append list-of-lists)
  527.     is compiled into a function call, and can run into problems with
  528.     the CALL-ARGUMENTS-LIMIT. Use REDUCE or MAPCAR instead:
  529.        (reduce #'append list-of-lists :from-end t)
  530.        (mapcan #'copy-list list-of-lists)
  531.     The second will often be more efficient (see note below about choosing
  532.     the right algorithm).
  533.  
  534.       - NTH must cdr down the list to reach the elements you are
  535.     interested in. If you don't need the structural flexibility of
  536.     lists, try using vectors and the ELT function instead.
  537.  
  538.       - Don't use quoted constants where you might later destructively
  539.     modify them. For example, instead of writing '(c d) in
  540.        (defun foo ()
  541.          (let ((var '(c d)))
  542.            ..))
  543.     write (list 'c 'd) instead. Using a quote here can lead to
  544.     unexpected results later. If you later destructively modify the 
  545.     value of var, this is self-modifying code! Some Lisp compilers
  546.     will complain about this, since they like to make constants
  547.     read-only. Modifying constants has undefined results in ANSI CL.
  548.     See also the answer to question [2-7].
  549.  
  550.     Similarly, beware of shared list structure arising from the use
  551.     of backquote. Any sublist in a backquoted expression that doesn't
  552.     contain any commas can share with the original source structure.
  553.  
  554.       - Don't proclaim unsafe optimizations, such as
  555.        (proclaim '(optimize (safety 0) (speed 3) (space 1))) 
  556.     since this yields a global effect. Instead, add the
  557.     optimizations as local declarations to small pieces of
  558.     well-tested, performance-critical code:
  559.        (defun well-tested-function ()
  560.           (declare (optimize (safety 0) (speed 3) (space 1)))
  561.          ..)
  562.     Such optimizations can remove run-time type-checking, which
  563.     is necessary unless you've very carefully checked your code
  564.     and added all the appropriate type declarations.
  565.  
  566.       - Don't add declarations to code until it is fully debugged.
  567.     Incorrect declarations can be an annoying source of errors.
  568.     Use CHECK-TYPE liberally while developing code, if you later
  569.     intend to add declarations.
  570.  
  571.    To produce efficient code,
  572.  
  573.       - choose the right algorithm. For example, consider seven possible
  574.     implementations of COPY-LIST:
  575.  
  576.        (defun copy-list (list)
  577.          (let ((result nil))
  578.            (dolist (item list result)
  579.          (setf result (append result (list item))))))
  580.  
  581.        (defun copy-list (list)
  582.          (let ((result nil))
  583.            (dolist (item list (nreverse result))
  584.          (push item result))))
  585.  
  586.        (defun copy-list (list)
  587.          (mapcar #'identity list))
  588.  
  589.        (defun copy-list (list)
  590.          (let ((result (make-list (length list))))
  591.            (do ((original list (cdr original))
  592.             (new result (cdr new)))
  593.            ((null original) result)
  594.          (setf (car new) (car original)))))
  595.  
  596.        (defun copy-list (list)
  597.          (when list
  598.            (let* ((result (list (car list)))
  599.               (tail-ptr result))
  600.          (dolist (item (cdr list) result)
  601.            (setf (cdr tail-ptr) (list item))
  602.            (setf tail-ptr (cdr tail-ptr))))))
  603.     
  604.         (defun copy-list (list)
  605.           (loop for item in list collect item))
  606.  
  607.         (defun copy-list (list)
  608.           (if (consp list) 
  609.           (cons (car list)
  610.             (copy-list (cdr list)))
  611.           list))
  612.  
  613.     The first uses APPEND to tack the elements onto the end of the list.
  614.     Since APPEND must traverse the entire partial list at each step, this
  615.     yields a quadratic running time for the algorithm.  The second
  616.     implementation improves on this by iterating down the list twice; once
  617.     to build up the list in reverse order, and the second time to reverse
  618.     it. The efficiency of the third depends on the Lisp implementation,
  619.     but it is usually similar to the second, as is the fourth.  The fifth
  620.     algorithm, however, iterates down the list only once. It avoids the
  621.     extra work by keeping a pointer (reference) to the last cons of the 
  622.     list and RPLACDing onto the end of that. Use of the fifth algorithm 
  623.     may yield a speedup. Note that this contradicts the earlier dictum to
  624.     avoid destructive functions. To make more efficient code one might
  625.     selectively introduce destructive operations in critical sections of
  626.     code. Nevertheless, the fifth implementation may be less efficient in
  627.     Lisps with cdr-coding, since it is more expensive to RPLACD cdr-coded
  628.     lists. Depending on the implementation of nreverse, however,
  629.     the fifth and second implementations may be doing the same
  630.     amount of work. The sixth example uses the Loop macro, which usually
  631.     expands into code similar to the third. The seventh example copies
  632.     dotted lists, and runs in linear time. It's equivalent to the other
  633.     linear-time examples in a lisp that is properly tail-recursive. To
  634.     get an implementation of copy-tree, replace (car list) with
  635.     (copy-list (car list)).
  636.  
  637.       - use type declarations liberally in time-critical code, but
  638.     only if you are a seasoned Lisp programmer. Appropriate type
  639.     declarations help the compiler generate more specific and
  640.     optimized code. It also lets the reader know what assumptions
  641.     were made. For example, if you only use fixnum arithmetic,
  642.     adding declarations can lead to a significant speedup. If you
  643.     are a novice Lisp programmer, you should use type declarations
  644.     sparingly, as there may be no checking to see if the
  645.     declarations are correct. Wrong declarations can lead to errors
  646.     in otherwise correct code, and can limit the reuse of code
  647.     in other contexts. Depending on the Lisp compiler, it may also
  648.     be necessary to declare the type of results using THE, since
  649.     some compilers don't deduce the result type from the inputs.
  650.  
  651.       - check the code produced by the compiler by using the
  652.     disassemble function
  653.  
  654. ----------------------------------------------------------------
  655. [1-3] Where can I learn about implementing Lisp interpreters and compilers?
  656.  
  657. Books about Lisp implementation include:
  658.  
  659.    1. John Allen
  660.       "Anatomy of Lisp"
  661.       McGraw-Hill, 1978. 446 pages. ISBN 0-07-001115-X
  662.  
  663.    2. Samuel Kamin
  664.       "Programming Languages, An Interpreter-Based Approach"
  665.       Addison-Wesley. ISBN 0-201-06824-9
  666.        Includes sources to several interpreters for Lisp-like
  667.        languages, and a pointer to sources via anonymous ftp.
  668.  
  669.    3. Sharam Hekmatpour
  670.       "Lisp: A Portable Implementation"
  671.       Prentice Hall, 1985. ISBN 0-13-537490-X.
  672.        Describes a portable implementation of a small dynamic
  673.        Lisp interpreter (including C source code). 
  674.  
  675.    4. Peter Henderson
  676.       "Functional Programming: Application and Implementation"
  677.       Prentice-Hall (Englewood Cliffs, NJ), 1980. 355 pages.
  678.  
  679.    5. Peter M. Kogge
  680.       "The Architecture of Symbolic Computers"
  681.       McGraw-Hill, 1991. ISBN 0-07-035596-7.
  682.        Includes sections on memory management, the SECD and
  683.        Warren Abstract Machines, and overviews of the various
  684.        Lisp Machine architectures.
  685.    
  686.    6. Daniel P. Friedman, Mitchell Wand, and Christopher T. Haynes
  687.       "Essentials of Programming Languages"
  688.       MIT Press, 1992, 536 pages. ISBN 0-262-06145-7.
  689.        Teaches fundamental concepts of programming language
  690.        design by using small interpreters as examples. Covers
  691.        most of the features of Scheme. Includes a discussion
  692.        of parameter passing techniques, object oriented languages,
  693.        and techniques for transforming interpreters to allow
  694.        their implementation in terms of any low-level language.
  695.        Also discusses scanners, parsers, and the derivation of
  696.        a compiler and virtual machine from an interpreter.
  697.  
  698.    7. Also see the proceedings of the biannual ACM Lisp and
  699.       Functional Programming conferences, and the implementation
  700.       notes for CMU Common Lisp.
  701. ----------------------------------------------------------------
  702. [1-4]  What does CLOS, PCL, X3J13, CAR, CDR, ... mean? 
  703.  
  704. Glossary of acronyms:
  705.    CAR           Originally meant "Contents of Address portion of Register",
  706.            which is what CAR actually did on the IBM 704.
  707.    CDR           Originally meant "Contents of Decrement portion of 
  708.            Register", which is what CDR actually did
  709.            on the IBM 704. Pronounced "Cudder".
  710.    LISP           Originally from "LISt Processing"
  711.    GUI           Graphical User Interface
  712.    CLOS           Common Lisp Object System. The object oriented
  713.            programming standard for Common Lisp. Based on
  714.            Symbolics FLAVORS and Xerox LOOPS, among others.
  715.            Pronounced either as "See-Loss" or "Closs". See also PCL.
  716.    PCL           Portable Common Loops. A portable CLOS implementation.
  717.            Available by anonymous ftp from parcftp.xerox.com:pcl/.
  718.    LOOPS       Lisp Object Oriented Programming System. A predecessor
  719.            to CLOS on Xerox Lisp machines.
  720.    X3J13       Subcommittee of the ANSI committee X3 which is
  721.            working on the ANSI Standardization of Common Lisp.
  722.    ANSI           American National Standards Institute
  723.    CL           Common Lisp
  724.    SC22/WG16       The full name is ISO/IEC JTC 1/SC 22/WG 16. It stands
  725.            for International Organization for
  726.            Standardization/International Electronics(?)     
  727.            Congress(?) Joint Technical Committee 1, Subcommittee 22,
  728.            Working Group 16.  This long-winded name is the ISO
  729.            working group working on an international Lisp standard,
  730.            (i.e., the ISO analogue to X3J13).
  731.    CLtL1       First edition of Guy Steele's book, 
  732.            "Common Lisp the Language". 
  733.    CLtL2       Second edition of Guy Steele's book,
  734.            "Common Lisp the Language". 
  735.  
  736.    SICP           Abelson and Sussman's book "Structure and
  737.            Interpretation of Computer Programs".
  738.    SCOOPS       An experimental object-oriented programming
  739.            language for Scheme.
  740.    R3RS           Revised^3 Report on the Algorithmic Language Scheme.
  741.    R4RS           Revised^4 Report on the Algorithmic Language Scheme.
  742. ----------------------------------------------------------------
  743.      
  744. ;;; ********************************
  745. ;;; Change Log *********************
  746. ;;; ********************************
  747. ;;; Date      Who     Ver   Reason
  748. ;;; ------------------------------------------------------------
  749. ;;;  7-FEB-92 mk      1.0   Initial release.
  750. ;;; 10-FEB-92 mk      1.1   Pre-release corrections and additions.
  751. ;;; 10-FEB-92 mk      1.11  Minor changes from Arun Welch, Mitch Marks, 
  752. ;;;                Mike Meyer, Matthias Felleisen, and John Gateley.
  753. ;;; 11-FEB-92 mk      1.12  Corrections by John Carroll, Jason Trenouth, Joel
  754. ;;;                Riedesel, David Neves, Lawrence Mayka and
  755. ;;;                Bruce Miller.
  756. ;;; 13-FEB-92 mk      1.13  Renumbering. Split into 3 files. Some more FAQs.
  757. ;;; 23-MAR-92 mk      1.14  Updated various FTP entries, bug in EXPLODE.
  758. ;;;                Updated harlequin entry.
  759. ;;; 25-MAR-92 mk      1.15  Added question [2-18]: saving data and CLOS
  760. ;;;                instances to disk for later retrieval.
  761. ;;;  1-MAY-92 mk      1.17  Added entry for Feel to question [1-5]. Updated CMU
  762. ;;;                ftp machines to point to ftp.cs.cmu.edu. Fixed CMU
  763. ;;;                CL entry to be approximately version independent.
  764. ;;;                         Revised entry on Garnet. uunet.uu.net -> ftp.uu.net
  765. ;;; 12-MAY-92 mk      1.18  Split questions 1-5, 1-6, and 1-7 into part 4,
  766. ;;;                         which is now cross-posted to comp.lang.scheme, and
  767. ;;;                         questions 1-8, 2-3, 2-9 and 2-18 into part 5 which
  768. ;;;                         is now cross-posted to comp.lang.clos.
  769. ;;;                         Added detail to Norvig entry in 1-1.
  770. ;;;                         Updated entries for several Lisp implementations.
  771. ;;; 26-MAY-92 mk      1.19  Changed 5-2 on the basis of comments by Jeff Greif.
  772. ;;; 29-MAY-92 mk      1.20  Added question [2-17] about lisp sockets.
  773. ;;; 16-JUN-92 mk      1.21  Moved the question about object oriented
  774. ;;;                         programming references to part 5 of the FAQ.
  775. ;;;                         Entry on Dylan. Addition to MIT Scheme entry
  776. ;;;                         regarding Schematik.
  777. ;;; 22-JUN-92 mk            Updated SOAR entry.
  778. ;;; 24-JUN-92 mk            Fixed MCL entry to note that CLIM is available 
  779. ;;;                         from ILA, not via Apple.
  780. ;;; 25-JUN-92 mk      1.22  Added question [2-18].
  781. ;;; 17-JUL-92 mk            Added entry on PSD (Portable Scheme Debugger).
  782. ;;; 20-JUL-92 mk            Updated entry on T3.1
  783. ;;; 30-JUL-92 mk            Added entry on XIT to question 2-2.
  784. ;;;  3-AUG-92 mk            Updated PC-Scheme entry (bought by Ibuki).
  785. ;;;  6-AUG-92 mk      1.23  Merged in Jeff Dalton's pitfalls list.
  786. ;;; ------------------------------------------------------------
  787.  
  788. ;;; *EOF*
  789.