From: RG <rNOSPAMon@flownet.com>
To: help-gnu-emacs@gnu.org
Subject: Re: lisp style question
Date: Sun, 05 Dec 2010 21:45:59 -0800 [thread overview]
Message-ID: <rNOSPAMon-D7AE66.21455905122010@hello.network> (raw)
In-Reply-To: 87aakjkg2i.fsf@kuiper.lan.informatimago.com
In article <87aakjkg2i.fsf@kuiper.lan.informatimago.com>,
"Pascal J. Bourguignon" <pjb@informatimago.com> wrote:
> RG <rNOSPAMon@flownet.com> writes:
>
> > In article
> > <6e2fe51c-ff4c-429f-b221-a3cbe23e958f@n2g2000pre.googlegroups.com>,
> > Katalin Sinkov <lispstylist@gmail.com> wrote:
> >
> >> how to conveniently costruct the list that goes with getf ?
> >
> > You can't construct anything with GETF. GETF is an accessor.
>
> This is not correct. GETF is special:
>
> CL-USER> (let ((plist '()))
> (setf (getf plist :k1) 1
> (getf plist :k2) 2)
> plist)
> (:K2 2 :K1 1)
>
> Setfers are able to do such things.
GETF is not unique in this regard. GETHASH works the same way. But
relying on GETF's ability to allocate storage for new keys is fraught
with peril, e.g.:
(defun make-new-plist () (list :key1 :value1))
(defun set-key (plist key value)
(setf (getf plist key) value))
(defun foo ()
(let* ((plist (make-new-plist)))
(set-key plist :key1 :new-value-1)
(set-key plist :key2 :value2)
plist))
(foo) ==> (:KEY1 :NEW-VALUE-1) ; What happened to key2?
I think it's better to advise beginners to avoid such things rather than
try to explain the sometimes subtle distinction between places and
first-class mutable data objects.
rg
next prev parent reply other threads:[~2010-12-06 5:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <ef033328-1f7d-49e9-8b1b-1e4e1f6edcb5@d8g2000yqf.googlegroups.com>
[not found] ` <82vd3ceexc.fsf@shevek.netfonds.no>
2010-12-03 1:11 ` lisp style question Katalin Sinkov
[not found] ` <87zkslgk3c.fsf@mail.geddis.org>
2010-12-05 18:22 ` Katalin Sinkov
2010-12-05 20:51 ` RG
[not found] ` <87aakjkg2i.fsf@kuiper.lan.informatimago.com>
2010-12-06 5:45 ` RG [this message]
2012-11-05 23:33 Rivka Miller
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=rNOSPAMon-D7AE66.21455905122010@hello.network \
--to=rnospamon@flownet.com \
--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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).