From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.help Subject: Re: How to describe something in Lisp? Date: Tue, 03 Feb 2009 17:46:57 +0100 Message-ID: <87ljsneada.fsf@thinkpad.tsdh.de> References: <929ccd880902030623t1ccb3567weecce35deb378f73@mail.gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1233679694 21869 80.91.229.12 (3 Feb 2009 16:48:14 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 3 Feb 2009 16:48:14 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Feb 03 17:49:28 2009 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.50) id 1LUOSj-000502-3A for geh-help-gnu-emacs@m.gmane.org; Tue, 03 Feb 2009 17:49:25 +0100 Original-Received: from localhost ([127.0.0.1]:48249 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LUORQ-00039L-GJ for geh-help-gnu-emacs@m.gmane.org; Tue, 03 Feb 2009 11:48:04 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LUOQa-0002c5-13 for help-gnu-emacs@gnu.org; Tue, 03 Feb 2009 11:47:12 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LUOQX-0002Yk-5z for help-gnu-emacs@gnu.org; Tue, 03 Feb 2009 11:47:11 -0500 Original-Received: from [199.232.76.173] (port=48448 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LUOQX-0002YW-0x for help-gnu-emacs@gnu.org; Tue, 03 Feb 2009 11:47:09 -0500 Original-Received: from main.gmane.org ([80.91.229.2]:34433 helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LUOQW-0007gh-FE for help-gnu-emacs@gnu.org; Tue, 03 Feb 2009 11:47:08 -0500 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1LUOQU-0000OZ-KY for help-gnu-emacs@gnu.org; Tue, 03 Feb 2009 16:47:06 +0000 Original-Received: from 141.26.67.2 ([141.26.67.2]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 03 Feb 2009 16:47:06 +0000 Original-Received: from tassilo by 141.26.67.2 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 03 Feb 2009 16:47:06 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 58 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 141.26.67.2 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.90 (gnu/linux) Cancel-Lock: sha1:jIAJbZ/wahImBIftXhWh6/5A4vw= X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) 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:61884 Archived-At: Johan Andersson writes: Hi Johan, > Then I could easy update attributes on the objects, remove and add > people and then update the file. > > I tried with a couple of solutions for this in Lisp: > > 1) One list named people: > ( > (name age married sex) > ... > ) I think a list of plists would be quite intuitive to someone with an OO background. Here's a quick and dirty snippet which should get you started: --8<---------------cut here---------------start------------->8--- (defvar persons '((:name "Klaus" :age 36 :sex male) (:name "Claudia" :age 31 :sex female))) (defun print-persons (buffer) (set-buffer buffer) (dolist (person persons) (insert (format "\n;; %s, %s, %s" (plist-get person :name) (plist-get person :age) (plist-get person :sex))))) (print-persons (current-buffer)) ;; <== C-x C-e here! ;; Klaus, 36, male ;; Claudia, 31, female (defun set-property (name prop newval) (let ((list persons)) (while (not (string= (plist-get (car list) :name) name)) (setq list (cdr list))) (when (not (null list)) (let ((plist (car list))) (setq persons (remove plist persons)) (setq persons (cons (plist-put plist prop newval) persons)))))) ;; Adjust the ages (set-property "Klaus" :age 37) (set-property "Claudia" :age 32) (print-persons (current-buffer)) ;; <== C-x C-e here! ;; Claudia, 32, female ;; Klaus, 37, male --8<---------------cut here---------------end--------------->8--- I'm assume that the name (the :name property) is unique, here. Bye, Tassilo