From: Tassilo Horn <tassilo@member.fsf.org>
To: help-gnu-emacs@gnu.org
Subject: Re: How to describe something in Lisp?
Date: Tue, 03 Feb 2009 17:46:57 +0100 [thread overview]
Message-ID: <87ljsneada.fsf@thinkpad.tsdh.de> (raw)
In-Reply-To: 929ccd880902030623t1ccb3567weecce35deb378f73@mail.gmail.com
Johan Andersson <johan.rejeep@gmail.com> 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
next prev parent reply other threads:[~2009-02-03 16:46 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-03 14:23 How to describe something in Lisp? Johan Andersson
2009-02-03 16:24 ` Thierry Volpiatto
2009-02-03 16:46 ` Tassilo Horn [this message]
[not found] ` <mailman.6652.1233679633.26697.help-gnu-emacs@gnu.org>
2009-02-04 10:33 ` Pascal J. Bourguignon
2009-02-04 11:43 ` Tassilo Horn
2009-02-05 2:28 ` Pascal J. Bourguignon
2009-02-05 7:22 ` Johan Andersson
[not found] ` <mailman.16.1233818553.17492.help-gnu-emacs@gnu.org>
2009-02-06 18:53 ` Ted Zlatanov
[not found] ` <7c63jq3319.fsf@pbourguignon.informatimago.com>
[not found] ` <mailman.6723.1233747843.26697.help-gnu-emacs@gnu.org>
2009-02-04 13:26 ` Pascal J. Bourguignon
[not found] <mailman.6644.1233674526.26697.help-gnu-emacs@gnu.org>
2009-02-03 15:48 ` Andreas Politz
2009-02-03 16:40 ` Pascal J. Bourguignon
2009-02-03 16:44 ` Johan Andersson
2009-02-03 16:54 ` Tassilo Horn
2009-02-03 17:07 ` Johan Andersson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ljsneada.fsf@thinkpad.tsdh.de \
--to=tassilo@member.fsf.org \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.