From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: RG Newsgroups: gmane.emacs.help Subject: Re: lisp style question Date: Sun, 05 Dec 2010 21:45:59 -0800 Organization: Amalgamated Widgets Unlimited Message-ID: References: <82vd3ceexc.fsf@shevek.netfonds.no> <6e2fe51c-ff4c-429f-b221-a3cbe23e958f@n2g2000pre.googlegroups.com> <87aakjkg2i.fsf@kuiper.lan.informatimago.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1291957148 13615 80.91.229.12 (10 Dec 2010 04:59:08 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 10 Dec 2010 04:59:08 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Dec 10 05:59:04 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 1PQv4S-0006mt-G7 for geh-help-gnu-emacs@m.gmane.org; Fri, 10 Dec 2010 05:59:04 +0100 Original-Received: from localhost ([127.0.0.1]:33818 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQuwe-0008P9-T1 for geh-help-gnu-emacs@m.gmane.org; Thu, 09 Dec 2010 23:51:01 -0500 Original-Path: usenet.stanford.edu!postnews.google.com!news4.google.com!feeder.news-service.com!feeder.ecngs.de!ecngs!feeder2.ecngs.de!78.46.240.70.MISMATCH!weretis.net!feeder4.news.weretis.net!news.albasani.net!rNOSPAMon Original-Newsgroups: comp.lang.lisp,comp.emacs,gnu.emacs.help Original-Lines: 45 Original-X-Trace: news.albasani.net u4uaNuxfJN6kLQXZXePFNuxhNA9xPYrg8PBV4jblo7UVonGLBJIu6ByKaI05TimBkqi27l4p6B6JYcsEhwnXQV7tJnkrWVI0erZIgNhYMR0GZBS5lRSbGPRI2vvlmcmf Original-NNTP-Posting-Date: Mon, 6 Dec 2010 05:46:01 +0000 (UTC) Cancel-Lock: sha1:TOVXWGwrglZ+O6ba70LmnOPELjc= User-Agent: MT-NewsWatcher/3.5.1 (Intel Mac OS X) Injection-Info: news.albasani.net; logging-data="oO/unL+JnAL6lywYZqOr/tYHoOGRJ0IF//ljRhfaXFujs1ezBmpe12zjRQcD2Xqfkn1RPM4JAyDtnZfNR2KKXvL4sWaDYXXjgh59gx5mCzJgJxpwzYzQU804r3R39MFV"; mail-complaints-to="abuse@albasani.net" Original-Xref: usenet.stanford.edu comp.lang.lisp:296257 comp.emacs:100929 gnu.emacs.help:182904 X-Mailman-Approved-At: Thu, 09 Dec 2010 20:23:28 -0500 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:77347 Archived-At: In article <87aakjkg2i.fsf@kuiper.lan.informatimago.com>, "Pascal J. Bourguignon" wrote: > RG writes: > > > In article > > <6e2fe51c-ff4c-429f-b221-a3cbe23e958f@n2g2000pre.googlegroups.com>, > > Katalin Sinkov 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