From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "rgb" Newsgroups: gmane.emacs.help Subject: Re: sharing list structure Date: 24 Mar 2005 21:49:15 -0800 Organization: http://groups.google.com Message-ID: <1111729755.575235.219080@z14g2000cwz.googlegroups.com> References: <1111712489.491757.194480@g14g2000cwa.googlegroups.com> <1111729482.406604.45210@l41g2000cwc.googlegroups.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: sea.gmane.org 1111730090 19161 80.91.229.2 (25 Mar 2005 05:54:50 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 25 Mar 2005 05:54:50 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Mar 25 06:54:49 2005 Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DEhmN-0003qM-Lv for geh-help-gnu-emacs@m.gmane.org; Fri, 25 Mar 2005 06:54:44 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DEi1n-0005zJ-Ss for geh-help-gnu-emacs@m.gmane.org; Fri, 25 Mar 2005 01:10:40 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!z14g2000cwz.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 51 Original-NNTP-Posting-Host: 63.229.221.50 Original-X-Trace: posting.google.com 1111729761 25053 127.0.0.1 (25 Mar 2005 05:49:21 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Fri, 25 Mar 2005 05:49:21 +0000 (UTC) User-Agent: G2/0.2 Complaints-To: groups-abuse@google.com Injection-Info: z14g2000cwz.googlegroups.com; posting-host=63.229.221.50; posting-account=C7LM4w0AAAD23IRuMuUUJVCLQTuHhTK8 Original-Xref: shelby.stanford.edu gnu.emacs.help:129586 Original-To: help-gnu-emacs@gnu.org 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 X-MailScanner-To: geh-help-gnu-emacs@m.gmane.org Xref: news.gmane.org gmane.emacs.help:25137 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:25137 rgb wrote: > > The data structure that I think ought to be capable of handling all > of > > this would be a list B that contains > > > > ((title1, H1, F1), (title2, H2, F2), ..., (titlen, Hn, Fn)) > > > > Well I'm not sure now if you're re-explaining the problem for my > benefit or showing me you've found the answer. Because the above > (with commas removed) seems to be a perfectly useable answer. > > > (setq all-my-lists > '((key1 (h1a h1b h1c ...) (f1a f1b f1c ...)) > (key2 (h2a h2b h2c ...) (f2a f2b f2c ...)) > ...)) > > It should't be too hard to write some functions that mannage a > set of nested lists such as that in whatever way is convenient to > your application. > > For example: > > (setq all '((a (h1 h2 h3)(f1 f2 f3)) ;test data > (b (ha hb hc)(fa fb fc)))) > > (defun get^h (key index) > "get h[index] value within KEY list" > (nth index (cadr (assoc key all)))) > > (get^h 'b 2) > hc > > (defun delete^h (key index) > "remove h[index] value from KEY list." > (if (< 0 index) > ;; the car of the list is not affected so just change the list > ;; I used (nth 1 ...) rather than (cadr ...) so it's more obvious > ;; how this could have a 3rd argument and not just access h. > (setcdr (nthcdr (1- index) (nth 1 (assoc key all))) > (nthcdr (1+ index) (nth 1 (assoc key all)))) > ;; when the car changes the outer list holding it must change > (setcar (cdr (assoc key all)) > (nthcdr 1 (cadr (assoc key all)))))) Naturally this needs a bit more code like probably bounds checking but as an example to get started with...