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 12:51:00 -0800 Organization: Amalgamated Widgets Unlimited Message-ID: References: <82vd3ceexc.fsf@shevek.netfonds.no> <6e2fe51c-ff4c-429f-b221-a3cbe23e958f@n2g2000pre.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: dough.gmane.org 1291955977 9907 80.91.229.12 (10 Dec 2010 04:39:37 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 10 Dec 2010 04:39:37 +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:39:33 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 1PQulZ-0001Vy-CJ for geh-help-gnu-emacs@m.gmane.org; Fri, 10 Dec 2010 05:39:33 +0100 Original-Received: from localhost ([127.0.0.1]:37043 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQujE-0001mE-Qf for geh-help-gnu-emacs@m.gmane.org; Thu, 09 Dec 2010 23:37:08 -0500 Original-Path: usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.84.MISMATCH!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!news.wiretrip.org!news2.arglkargh.de!news.albasani.net!rNOSPAMon Original-Newsgroups: comp.lang.lisp,comp.emacs,gnu.emacs.help Original-Lines: 73 Original-X-Trace: news.albasani.net IOkpCHKA7L5kNeKd1IoXR3dG5kF+gRFQbJJzDpfF1r84tqhOUYq6j4ZgKqGduqxLIyGN1vbVDhnHJRPiJdPvXQm44TLC2bBKNyMLzui4KFX9bZoBW3rpZ7ya50fZfelQ Original-NNTP-Posting-Date: Sun, 5 Dec 2010 20:51:02 +0000 (UTC) Cancel-Lock: sha1:maKhdUbzqO5ft1CA0EHTA8eVDLo= User-Agent: MT-NewsWatcher/3.5.1 (Intel Mac OS X) Injection-Info: news.albasani.net; logging-data="V1x/6O69itkewc9WewtE+iNROr/+VE7gtWL/XCqId4bP4bciPXAHauqGfj4NBGR6Zbybv8/7Get4HPxIaWdU4MEiBU4Yxiv7AwMmSoPbMxM5odS24xA/uR55HlwLSHwD"; mail-complaints-to="abuse@albasani.net" Original-Xref: usenet.stanford.edu comp.lang.lisp:296231 comp.emacs:100921 gnu.emacs.help:182888 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:77327 Archived-At: In article <6e2fe51c-ff4c-429f-b221-a3cbe23e958f@n2g2000pre.googlegroups.com>, Katalin Sinkov wrote: > On Dec 2, 12:50 am, "Frode V. Fjeld" wrote: > > Katalin Sinkov writes: > > > In the {} world I would return a small table like > > > > > width   1 > > > height  2 > > > weight  3 > > > > Typically in Lisp you'd return either a property or association list. > > > > I.e: (WIDTH 1 HEIGHT 2 WEIGHT 3) with accessor GETF, > > > > or ((WIDTH . 1) (HEIGHT . 2) (WEIGHT . 3)) with accessor ASSOC. > > > > -- > > Frode V. Fjeld > > Of all the four or five replies, I found yours most helpful although > brief. This is perhaps due to me being a beginner, although the > replies seem very promising and I am desirous of understanding them. I > have just read the paper by McCarthy and the micro manual. There's another solution that doesn't seem to have been mentioned yet: ? (defstruct thing width height weight) THING ? (setf thing (make-thing :width 1 :height 2 :weight 3)) #S(THING :WIDTH 1 :HEIGHT 2 :WEIGHT 3) ? (thing-height thing) 2 ? (slot-value thing 'height) 2 > what is an "assoc list" and "a property list" and their difference ? The difference is purely one of convention. Both are simple arrangements of cons cells, but an association list (also called an assoc list of an a-list) looks like this: ((key . value) (key . value) ...) while a property list (also called a p-list) looks like this: (key value key value ...) These are not the only ways to create associative maps using cons cells. For example, there is a little-used convention that I call a D-List (for "dissociated association list") that looks like this: ((key key ...) value value ...) The advantage of a D-List is that multiple D-List can share the same set of keys so if you have a lot of associative maps with the same keys this can be a big performance win. There are lots of other efficiency hacks you can do on D-Lists that you can't do on A-Lists or P-Lists, but that's probably more advanced than you want to get right now. > what is "setf" and how to write it in terms of the elementary > functions, car/cdr/cons/quote/cond/atom/eq ? SETF is a macro, not a function, and a particularly complicated one. You should read up on macros in general before trying to understand how SETF is implemented. > how to conveniently costruct the list that goes with getf ? You can't construct anything with GETF. GETF is an accessor. rg