home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / answers / lisp-faq / part2 < prev    next >
Encoding:
Text File  |  1993-12-12  |  43.1 KB  |  873 lines

  1. Newsgroups: comp.lang.lisp,news.answers,comp.answers
  2. Path: senator-bedfellow.mit.edu!bloom-beacon.mit.edu!news.kei.com!eff!usenet.ins.cwru.edu!gatech!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 2/7 [Monthly posting]
  5. Message-ID: <lisp_2.faq_755769752@cs.cmu.edu>
  6. Followup-To: poster
  7. Summary: Frequently asked questions about Lisp -- General Questions
  8. Sender: news@cs.cmu.edu (Usenet News System)
  9. Supersedes: <lisp_2.faq_753177695@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:02:54 GMT
  14. Approved: news-answers-request@MIT.Edu
  15. Expires: Mon, 24 Jan 1994 08:02:32 GMT
  16. Lines: 854
  17. Xref: senator-bedfellow.mit.edu comp.lang.lisp:11525 news.answers:15717 comp.answers:2969
  18.  
  19. Archive-name: lisp-faq/part2
  20. Last-Modified: Mon Nov 15 15:59:00 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_2.faq -- 43488 bytes
  28.  
  29. This post contains Part 2 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. Topics Covered (Part 2):
  35.  
  36.   [2-1]   Is there a GNU-Emacs interface to Lisp?
  37.   [2-2]   When should I use a hash table instead of an association list?
  38.   [2-3]   What is the equivalent of EXPLODE and IMPLODE in Common Lisp?
  39.   [2-4]   Is Lisp inherently slower than more conventional languages such as C?
  40.   [2-5]   Why does Common Lisp have "#'"?
  41.   [2-6]   How do I call non-Lisp functions from Lisp?
  42.   [2-7]   Can I call Lisp functions from other languages?
  43.   [2-8]   I want to call a function in a package that might not exist at
  44.           compile time. How do I do this?  
  45.   [2-9]   What is CDR-coding?
  46.   [2-10]  What is garbage collection?
  47.   [2-11]  How do I save an executable image of my loaded Lisp system?
  48.           How do I run a Unix command in my Lisp?
  49.           How do I get the current directory name from within a Lisp program?
  50.   [2-12]  I'm porting some code from a Symbolics Lisp machine to some
  51.           other platform, and there are strange characters in the code.
  52.           What do they mean?  
  53.   [2-13]  History: Where did Lisp come from?
  54.   [2-14]  How do I find the argument list of a function?
  55.           How do I get the function name from a function object?
  56.   [2-15]  How can I have two Lisp processes communicate via unix sockets?
  57.   [2-16]  How can I create a stream that acts like UNIX's /dev/null
  58.           (i.e., gobbles any output and immediately signals EOF on
  59.           input operations)?
  60.   [2-17]  Read-time conditionalization of code (#+ #- and *features*)   
  61.   [2-18]  What reader macro characters are used in major Lisp systems?
  62.  
  63. Search for \[#\] to get to question number # quickly.
  64.  
  65. ----------------------------------------------------------------
  66. Subject: [2-1] Is there a GNU-Emacs interface to Lisp?
  67.  
  68. ILISP is a powerful GNU-Emacs interface to many dialects of Lisp,
  69. including Lucid, Allegro, {A}KCL, IBCL, and CMU. Written by Chris
  70. McConnell <ccm+@cs.cmu.edu> and now maintained by Ivan Vazquez
  71. <ivan@haldane.bu.edu>. It is available by anonymous ftp from
  72. haldane.bu.edu [128.197.54.25] in the directory pub/ilisp as the file
  73. ilisp.tar.Z. If you want to be on the ilisp mailing list, to hear about
  74. new releases and patches, send mail to ilisp-request@darwin.bu.edu
  75. Please send any comments or code to ilisp@darwin.bu.edu. Bugs should
  76. be sent to ilisp-bug@darwin.bu.edu (or ilisp-bugs@darwin.bu.edu).
  77.  
  78. Franz Inc.'s GNU-Emacs/Lisp interface includes an online Common
  79. Lisp manual. It is available by license from Franz Inc. Contact
  80. info@franz.com for more information. The Emacs-Lisp interface (without
  81. the online Common Lisp reference manual and some Allegro-specific code)
  82. is available free from
  83.    ftp.uu.net:/vendor/franz/emacs/emacs-lisp-2.0.4.tar.Z
  84. There is also a mailing list, lisp-emacs-forum-request@ucbarpa.berkeley.edu.
  85. (See also [1-2] for a hardcopy version of the Common Lisp reference manual.)
  86.  
  87. The cl-shell package provides a major mode (cl-shell-mode) for running
  88. Common Lisp (CL) as an Emacs subprocess.  It provides a general
  89. mechanism for communication between CL and Emacs which does not rely
  90. on extra processes, and should therefore be easily portable to any
  91. version of CL.  Features include direct (i.e., not through a temp file)
  92. evaluation and in-package compilation of forms from lisp-mode buffers,
  93. type-ahead and a history mechanism for the cl-shell buffer, and pop-up
  94. help facilities for the CL functions documentation, macroexpand and
  95. describe.  Extensions for Lucid Common Lisp provide pop-up arglists
  96. and source file editing.  Other extensions are provided to allow
  97. editing source files of CLOS or Flavors methods.  Cl-shell is
  98. available on the Lucid tape (in the goodies directory) or via
  99. anonymous ftp from whitechapel.media.mit.edu (18.85.0.125).
  100.  
  101. Lucid includes some other Emacs-Lisp interfaces in its goodies directory.
  102.  
  103. Harlequin's LispWorks includes an Emacs-Lisp interface.
  104.  
  105. Venue's Medley has an optional EMACS Interface.
  106.  
  107. GNU-Emacs itself is available by anonymous ftp from prep.ai.mit.edu.
  108.  
  109. ----------------------------------------------------------------
  110. Subject: [2-2] When should I use a hash table instead of an association list?
  111.  
  112. Both association lists (alists) and hash tables may be used to
  113. represent tabular data. Hash tables have an O(1) running time and
  114. alists an O(n) running time, so hash tables are ultimately more
  115. efficient than alists. However, if the alists are small, they can be
  116. more efficient than hash tables, which have a large initial overhead.
  117.  
  118. Alists can sometimes be more efficient if the keys are sorted
  119. according to frequency, with the most heavily accessed keys appearing
  120. at the front of the list. But one doesn't always know this kind of
  121. information, and even then the frequency distribution may be flat.
  122.  
  123. In Allegro CL 4.1 [SPARC; R1], the rule of thumb is that for less than
  124. 24 elements, linear search using alists beats hashing.  In Lucid CL
  125. 4.0.1 HP 9000/700, the break-even point is at 10 elements. The
  126. break-even points vary in other lisps from as low as 4 elements to as
  127. high as 100 elements. So if you're using alists in your code, using 
  128. hash tables instead may speed up your program. 
  129.  
  130. A potential problem may occur, however, when the keys of an EQ or EQL
  131. hash table are Lisp objects such as conses or arrays (or other objects
  132. that are identified by their addresses). In most implementations, such
  133. tables must be re-hashed after garbage collection. If your application
  134. causes frequent GCs, this can adversely affect the performance of hash
  135. table lookup. Since EQL-hashing and =-hashing of fixnums generally
  136. don't require rehashing after GC, one way of avoiding this problem is
  137. to include a unique identifier in each key object and hash on that
  138. instead. Another solution is to use an EQUAL hash table if the keys
  139. are conses or an EQUALP hash table if the keys are arrays or other
  140. (non-circular!) structures.
  141.  
  142. ----------------------------------------------------------------
  143. Subject: [2-3] What is the equivalent of EXPLODE and IMPLODE in Common Lisp?
  144.  
  145. Hopefully, the only reason you need to do this is as part of trying to port
  146. some old MacLisp code to Common Lisp.  These functions predated the
  147. inclusion of strings as a first-class data type in Lisp; symbols were used
  148. as strings, and they ere EXPLODEd to allow the individual characters to be
  149. manipulated in a list.
  150.  
  151. Probably the best approximations of these are:
  152.  
  153.    (defun explode (object)
  154.      (loop for char across (prin1-to-string object)
  155.            collect (intern (string char))))
  156.  
  157.    (defun implode (list)
  158.      (read-from-string (coerce (mapcar #'character list) 'string)))
  159.  
  160. An alternate definition of EXPLODE which uses MAP instead of LOOP is:
  161.  
  162.    (defun explode (object)
  163.      (map 'list #'(lambda (char) 
  164.                     (intern (string char)))
  165.           (prin1-to-string object)))
  166.  
  167. The creation of N conses of garbage to process a string of N
  168. characters is a hideously inefficient way of doing the job.  Rewrite
  169. EXPLODE code with PRIN1-TO-STRING, or better STRING if the arguments
  170. are symbols without funny characters.  For IMPLODE, try to make its
  171. caller use strings and try to make the result usable as a string to
  172. avoid having to call INTERN or READ-FROM-STRING.
  173.  
  174. ----------------------------------------------------------------
  175. Subject: [2-4] Is Lisp inherently slower than more conventional languages
  176.                such as C?
  177.  
  178. This is a tough question to answer, as you probably expected.  In many
  179. cases, it appears to be.  Lisp does not require the programmer to specify
  180. the data type of variables, so generic arithmetic operators may have to
  181. perform type checking at runtime in order to determine how to proceed.
  182. However, Lisp code can also be denser (i.e.  there is more expressed in a
  183. single line) than many other languages: the Lisp expression (+ A B) is more
  184. powerful than the C expression A+B (the Lisp version supports bignums,
  185. rationals, and complex numbers, while the C version only supports
  186. limited-size integers and floating point); therefore, one may claim that it
  187. is reasonable that the Lisp version take longer than the C version (but
  188. don't expect everyone to accept this rationalization).  Solutions to this
  189. include hardware support (e.g. processors that support type tags in data,
  190. such as SPARC and Symbolics Lisp Machines), declarations, and specialized
  191. variants of functions (e.g. in MacLisp, + accepts and returns only fixnums,
  192. +$ accepts and returns only flonums, and PLUS is generic).
  193.  
  194. At one time, the MIT PDP-10 MacLisp compiler was compared to DEC's
  195. PDP-10 Fortran compiler.  When appropriate declarations were supplied
  196. in the Lisp code, the performance of compiled Lisp arithmetic rivaled
  197. that of the Fortran code.  It would hardly be fair to compare Lisp
  198. without declarations to Fortran, since the Fortran compiler would have
  199. more information upon which it could base its optimizations. A more
  200. recent test found that numeric code compiled with optimizations using
  201. CMU CL is within the same ballpark as highly optimized Fortran code.
  202. For unoptimized Fortran code, CMU CL was about 4 times faster.
  203. Even the speed of numeric code generated by other Lisp compilers
  204. (AKCL, Allegro, Lucid) was well within an order of magnitude of good
  205. Fortran and C compilers (although slower than CMU CL).  Inspection of
  206. the emitted C code from AKCL doesn't reveal many obvious sources of
  207. inefficiency. (Since AKCL compiles Lisp into C, there are many cases
  208. where KCL code is as fast as hand-written C code.)
  209.  
  210. See the paper peoplesparc.berkeley.edu:~ftp/pub/papers/fastlisp.ps.Z
  211. for a discussion of the speed of Lisp vis a vis Fortran or C.
  212.  
  213. Since Lisp is a good language for rapid prototyping, it is easy for a
  214. mediocre programmer (or even a good programmer, who isn't being careful) to
  215. generate a large amount of inefficient Lisp code. A good example is the use
  216. of APPEND to link successive lists together, instead of keeping a pointer
  217. to the tail of the list. Often a programmer can obtain significant
  218. speed increases by using a time/space profiler to identify the
  219. functions which waste time (often small functions which are called
  220. frequently) and rewriting those functions.
  221.      
  222. ----------------------------------------------------------------
  223. Subject: [2-5] Why does Common Lisp have "#'"?
  224.  
  225. #' is a macro-character which expands #'FOO to (FUNCTION FOO).  Symbols in
  226. Lisp have two bindings, one for values and one for functions, allowing them
  227. to represent both variables and functions, depending on context. #'FOO
  228. accesses FOO's lexical function binding in a context where the value
  229. interpretation would normally occur.  #' is also used to create lexical
  230. closures for lambda expressions. A lexical closure is a function which when
  231. invoked executes the body of the lambda-expression in the lexical
  232. environment within which the closure was created.  See pp. 115-117 of CLtL2
  233. for more details.
  234.  
  235. ----------------------------------------------------------------
  236. Subject: [2-6] How do I call non-Lisp functions from Lisp?
  237.  
  238. Most Lisp implementations for systems where Lisp is not the most common
  239. language provide a "foreign function" interface.  As of now there has been
  240. no significant standardization effort in this area.  They tend to be
  241. similar, but there are enough differences that it would be inappropriate to
  242. try to describe them all here.  In general, one uses an
  243. implementation-dependent macro that defines a Lisp function, but instead of
  244. supplying a body for the function, one supplies the name of a function written
  245. in another language; the argument list portion of the definition is
  246. generally augmented with the data types the foreign function expects and
  247. the data type of the foreign function's return value, and the Lisp
  248. interface function arranges to do any necessary conversions.  There is also
  249. generally a function to "load" an object file or library compiled in a
  250. foreign language, which dynamically links the functions in the file being
  251. loaded into the address space of the Lisp process, and connects the
  252. interface functions to the corresponding foreign functions.
  253.  
  254. If you need to do this, see the manual for your language implementation for
  255. full details.  In particular, be on the lookout for restrictions on the
  256. data types that may be passed.  You may also need to know details about the
  257. linkage conventions that are used on your system; for instance, many C
  258. implementations prepend an underscore onto the names of C functions when
  259. generating the assembler output (this allows them to use names without
  260. initial underscores internally as labels without worrying about conflicts),
  261. and the foreign function interface may require you to specify this form
  262. explicitly.
  263.  
  264. Franz Allegro Common Lisp's "Foreign Function Call Facility" is
  265. described in chapter 10 of the documentation. Calling Lisp Functions
  266. from C is treated in section 10.8.2. The foreign function interface in
  267. Macintosh Common Lisp is similar. The foreign function interface for
  268. KCL is described in chapter 10 of the KCL Report. The foreign function
  269. interfaces for Lucid on the Vax and Lucid on the Sun4 are
  270. incompatible. Lucid's interface is described in chapter 5 of the
  271. Advanced User's Guide.
  272.  
  273. ----------------------------------------------------------------
  274. Subject: [2-7] Can I call Lisp functions from other languages?
  275.  
  276. In implementations that provide a foreign function interface as described
  277. above, there is also usually a "callback" mechanism.  The programmer may
  278. associate a foreign language function name with a Lisp function.  When a
  279. foreign object file or library is loaded into the Lisp address space, it is
  280. linked with these callback functions.  As with foreign functions, the
  281. programmer must supply the argument and result data types so that Lisp may
  282. perform conversions at the interface. Note that in such foreign function
  283. interfaces Lisp is often left "in control" of things like memory
  284. allocation, I/O channels, and startup code (this is a major nuisance
  285. for lots of people).
  286.      
  287. ----------------------------------------------------------------
  288.  
  289. Subject: [2-8]  I want to call a function in a package that might not exist at
  290.                 compile time. How do I do this?
  291.  
  292. Use (funcall (find-symbol "SYMBOL-NAME" :pkg-name) ...).
  293.  
  294. ----------------------------------------------------------------
  295. Subject: [2-9]  What is CDR-coding?
  296.  
  297. CDR-coding is a space-saving way to store lists in memory.  It is normally
  298. only used in Lisp implementations that run on processors that are
  299. specialized for Lisp, as it is difficult to implement efficiently
  300. in software.  In normal list structure, each element of the
  301. list is represented as a CONS cell, which is basically two pointers (the
  302. CAR and CDR); the CAR points to the element of the list, while the CDR
  303. points to the next CONS cell in the list or NIL.  CDR-coding takes
  304. advantage of the fact that most CDR cells point to another CONS, and
  305. further that the entire list is often allocated at once (e.g. by a call to
  306. LIST).  Instead of using two pointers to implement each CONS cell, the CAR
  307. cell contains a pointer and a two-bit "CDR code".  The CDR code may contain
  308. one of three values: CDR-NORMAL, CDR-NEXT, and CDR-NIL.  If the code is
  309. CDR-NORMAL, this cell is the first half of an ordinary CONS cell pair, and
  310. the next cell in memory contains the CDR pointer as described above.  If
  311. the CDR code is CDR-NEXT, the next cell in memory contains the next CAR
  312. cell; in other words, the CDR pointer is implicitly thisaddress+1, where
  313. thisaddress is the memory address of the CAR cell.  If the CDR code is
  314. CDR-NIL, then this cell is the last element of the list; the CDR pointer is
  315. implicitly a reference to the object NIL.  When a list is constructed
  316. incrementally using CONS, a chain of ordinary pairs is created; however,
  317. when a list is constructed in one step using LIST or MAKE-LIST, a block of
  318. memory can be allocated for all the CAR cells, and their CDR codes all set
  319. to CDR-NEXT (except the last, which is CDR-NIL), and the list will only
  320. take half as much storage (because all the CDR pointers are implicit).
  321.  
  322. If this were all there were to it, it would not be difficult to implement
  323. in software on ordinary processors; it would add a small amount of overhead
  324. to the CDR function, but the reduction in paging might make up for it.  The
  325. problem arises when a program uses RPLACD on a CONS cell that has a CDR
  326. code of CDR-NEXT or CDR-NIL.  Normally RPLACD simply stores into the CDR
  327. cell of a CONS, but in this case there is no CDR cell -- its contents are
  328. implicitly specified by the CDR code, and the word that would normally
  329. contain the CDR pointer contains the next CONS cell (in the CDR-NEXT case)
  330. to which other data structures may have pointers, or the first word of some
  331. other object (in the CDR-NIL case).  When CDR-coding is used, the
  332. implementation must also provide automatic "forwarding pointers"; an
  333. ordinary CONS cell is allocated, the CAR of the original cell is copied
  334. into its CAR, the value being RPLACD'ed is stored into its CDR, and the old
  335. CAR cell is replaced with a forwarding pointer to the new CONS cell.
  336. Whenever CAR or CDR is performed on a CONS, it must check whether the
  337. location contains a forwarding pointer.  This overhead on both CAR and CDR,
  338. coupled with the overhead on CDR to check for CDR codes, is generally
  339. enough that using CDR codes on conventional hardware is infeasible.
  340.  
  341. There is some evidence that CDR-coding doesn't really save very much
  342. memory, because most lists aren't constructed at once, or RPLACD is done on
  343. them enough that they don't stay contiguous.  At best this technique can
  344. save 50% of the space occupied by CONS cells. However, the savings probably
  345. depends to some extent upon the amount of support the implementation
  346. provides for creating CDR-coded lists.  For instance, many system functions
  347. on Symbolics Lisp Machines that operate on lists have a :LOCALIZE option;
  348. when :LOCALIZE T is specified, the list is first modified and then copied
  349. to a new, CDR-coded block, with all the old cells replaced with forwarding
  350. pointers.  The next time the garbage collector runs, all the forwarding
  351. pointers will be spliced out.  Thus, at a cost of a temporary increase in
  352. memory usage, overall memory usage is generally reduced because more lists
  353. may be CDR-coded. There may also be some benefit in improved paging
  354. performance due to increased locality as well (putting a list into
  355. CDR-coded form makes all the "cells" contiguous). Nevertheless, modern
  356. Lisps tend to use lists much less frequently, with a much heavier
  357. reliance upon code, strings, and vectors (structures).
  358.  
  359. ----------------------------------------------------------------
  360. Subject: [2-10] What is garbage collection?
  361.  
  362. Garbage Collection (GC) refers to the automatic storage allocation
  363. mechanisms present in many Lisps. There are several kinds of storage
  364. allocation algorithms, but most fall within two main classes:
  365.  
  366.    1. Stop and Copy. Systems which copy active objects from "old"
  367.       storage to "new" storage and then recycle the old storage.
  368.  
  369.    2. Mark and Sweep. Systems which link together storage
  370.       used by discarded objects. 
  371.  
  372. Generational scavenging garbage collection (aka emphemeral GC) is a
  373. variation in which memory is allocated in layers, with tenured
  374. (long-lived) objects in the older layers. Rather than doing a full GC
  375. of all of memory every time more room is needed, only the last few
  376. layers are GCed during an ephemeral GC, taking much less time.
  377. Short-lived objects are quickly recycled, and full GCs are then much
  378. less frequent. It is most often used to improve the performance of
  379. stop and copy garbage collectors.  It is possible to implement
  380. ephemeral GC in mark and sweep systems, just much more difficult.
  381.  
  382. Stop and copy garbage collection provides simpler storage allocation,
  383. avoids fragmentation of memory (intermixing of free storage with used
  384. storage). Copying, however, consumes more of the address space, since up to
  385. half the space must be kept available for copying all the active objects.
  386. This makes stop and copy GC impractical for systems with a small address
  387. space or without virtual memory.  Also, copying an object requires that you
  388. track down all the pointers to an object and update them to reflect the new
  389. address, while in a non-copying system you need only keep one pointer to an
  390. object, since its location will not change. It is also more difficult to
  391. explicitly return storage to free space in a copying system.
  392.  
  393. Garbage collection is not part of the Common Lisp standard. Most Lisps
  394. provide a function ROOM which provides human-readable information about the
  395. state of storage usage. In many Lisps, (gc) invokes an ephemeral garbage
  396. collection, and (gc t) a full garbage collection.
  397.  
  398. ----------------------------------------------------------------
  399. Subject: [2-11] How do I save an executable image of my loaded Lisp system?
  400.                 How do I run a Unix command in my Lisp?
  401.                 How do I get the current directory name from within a Lisp 
  402.                 program?
  403.  
  404. There is no standard for dumping a Lisp image. Here are the
  405. commands from some lisp implementations:
  406.    Lucid:               DISKSAVE
  407.    Symbolics:           Save World  [CP command]
  408.    CMU CL:              SAVE-LISP
  409.    Franz Allegro:       EXCL:DUMPLISP (documented) 
  410.                         SAVE-IMAGE (undocumented)
  411.    Medley:              IL:SYSOUT or IL:MAKESYS
  412.    MCL:                 SAVE-APPLICATION <pathname>
  413.                           &key :toplevel-function  :creator :excise-compiler
  414.                           :size :resources :init-file :clear-clos-caches
  415.    KCL:                 (si:save-system "saved_kcl")
  416.    LispWorks:        LW:SAVE-IMAGE
  417.  
  418. There is no standard for running a Unix shell command from Lisp,
  419. especially since not all Lisps run on top of Unix. Here are the
  420. commands from some Lisp implementations:
  421.    Allegro:             EXCL:RUN-SHELL-COMMAND
  422.    Lucid:               RUN-PROGRAM (name 
  423.                                      &key input output
  424.                                           error-output (wait t) arguments
  425.                                           (if-input-does-not-exist :error)
  426.                                           (if-output-exists :error)
  427.                                           (if-error-output-exists :error))
  428.    KCL:                 SYSTEM 
  429.                         For example, (system "ls -l").
  430.                         You can also try RUN-PROCESS and EXCLP, but they
  431.                         don't work with all versions of KCL.
  432.    CMU CL:              RUN-PROGRAM (program args
  433.                &key (env *environment-list*) (wait t) pty input
  434.                if-input-does-not-exist output
  435.                (if-output-exists :error) (error :output) 
  436.                (if-error-exists :error) status-hook before-execve)
  437.    LispWorks:           FOREIGN:CALL-SYSTEM-SHOWING-OUTPUT
  438.  
  439. There's no standard function for finding the current directory from
  440. within a Lisp program, since not all Lisp environments have the
  441. concept of a current directory. Here are the commands from some Lisp
  442. implementations:
  443.    Lucid:               WORKING-DIRECTORY (which is also SETFable)
  444.                         PWD and CD also work
  445.    Allegro:             CURRENT-DIRECTORY (use excl:chdir to change it)
  446.    CMU CL:              DEFAULT-DIRECTORY
  447.    LispWorks:           LW:*CURRENT-WORKING-DIRECTORY* 
  448.                         (use LW:CHANGE-DIRECTORY to change it)
  449.  
  450. Allegro also uses the variable *default-pathname-defaults* to resolve
  451. relative pathnames, maintaining it as the current working directory.
  452. So evaluating (truename "./") in Allegro (and on certain other
  453. systems) will return a pathname for the current directory. Likewise,
  454. in some VMS systems evaluating (truename "[]") will return a pathname
  455. for the current directory.
  456.  
  457. To toggle source file recording and cross-reference annotations, use
  458.    Allegro:             excl:*record-source-file-info*
  459.             excl:*load-source-file-info* 
  460.             excl:*record-xref-info*
  461.             excl:*load-xref-info*
  462.    LispWorks:           (toggle-source-debugging nil)
  463.  
  464. Memory management:
  465.    CMU CL:              (bytes-consed-between-gcs)  [this is setfable]
  466.    Lucid:        (change-memory-management 
  467.                      &key growth-limit expand expand-reserved)
  468.    Allegro:        *tenured-bytes-limit*
  469.    LispWorks:           LW:GET-GC-PARAMETERS
  470.                         (use LW:SET-GC-PARAMETERS to change them)
  471.  
  472. ----------------------------------------------------------------
  473. Subject: [2-12] I'm porting some code from a Symbolics Lisp machine to some
  474.                 other platform, and there are strange characters in the code.
  475.                 What do they mean?
  476.  
  477. The Symbolics Zetalisp character set includes the following
  478. characters not present in other Lisps (^ means control):
  479.    ^]      >=      greater than or equal to
  480.    ^\      <=      less than or equal to
  481.    ^Z      !=      not equal to
  482.    ^^      ==      equivalent to 
  483.    ^E      not
  484.    ^G      pi
  485.    ^L      +/-     plus/minus
  486.    ^H      lambda
  487.    ^F      epsilon
  488.    ^W      <-->    left/right arrow
  489.    ^X      <--     left arrow
  490.    ^Y      -->     right arrow
  491.    ^A              down arrow
  492.    ^K              up arrow
  493.    ^D              up caret
  494.    ^_              down caret
  495.    ^T              forall
  496.    ^U              there exists
  497.    ^B              alpha
  498.    ^C              beta
  499.    ^I              gamma
  500.    ^J              delta
  501.    ^O              partial delta  
  502.    ^N              infinity
  503.    ^M              circle +
  504.    ^V              circle x
  505.  
  506. Other special characters to look out for are the font-change characters,
  507. which are represented as a ^F followed by a digit or asterisk. A digit
  508. means to push font #N onto the stack; an asterisk means to pop the most
  509. recent font from the stack. You can clean up the code by replacing "\^F."
  510. with "". In format statements, ^P and ^Q are used to delimit text to
  511. be printed in a particular character style.
  512.      
  513. ----------------------------------------------------------------
  514. Subject: [2-13] History: Where did Lisp come from?
  515.  
  516. John McCarthy developed the basics behind Lisp during the 1956 Dartmouth
  517. Summer Research Project on Artificial Intelligence.  He intended it as an
  518. algebraic LISt Processing (hence the name) language for artificial
  519. intelligence work. Early implementations included the IBM 704, the IBM
  520. 7090, the DEC PDP-1, the DEC PDP-6 and the DEC PDP-10. The PDP-6 and
  521. PDP-10 had 18-bit addresses and 36-bit words, allowing a CONS cell to
  522. be stored in one word, with single instructions to extract the CAR and
  523. CDR parts. The early PDP machines had a small address space, which
  524. limited the size of Lisp programs. 
  525.  
  526. Milestones in the development of Lisp:
  527.  
  528.    1956            Dartmouth Summer Research Project on AI.
  529.  
  530.    1960-65         Lisp1.5 is the primary dialect of Lisp.
  531.  
  532.    1964-           Development of BBNLisp at BBN.
  533.  
  534.    late 60s        Lisp1.5 diverges into two main dialects:
  535.                    Interlisp (originally BBNLisp) and MacLisp.
  536.  
  537.    early 70s       Development of special-purpose computers known as Lisp
  538.                    Machines, designed specificly to run Lisp programs. 
  539.                    Xerox D-series Lisp Machines run Interlisp-D. 
  540.                    Early MIT Lisp Machines run Lisp Machine Lisp 
  541.                    (an extension of MacLisp).
  542.  
  543.    1969            Anthony Hearn and Martin Griss define Standard Lisp to
  544.                    port REDUCE, a symbolic algebra system, to a variety
  545.                    of architectures.  
  546.  
  547.    late 70s        Macsyma group at MIT developed NIL (New Implementation
  548.                    of Lisp), a Lisp for the VAX.
  549.  
  550.                    Stanford and Lawrence Livermore National Laboratory
  551.                    develop S-1 Lisp for the Mark IIA supercomputer.
  552.  
  553.                    Franz Lisp (dialect of MacLisp) runs on stock-hardware
  554.                    Unix machines.
  555.  
  556.                    Gerald J. Sussman and Guy L. Steele developed Scheme,
  557.                    a simple dialect of Lisp with lexical scoping and
  558.                    lexical closures, continuations as first-class objects,
  559.                    and a simplified syntax (i.e., only one binding per symbol).
  560.  
  561.                    Advent of object-oriented programming concepts in Lisp.
  562.                    Flavors was developed at MIT for the Lisp machine,
  563.                    and LOOPS (Lisp Object Oriented Programming System) was
  564.                    developed at Xerox. 
  565.  
  566.    early 80s       Development of SPICE-Lisp at CMU, a dialect of MacLisp
  567.                    designed to run on the Scientific Personal Integrated
  568.                    Computing Environment (SPICE) workstation.
  569.  
  570.    1980            First biannual ACM Lisp and Functional Programming Conf.
  571.  
  572.    1981            PSL (Portable Standard Lisp) runs on a variety of platforms.
  573.  
  574.    1981+           Lisp Machines from Xerox, LMI (Lisp Machines Inc) 
  575.                    and Symbolics available commercially.
  576.  
  577.    April 1981      Grass roots definition of Common Lisp as a description
  578.                    of the common aspects of the family of languages (Lisp
  579.                    Machine Lisp, MacLisp, NIL, S-1 Lisp, Spice Lisp, Scheme). 
  580.                    
  581.  
  582.    1984            Publication of CLtL1. Common Lisp becomes a de facto 
  583.                    standard.
  584.  
  585.    1986            X3J13 forms to produce a draft for an ANSI Common Lisp
  586.                    standard. 
  587.  
  588.    1987            Lisp Pointers commences publication.
  589.  
  590.    1990            Steele publishes CLtL2 which offers a snapshot of
  591.                    work in progress by X3J13.  (Unlike CLtL1, CLtL2
  592.                    was NOT an output of the standards process and was
  593.                    not intended to become a de facto standard.  Read
  594.                    the Second Edition Preface for further explanation
  595.                    of this important issue.) Includes CLOS,
  596.                    conditions, pretty printing and iteration facilities. 
  597.  
  598.    1992            X3J13 creates a draft proposed American National
  599.                    Standard for Common Lisp. This document is the
  600.                    first official successor to CLtL1. 
  601.  
  602. [Note: This summary is based primarily upon the History section of the
  603. draft ANSI specification. More detail and references can be obtained from
  604. that document. See [4-12] for information on obtaining a copy.]
  605. ----------------------------------------------------------------
  606. Subject: [2-14]  How do I find the argument list of a function?
  607.                  How do I get the function name from a function object?
  608.  
  609. There is no standard way to find the argument list of a function,
  610. since implementations are not required to save this information.
  611. However, many implementations do remember argument information, and
  612. usually have a function that returns the lambda list. Here are the
  613. commands from some Lisp implementations:
  614.  
  615.    Lucid:                               arglist
  616.    Allegro:                             excl::arglist
  617.    Symbolics:                           arglist
  618.    LispWorks:                           lw:function-lambda-list
  619.  
  620. CMU Common Lisp, new compiler:
  621.    #+(and :CMU :new-compiler)
  622.    (defun arglist (name)
  623.      (let* ((function (symbol-function name))
  624.             (stype (system:%primitive get-vector-subtype function)))
  625.        (when (eql stype system:%function-entry-subtype)
  626.          (cadr (system:%primitive header-ref function
  627.                                   system:%function-entry-type-slot)))))
  628.  
  629. If you're interested in the number of required arguments you could use
  630.  
  631.    (defun required-arguments (name)
  632.      (or (position-if #'(lambda (x) (member x lambda-list-keywords))
  633.                       (arglist name))
  634.          (length (arglist name))))
  635.  
  636. To extract the function name from the function object, as in
  637.         (function-name #'car) ==> 'car
  638. use the following vendor-dependent functions:
  639.  
  640.    Symbolics: (si::compiled-function-name <fn>)
  641.     (unless (si:lexical-closure-p <fn>) ...)
  642.    Lucid:     (sys::procedure-ref <fn> SYS:PROCEDURE-SYMBOL)
  643.     (when (sys:procedurep <fn>) ..)
  644.    Allegro:   (xref::object-to-function-name <fn>)
  645.    CMU CL:    (kernel:%function-header-name <fn>)
  646.    AKCL:      (system::compiled-function-name <fn>)
  647.    MCL:       (ccl::function-name <fn>)
  648.    Harlequin: (system::function-name <fn>)
  649.  
  650. If a vendor-dependent function does not exist, the following
  651. (inefficient) code maps over all symbols looking for one whose
  652. function-cell matches the function object.
  653.  
  654. (defun function-name (fobject)
  655.    (do-all-symbols (fsymbol)
  656.       (when (and (fboundp fsymbol)
  657.                  (eq (symbol-function fsymbol) fobject))
  658.         (return fsymbol))))
  659.  
  660. If a vendor supports FUNCTION-LAMBDA-EXPRESSION, the third value is
  661. the name of the function, if available.
  662.  
  663. ----------------------------------------------------------------
  664. Subject: [2-15] How can I have two Lisp processes communicate via unix sockets?
  665.  
  666. CLX uses Unix sockets to communicate with the X window server. Look at
  667. the following files from the CLX distribution for a good example of
  668. using Unix sockets from Lisp:
  669.         defsystem.lisp          Lucid, AKCL, IBCL, CMU.
  670.         socket.c, sockcl.lisp   AKCL, IBCL
  671.         excldep.lisp            Franz Allegro CL
  672. You will need the "socket.o" files which come with Lucid and Allegro.
  673. To obtain CLX, see the entry for CLX in the answer to question [7-1].
  674.  
  675. See the file sockets.tar.gz in the Lisp Utilities repository
  676. described in the answer to question [6-1].
  677.  
  678. ----------------------------------------------------------------
  679. Subject: [2-16]  How can I create a stream that acts like UNIX's /dev/null
  680.                  (i.e., gobbles any output and immediately signals EOF on
  681.                  input operations)?
  682.  
  683. (defparameter *dev-null*
  684.   #-lispm
  685.   (make-two-way-stream (make-concatenated-stream) (make-broadcast-stream))
  686.   ;; Since Lisp Machines have a built-in /dev/null which handles
  687.   ;; additional, non-standard operations, we'll use that instead.
  688.   #+lispm #'system:null-stream)
  689.  
  690. ----------------------------------------------------------------
  691. Subject: [2-17] Read-time conditionalization of code (#+ #- and *features*)
  692.  
  693. The #+ and #- syntax provides for the read-time conditionalization of
  694. lisp code, depending on the presence or absence of keywords on the
  695. *features* list. The nascent Common Lisp standard does not specify
  696. what keywords an implementation must have on its features list.
  697. Nevertheless, most implementations have features that allow one to
  698. distinguish the implementation from other implementations. This allows
  699. one to write implementation-dependent code that is run only in the
  700. relevant implementations.
  701.  
  702. Here is a list of the features to use to specify a particular Common
  703. Lisp implementation. Unfortunately, not every vendor has a
  704. unique keyword that distinguishes their family of implementations from
  705. those of other vendors, nor major and minor versions of the implementation.
  706.  
  707.    :lucid                       Lucid Common Lisp
  708.    :lcl3.0                      Lucid Common Lisp v3.0 and above
  709.    :lcl4.0                      Lucid Common Lisp v4.0 and above
  710.    ----------------
  711.    (and :allegro :franz-inc)    Franz Allegro Common Lisp
  712.    :excl                        Franz Allegro Common Lisp 
  713.    :aclpc                       Franz Allegro Common Lisp\PC.
  714.    :allegro-v3.0                Franz Allegro Common Lisp v3.0 and above
  715.    :allegro-v3.1                Franz Allegro Common Lisp v3.1 and above
  716.    :allegro-v4.0                Franz Allegro Common Lisp v4.0 and above
  717.    :allegro-v4.1                Franz Allegro Common Lisp v4.1 and above
  718.    ----------------
  719.    :cmu                         CMU Common Lisp
  720.    (and :cmu :new-compiler)     CMU Common Lisp w/Python compiler
  721.    (and :cmu :python)           CMU Common Lisp w/Python compiler
  722.    :cmu17                       CMU Common Lisp v17 and above
  723.    ----------------
  724.    kcl                          Kyoto Common Lisp
  725.    akcl                         Austin KCL
  726.    :ibcl                        Ibuki Common Lisp 
  727.    ----------------
  728.    :mcl                         Macintosh Common Lisp
  729.    :coral                       Coral Lisp; bought by Apple to become
  730.                 MACL, then MCL
  731.    :ccl                         Coral Common Lisp
  732.     [Note: Harlequin LispWorks also uses :ccl]
  733.    :ccl-1                       Coral Common Lisp v1
  734.    :ccl-1.3                     Coral Common Lisp v1.3 and higher
  735.    :ccl-2                       present in Macintosh Common Lisp 2.0 and higher
  736.    ----------------
  737.    :harlequin-common-lisp       Harlequin Common Lisp
  738.    :harlequin-unix-lisp         Harlequin on Unix platforms
  739.    :harlequin-PC-lisp           Harlequin on PC platforms
  740.    :lispworks                   Harlequin Lispworks development environment
  741.    :lispworks3                  major release of Harlequin Lispworks
  742.    :lispworks3.1                major and minor release of Harlequin Lispworks
  743.    :harlequin                   All Harlequin products. not always present?
  744.    ----------------
  745.    :clisp                       CLISP Common Lisp
  746.    ----------------
  747.    :symbolics                   Symbolics Genera
  748.    :imach                       Symbolics Genera for Ivory architecture
  749.    :cloe-runtime                Symbolics CLOE
  750.    :cloe                        CLOE 3.1
  751.    ----------------
  752.    :procyon                     Procyon Common Lisp
  753.    (and :procyon :macintosh)    Procyon Common Lisp, Macintosh version
  754.    (and :procyon :os2)          Procyon Common Lisp, OS2 version
  755.    ----------------
  756.    :gclisp                      Golden Common Lisp
  757.    ----------------
  758.    (and dec vax common)         DEC VAXlisp
  759.    ----------------
  760.    :explorer                    TI Explorer Lisp Machine  | used
  761.    :TI                          TI Explorer Lisp Machine  | interchangeably
  762.    :elroy                       TI Explorer release 3 and successors
  763.    ----------------
  764.    :Xerox                       Medley (Venue's CL/InterLisp combo) to rel2.01
  765.    :medley                      Medley releases 3.0 and up
  766.       Use  (IL:UNIX-GETPARM "mach") and (IL:UNIX-GETPARM "arch") to
  767.       distinguish platforms under Medley.
  768.    ----------------
  769.    :ecl                         ECoLisp
  770.    ----------------
  771.    :lispm                       Symbolics, TI, and LMI Lisp machines
  772.  
  773.    In the cases where a feature is not a keyword, it is almost always
  774.    in the LISP package.
  775.  
  776. The draft ANSI standard defines some other useful features:
  777.  
  778.   :cltl1                Compatible with the 1st edition of Steele
  779.   :cltl2                Compatible with the 2nd edition of Steele
  780.   :IEEE-Floating-Point  IEEE floating point support
  781.   :X3J13                conforms to some particular draft of the ANSI
  782.                         CL specification 
  783.   :draft-ANSI-CL        conforms to first full public review draft
  784.   :ANSI-CL              conforms to ANSI CL after its adoption
  785.   :common-lisp          language family "Common Lisp"
  786.  
  787. Other features used by some Lisps include:
  788.  
  789.   :clos                 Contains a native CLOS implementation.
  790.   :pcl                  Contains the PCL implementation of CLOS.
  791.   :flavors              Has an implementation of Symbolics Flavors
  792.   :loop                 Contains the :cltl1 version of the Loop macro
  793.   :ansi-loop            Contains the ANSI Loop macro
  794.   :clx or :xlib         Contains CLX
  795.   :clxr4 or :CLX-MIT-R4 Contains CLX for X11R4
  796.   :clxr5 or :CLX-MIT-R5 Contains CLX for X11R5
  797.   :compiler             Contains a compiler  
  798.   :windows              MS Windows version
  799.   :color                Color display
  800.   :monochrome           Monochrome display
  801.   :multiprocessing      Has multiprocessing capabilities.
  802.   :profiler             Has a PC-monitoring based profiler.
  803.  
  804. Platform-specific features, CPU-dependent features, and
  805. operating-system specific features are also important because they can
  806. indicate changes between different implementations of the same lisp,
  807. such as compiled file extensions (e.g., .sbin, .hbin, etc.).
  808. Unfortunately, not every vendor includes such features, and the naming
  809. conventions are inconsistent. Where there are several names for the
  810. same feature, we've put the preferred name first. Hopefully the
  811. vendors will begin to standardize their use of these features.
  812. CPU-dependent features include :sparc (used in CMU CL, Lucid CL,
  813. Harlequin, and Allegro CL), :mips (used in Allegro CL), :r2000 (used
  814. in Allegro CL even on r4000 machines), :mc68000, and :pa (HP's
  815. 9000/800 RISC cpu).  Platform-specific features include :sun (used in
  816. Allegro CL and Lucid), :sun4 (used in CMU CL and Allegro CL), :sgi
  817. (used in Allegro CL), :hp300, :hp400, :hp500, :sun3, :vax, :prime,
  818. :dec, :dec3100, :macintosh (used in Procyon but not MCL), :ibm-pc,
  819. :ibm-rt-pc.  OS-specific features include :unix (used in CMU CL, IBCL,
  820. and Lucid CL), :vms, :sunos (used in CMU CL), :sun-os (used in Lucid),
  821. :sunos4.0 and :sunos4 (used in various Allegro versions independent of
  822. the actual version of SunOS), :mach (used in CMU CL), :hpux, :ultrix,
  823. :os2, and :svr4.
  824.  
  825. Notes:
  826.  
  827.    :allegro alone doesn't suffice to distinguish Franz Allegro Common
  828.    Lisp from Macintosh Allegro Common Lisp (an early version of
  829.    Macintosh Common Lisp). :excl specifies that the EXCL package (a
  830.    set of Allegro extensions to Common Lisp) is present, but this has
  831.    since become synonymous with Franz Allegro Common Lisp.
  832.  
  833.    Thanks to Vincent Keunen for gathering the information in this list.
  834.  
  835. ----------------------------------------------------------------
  836. Subject: [2-18]  What reader macro characters are used in major Lisp systems?
  837.  
  838. The draft ANSI standard for Common Lisp leaves many dispatching macro
  839. characters unassigned. Of these, the following are explicitly reserved
  840. for the user and hence will never be defined by Common Lisp:
  841.    #!, #?, #[, #], #{, and #}. 
  842. All other unassigned macro characters are not reserved for the user,
  843. and hence the user has no guarantee that they won't be used by some
  844. Lisp implementation. 
  845.  
  846. As a result, there is the potential of portability clashes between
  847. systems that use the same macro characters. This question lists the
  848. non-standard macro character usage of major Lisp systems, in an effort
  849. to avoid such conflicts.
  850.  
  851.    #"        AKCL; pathnames
  852.    #$        Macintosh Common Lisp; traps
  853.    #%        Cyc; references to constants in the representation language
  854.    #%        Harlequin Lispworks; ?
  855.    #@        Macintosh Common Lisp; Points notation
  856.    #@         Defsystem    
  857.    #I        Portable Infix Package
  858.    #L        Allegro Common Lisp; logical pathnames
  859.    #M        Series
  860.    #T         Allegro Common Lisp; ?
  861.    #Y        CLISP; ?
  862.    #Z        Series
  863.    #_        Macintosh Common Lisp; traps
  864.    #`        Harlequin Lispworks; ?
  865.  
  866. There is a proposal in the ANSI draft to have COMPILE-FILE and LOAD
  867. bind *READTABLE*, which would allow one to locally redefine syntax
  868. through private readtables. Unfortunately, this doesn't help with the
  869. Infix Package, where one wants to globally extend syntax.
  870.  
  871. ----------------------------------------------------------------
  872. ;;; *EOF*
  873.