From: RG <rNOSPAMon@flownet.com>
To: help-gnu-emacs@gnu.org
Subject: Re: lisp style question
Date: Sun, 05 Dec 2010 12:51:00 -0800 [thread overview]
Message-ID: <rNOSPAMon-79CF96.12510005122010@hello.network> (raw)
In-Reply-To: 6e2fe51c-ff4c-429f-b221-a3cbe23e958f@n2g2000pre.googlegroups.com
In article
<6e2fe51c-ff4c-429f-b221-a3cbe23e958f@n2g2000pre.googlegroups.com>,
Katalin Sinkov <lispstylist@gmail.com> wrote:
> On Dec 2, 12:50 am, "Frode V. Fjeld" <fr...@netfonds.no> wrote:
> > Katalin Sinkov <lispstyl...@gmail.com> 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
next prev parent reply other threads:[~2010-12-05 20:51 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 [this message]
[not found] ` <87aakjkg2i.fsf@kuiper.lan.informatimago.com>
2010-12-06 5:45 ` RG
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-79CF96.12510005122010@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).