From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: PJ Weisberg Newsgroups: gmane.emacs.help Subject: Re: How to remove verbosity from the data passing mechanism using alist or plist ? Date: Tue, 7 Dec 2010 08:55:41 -0800 Message-ID: References: <87lj43at0i.fsf@ambire.localdomain> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1291740978 22999 80.91.229.12 (7 Dec 2010 16:56:18 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 7 Dec 2010 16:56:18 +0000 (UTC) To: help-gnu-emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Dec 07 17:56:15 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PQ0pq-000832-5C for geh-help-gnu-emacs@m.gmane.org; Tue, 07 Dec 2010 17:56:14 +0100 Original-Received: from localhost ([127.0.0.1]:47835 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQ0pp-0004Rr-Fj for geh-help-gnu-emacs@m.gmane.org; Tue, 07 Dec 2010 11:56:13 -0500 Original-Received: from [140.186.70.92] (port=59457 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQ0pR-0004RZ-QK for Help-gnu-emacs@gnu.org; Tue, 07 Dec 2010 11:55:50 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PQ0pQ-0007ck-Kj for Help-gnu-emacs@gnu.org; Tue, 07 Dec 2010 11:55:49 -0500 Original-Received: from smtpauth11.prod.mesa1.secureserver.net ([64.202.165.33]:52125) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1PQ0pQ-0007cR-BR for Help-gnu-emacs@gnu.org; Tue, 07 Dec 2010 11:55:48 -0500 Original-Received: (qmail 1082 invoked from network); 7 Dec 2010 16:55:46 -0000 Original-Received: from unknown (74.125.82.169) by smtpauth11.prod.mesa1.secureserver.net (64.202.165.33) with ESMTP; 07 Dec 2010 16:55:45 -0000 Original-Received: by wyj26 with SMTP id 26so123799wyj.0 for ; Tue, 07 Dec 2010 08:55:43 -0800 (PST) Original-Received: by 10.227.128.7 with SMTP id i7mr7517717wbs.165.1291740941643; Tue, 07 Dec 2010 08:55:41 -0800 (PST) Original-Received: by 10.227.147.140 with HTTP; Tue, 7 Dec 2010 08:55:41 -0800 (PST) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:75532 Archived-At: On Tue, Dec 7, 2010 at 7:14 AM, Drew Adams wrote: >> those things that look like lists but have dots in them are >> a result of someone abusing "cons" to make a cons cell whose >> 'next' pointer points to something other than the next cons >> cell in a list. > > Actually this is not an abuse of poor little `cons'. =A0;-) > > The list `(x)' is in fact an example of such "abusive" behavior: the cdr > ("next") is the symbol `nil', which is an atom, not a cons cell: `(x . ni= l)'. > > It is correct to say that cons cells are used to build lists, and that th= at is > their most common use. =A0And that a list is either `nil' or a cons cell = whose cdr > is a list. =A0But it is also correct that some cons cells are not lists, = i.e., do > not have a list as their cdr. > > `cons' is untyped wrt its parameters. =A0It is not only the first paramet= er (the > car) that need not be a list, but also the second (the cdr). Yeah, I hesitated to use 'abuse' there, but I was tired and decided to opt for the more colorful language. :-) The first thing I think of when I think of cons is a trivial example from a college class, like "(cons 1 (cons 2 (cons 3 nil)))" to make a 3-item list. So I usually think of cons as a way to add something to the front of a list (nil being the same thing as an empty list). Basically, 'list' and 'cons' both return a cons cell. With 'cons', the car of the cons cell is the first argument and the cdr is the second argument. With 'list', the car is the first argument and the cdr is another cons cell, whose car is the second argument and whose cdr is another cons cell, and so on until you get to a cons cell whose car is the last argument and whose cdr is nil. I was trying to come up with an example to show how 'list' was like a bunch of 'cons's, but the part of my brain that can do recursion was in sleep mode, and then the best I came up with was (defun my-list( &rest args ) (if args (cons (car args) (eval (cons 'my-list (cdr args)))) nil)) and I didn't think was was clarifying *anything* if I had to use eval to while I was explaining cons. ;-) P.S.: For the benefit of lisp beginners who don't know, if args is '(1 2 3 4), then (cdr args) is '(2 3 4), and (cons 'my-list '(2 3 4)) is '(my-list 2 3 4). Doesn't that look like a function call? eval treats it as such.