Path: utzoo!utgpu!water!watmath!clyde!rutgers!rochester!bbn!uwmcsd1!ig!agate!ucbvax!decvax!decwrl!sun!pitstop!sundc!seismo!uunet!cme-durer!klm From: klm@cme-durer.ARPA (Ken Manheimer) Newsgroups: comp.emacs Subject: Re: alist help for an elisp beginner Summary: The describe-function spiels for fundamental lisp funcs are vacuous Message-ID: <232@stylus.cme-durer.ARPA> Date: 18 Feb 88 04:09:19 GMT References: <276@ho7cad.ATT.COM> Reply-To: klm@cme-amrf.arpa (Ken Manheimer) Organization: National Bureau of Standards, Gaithersburg, MD Lines: 68 In article jk3k+@ANDREW.CMU.EDU ("Joseph G. Keane") writes: >Use: >(defvar file-name-abbreviation-alist > (list > (cons (format "^%s" (getenv "HOME")) "~") > (cons (format "^%s" (getenv "TOOLS")) ""))) > >(I bet this looks pretty random if you don't know Lisp.) > >--Joe It's funny; just yesterday i was scrambling around gnuEmacs with someone who was just learning to maneuver around the editor and its elisp, and he pointed out a particularly fine little suite of mutually circular definitions. Of course, it was the fundamental (and most beguilingly named) lisp functions that were being "defined". The quest started with a question about 'assq' and alists; referring to describe-function, we get: assq: Returns non-nil if ELT is the car of an element of LIST. Comparison done with eq. The value is actually the element of LIST whose car is ELT. Well, ok, but if you're a spanking brand new beginner, you're going to wonder about 'car'. If you know lisp, you know 'car' means "first element of a list (or nil for nil)" (or, "Contents of the Accumulator Register", historically speaking...). However, if you once again resort to emacs' helping hand, car: Return the car of CONSCELL. If arg is nil, return nil. Hmm. CONSCELL. We've seen 'cons' around, right? What about that one? cons: Create a new cons, give it CAR and CDR as components, and return it. Oh, that's much better. How about cdr? cdr: Return the cdr of CONSCELL. If arg is nil, return nil. I know that emacs help is not intended to provide a tutorial for or introduction to lisp. If you don't have some idea about the list data structure and its accessors and CONStructors, you ought to start elsewhere; however i think it's at least a little amusing how blatantly circular these definitions are. I mean, the definition for 'cdr' above provides some info about what happens for the boundary condition nil, but it doesn't say anything about the error that's provoked when a non-list expression is provided to cdr, and saying that cdr returns "the cdr of CONSCELL" is *not* an example of a recursive def, but instead a vacuous one. Would it hurt, eg for 'cdr', to say something to the effect of "nil for a null list, the portion of a list after the first element, or else an error"? I expect that some such more informative (though less formal) description might help answer questions like the one Barry asks, about the difference between 'append' and 'cons'. (Btw, is this phrasing sound for dotted pairs?) Or is the idea specifically to send the novice scrambling for a real Lisp manual? Ken Manheimer klm@cme-durer.arpa or ..!uunet!cme-durer.arpa!klm "For without the inner the outer loses its meaning; and without the outer, the inner loses its substance." R.D.Laing