all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How to populate a property list?
@ 2004-10-26 10:09 Hattuari
  2004-10-26 12:28 ` Thien-Thi Nguyen
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Hattuari @ 2004-10-26 10:09 UTC (permalink / raw)


Suppose I have a collection of key values pairs as follows:

char  c 
short s 
int   i 
long  l

I want to put them in a property list.  I can do this:

(setq type-map '(char c short s int i long l))

Which works for this short list.  I don't find it particularly expressive. 
I can try playing with the format:

(setq type-map 
      '(char c 
             short s 
             int i 
             long l))

That's heading nowhere fast.
I can try adding additional pairs like this:
(setq type-map (plist-put type-map 'float 'f))

That, however, seems excessively verbose. Is there a more concise means of
adding the members of a property list in pairwise fashion?
-- 
p->m == (*p).m == p[0].m

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: How to populate a property list?
  2004-10-26 10:09 How to populate a property list? Hattuari
@ 2004-10-26 12:28 ` Thien-Thi Nguyen
  2004-10-27 20:38   ` Hattuari
  2004-10-26 15:24 ` Kevin Rodgers
  2004-10-31 14:36 ` Kai Grossjohann
  2 siblings, 1 reply; 14+ messages in thread
From: Thien-Thi Nguyen @ 2004-10-26 12:28 UTC (permalink / raw)


Hattuari <susudata@setidava.kushan.aa> writes:

> adding the members of a property list
> in pairwise fashion?

invest in some problem-specific abstraction now and you will be able
to switch to another implementation (e.g., hash tables) later, simply.
a side benefit is the conciseness you seek.

thi

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: How to populate a property list?
  2004-10-26 10:09 How to populate a property list? Hattuari
  2004-10-26 12:28 ` Thien-Thi Nguyen
@ 2004-10-26 15:24 ` Kevin Rodgers
  2004-10-30 12:05   ` Hattuari
  2004-10-31 14:36 ` Kai Grossjohann
  2 siblings, 1 reply; 14+ messages in thread
From: Kevin Rodgers @ 2004-10-26 15:24 UTC (permalink / raw)


Hattuari wrote:
 > Suppose I have a collection of key values pairs as follows:
 >
 > char  c
 > short s
 > int   i
 > long  l
 >
 > I want to put them in a property list.  I can do this:

Why a property list instead of an association list?

(setq type-map
       '((char . c)
         (short . s)
         (int . i)
         (long . l)))

-- 
Kevin Rodgers

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: How to populate a property list?
  2004-10-26 12:28 ` Thien-Thi Nguyen
@ 2004-10-27 20:38   ` Hattuari
  2004-10-31 14:39     ` Kai Grossjohann
  0 siblings, 1 reply; 14+ messages in thread
From: Hattuari @ 2004-10-27 20:38 UTC (permalink / raw)


Thien-Thi Nguyen wrote:

> Hattuari <susudata@setidava.kushan.aa> writes:
> 
>> adding the members of a property list
>> in pairwise fashion?
> 
> invest in some problem-specific abstraction now and you will be able
> to switch to another implementation (e.g., hash tables) later, simply.
> a side benefit is the conciseness you seek.
> 
> thi
I don't believe hash tables are the correct data structure for my problem. 
I believe property lists are the logically most correct in terms of
mapping.  The may, however, not be the easiest to work with.  This is the
kind of solution I was seeking:

(setq gl-type-map ())
(setq gl-type-map
      (apply 'append
         '((GLbyte     b)
           (GLshort    s)
           (GLint      i)
           (GLsizei    i)
           (GLfloat    f)
           (GLclampf   f)
           (GLdouble   d)
           (GLclampd   d)
           (GLubyte    ub)
           (GLboolean  ub)
           (GLushort   us)
           (GLuint     ui)
           (GLenum     ui)
           (GLbitfield ui))))
-- 
p->m == (*p).m == p[0].m

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: How to populate a property list?
  2004-10-26 15:24 ` Kevin Rodgers
@ 2004-10-30 12:05   ` Hattuari
  2004-10-30 17:12     ` Thien-Thi Nguyen
  0 siblings, 1 reply; 14+ messages in thread
From: Hattuari @ 2004-10-30 12:05 UTC (permalink / raw)


Kevin Rodgers wrote:

> Hattuari wrote:
>  > Suppose I have a collection of key values pairs as follows:
>  >
>  > char  c
>  > short s
>  > int   i
>  > long  l
>  >
>  > I want to put them in a property list.  I can do this:
> 
> Why a property list instead of an association list?
> 
> (setq type-map
>        '((char . c)
>          (short . s)
>          (int . i)
>          (long . l)))
> 

I didn't notice this message until just now.  It must have taken the long
way around to the server I read from.  The aspect of a plist which fits my
situation better is that a plist has unique keys.  An alist can have
multiple instances of the same key.  Thus a plist maps more accurately to
the logical structure of my data.  I have to confess, I'm finding both
alist and plist a bit awkward to work with.  The alist isn't necessarily a
Lisp list, and the plist isn't doesn't have some of the facilities I would
like for accessing and manipulating the data.

I suspect with time I will find reasonably concise means of expressing these
operations.  Lisp requires a different kind of thinking than other
languages I've worked with.  The closest language to Lisp that I have any
significant experience with is Mathematica.
-- 
p->m == (*p).m == p[0].m

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: How to populate a property list?
  2004-10-30 12:05   ` Hattuari
@ 2004-10-30 17:12     ` Thien-Thi Nguyen
  2004-10-30 17:54       ` Hattuari
  0 siblings, 1 reply; 14+ messages in thread
From: Thien-Thi Nguyen @ 2004-10-30 17:12 UTC (permalink / raw)


Hattuari <susudata@setidava.kushan.aa> writes:

> a plist has unique keys

only if constructed that way.

consider this *scratch* buffer snapshot:

  (setq x '(:k1 1 :k2 2 :k1 42))
  
  (plist-get x :k1)
  1
  
  (plist-get (cddr x) :k1)
  42

here, `(cddr x)' has unique keys, but `x' does not.  both have the plist
form (i.e., are amenable to passing to `plist-get' or being hung off a
symbol).  if you use `x' w/ assumption of unique keys, certain usage
patterns will end up hiding the second :k1 from you but not actually
recycling it.  result: unsightly (literally!) bloat.  e.g., continuing
from above:

  (setplist 'x x)
  (:k1 1 :k2 2 :k1 42)

  (get 'x :k1)
  1

  (put 'x :k1 "one")
  "one"
  
  (get 'x :k1)
  "one"
  
all's cool from `put' and `get' pov, right?  but the truth is deeper;
ignorance of it does not make it go away:

  x
  (:k1 "one" :k2 2 :k1 42)

thi

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: How to populate a property list?
  2004-10-30 17:12     ` Thien-Thi Nguyen
@ 2004-10-30 17:54       ` Hattuari
  2004-10-30 20:17         ` Thien-Thi Nguyen
  2004-11-01 16:44         ` Kevin Rodgers
  0 siblings, 2 replies; 14+ messages in thread
From: Hattuari @ 2004-10-30 17:54 UTC (permalink / raw)


Thien-Thi Nguyen wrote:

> Hattuari <susudata@setidava.kushan.aa> writes:
> 
>> a plist has unique keys
> 
> only if constructed that way.
> 
> consider this *scratch* buffer snapshot:
> 
>   (setq x '(:k1 1 :k2 2 :k1 42))
>   
>   (plist-get x :k1)
>   1
>   
>   (plist-get (cddr x) :k1)
>   42
> 
> here, `(cddr x)' has unique keys, but `x' does not.  both have the plist
> form (i.e., are amenable to passing to `plist-get' or being hung off a
> symbol).  if you use `x' w/ assumption of unique keys, certain usage
> patterns will end up hiding the second :k1 from you but not actually
> recycling it.  result: unsightly (literally!) bloat.  e.g., continuing
> from above:
> 
>   (setplist 'x x)
>   (:k1 1 :k2 2 :k1 42)
> 
>   (get 'x :k1)
>   1
> 
>   (put 'x :k1 "one")
>   "one"
>   
>   (get 'x :k1)
>   "one"
>   
> all's cool from `put' and `get' pov, right?  but the truth is deeper;
> ignorance of it does not make it go away:
> 
>   x
>   (:k1 "one" :k2 2 :k1 42)
> 
> thi

I don't know what to make of this then:

edition 2.9 of the GNU Emacs Lisp Reference Manual, corresponding to GNU
Emacs version 21.3, §8.4.1 Property Lists and Association Lists
------------------------------------------
"Association lists (*note Association Lists::) are very similar to
property lists.  In contrast to association lists, the order of the
pairs in the property list is not significant since the property names
must be distinct."
-- 
p->m == (*p).m == p[0].m

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: How to populate a property list?
  2004-10-30 17:54       ` Hattuari
@ 2004-10-30 20:17         ` Thien-Thi Nguyen
  2004-10-31  8:32           ` Hattuari
  2004-11-01 16:44         ` Kevin Rodgers
  1 sibling, 1 reply; 14+ messages in thread
From: Thien-Thi Nguyen @ 2004-10-30 20:17 UTC (permalink / raw)


Hattuari <susudata@setidava.kushan.aa> writes:

> "[...] In contrast to association lists, the order of the pairs
> in the property list is not significant since the property names
> must be distinct."

this part of the elisp manual discusses plists in the abstract,
idealized sense.  a little further on, where actual plist-munging
funcs are documented, there is some disclaimer about enforcement.

altogether, my understanding is that the elisp manual is not a
standards document, so its use of "must" et al are not rigorous.
when i read it, i expect the documentation describing the behavior
of functions and variables to be accurate; everything else is a
bonus, a hint of what hair and bondage lies outside the pleasant
island that is emacs and elisp programming.

of course, ymmv.  you may wish for industrial strength building
materials instead of coconuts and sand castles.  that's fine, too.
every once in a while some titanic technology grounds itself out
on the emacs shore -- in time, transformed by the incessant yap,
hap, lapping of the [yhl]acker s[eu]rf (itself a {t}id{al,le}
reflection of lunatic ellipsoid centered around "know" and "do"),
it becomes coconuts and sand castles in the playful hands of the
island inhabitants, as well.

thi

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: How to populate a property list?
  2004-10-30 20:17         ` Thien-Thi Nguyen
@ 2004-10-31  8:32           ` Hattuari
  2004-10-31  8:57             ` Thien-Thi Nguyen
  2004-10-31 15:23             ` Hattuari
  0 siblings, 2 replies; 14+ messages in thread
From: Hattuari @ 2004-10-31  8:32 UTC (permalink / raw)


Thien-Thi Nguyen wrote:

> of course, ymmv.  you may wish for industrial strength building
> materials instead of coconuts and sand castles.  that's fine, too.
> every once in a while some titanic technology grounds itself out
> on the emacs shore -- in time, transformed by the incessant yap,
> hap, lapping of the [yhl]acker s[eu]rf (itself a {t}id{al,le}
> reflection of lunatic ellipsoid centered around "know" and "do"),
> it becomes coconuts and sand castles in the playful hands of the
> island inhabitants, as well.
> 
> thi

You have know idea how ironic your comments are in contrast to the culture
of C++.  
-- 
p->m == (*p).m == p[0].m

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: How to populate a property list?
  2004-10-31  8:32           ` Hattuari
@ 2004-10-31  8:57             ` Thien-Thi Nguyen
  2004-10-31 15:23             ` Hattuari
  1 sibling, 0 replies; 14+ messages in thread
From: Thien-Thi Nguyen @ 2004-10-31  8:57 UTC (permalink / raw)


Hattuari <susudata@setidava.kushan.aa> writes:

> culture of C++

i'm curious: what is the culture of C++ these dayz?

thi

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: How to populate a property list?
  2004-10-26 10:09 How to populate a property list? Hattuari
  2004-10-26 12:28 ` Thien-Thi Nguyen
  2004-10-26 15:24 ` Kevin Rodgers
@ 2004-10-31 14:36 ` Kai Grossjohann
  2 siblings, 0 replies; 14+ messages in thread
From: Kai Grossjohann @ 2004-10-31 14:36 UTC (permalink / raw)


Hattuari <susudata@setidava.kushan.aa> writes:

> I want to put them in a property list.  I can do this:
>
> (setq type-map '(char c short s int i long l))
>
> Which works for this short list.  I don't find it particularly
> expressive.

Well, it is not pretty, but it works.  And it is concise, too.

If it is only the indentation that's wrong, then perhaps a trick such
as the following could be useful:

(setq type-map (cdr '(dummy
                      char c
                      short s
                      int i
                      long l)))

I'm not convinced of the merits of this approach, though.

Kai

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: How to populate a property list?
  2004-10-27 20:38   ` Hattuari
@ 2004-10-31 14:39     ` Kai Grossjohann
  0 siblings, 0 replies; 14+ messages in thread
From: Kai Grossjohann @ 2004-10-31 14:39 UTC (permalink / raw)


Hattuari <susudata@setidava.kushan.aa> writes:

> I don't believe hash tables are the correct data structure for my
> problem.

What's wrong about hash tables?  Hash tables map keys to values, order
of keys is not significant and keys are unique.  Those are the
properties you were asking for, I think.

I'd use alists, though.  Even though the uniqueness of the values is
not guaranteed, alists are used very often in Emacs lisp and thus any
reader will instantly see what you are getting at.  When people see a
plist instead, they will think:  Why did the author avoid alists?
When people see a hash table, they will think:  This must be getting
big.

Kai

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: How to populate a property list?
  2004-10-31  8:32           ` Hattuari
  2004-10-31  8:57             ` Thien-Thi Nguyen
@ 2004-10-31 15:23             ` Hattuari
  1 sibling, 0 replies; 14+ messages in thread
From: Hattuari @ 2004-10-31 15:23 UTC (permalink / raw)


Hattuari wrote:

> Thien-Thi Nguyen wrote:
> 
>> of course, ymmv.  you may wish for industrial strength building
>> materials instead of coconuts and sand castles.  that's fine, too.
>> every once in a while some titanic technology grounds itself out
>> on the emacs shore -- in time, transformed by the incessant yap,
>> hap, lapping of the [yhl]acker s[eu]rf (itself a {t}id{al,le}
>> reflection of lunatic ellipsoid centered around "know" and "do"),
>> it becomes coconuts and sand castles in the playful hands of the
>> island inhabitants, as well.
>> 
>> thi
> 
> You have know idea how ironic your comments are in contrast to the culture
> of C++.
Here people throw coconuts at you when they don't like what you say.  On
comp.lang.c++ they throw knives. Seriously.  In the C++ community there is
a certain obsession about specifying things exactly (note that I did not
say clearly), and an expectation that things behave as specified.  
-- 
p->m == (*p).m == p[0].m

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: How to populate a property list?
  2004-10-30 17:54       ` Hattuari
  2004-10-30 20:17         ` Thien-Thi Nguyen
@ 2004-11-01 16:44         ` Kevin Rodgers
  1 sibling, 0 replies; 14+ messages in thread
From: Kevin Rodgers @ 2004-11-01 16:44 UTC (permalink / raw)


Hattuari wrote:
 > I don't know what to make of this then:
 >
 > edition 2.9 of the GNU Emacs Lisp Reference Manual, corresponding to GNU
 > Emacs version 21.3, ?8.4.1 Property Lists and Association Lists
 > ------------------------------------------
 > "Association lists (*note Association Lists::) are very similar to
 > property lists.  In contrast to association lists, the order of the
 > pairs in the property list is not significant since the property names
 > must be distinct."

The documentation focuses almost completely on property lists attached
to the property list cell of a symbol.  Only the "Other Plists" node
(aka Property Lists Outside Symbols) discusses disembodied property
lists (as the are known in other Lisp dialects).  Note that you will
never get a property with duplicate keys if you construct it solely with
put and plist-put.

-- 
Kevin Rodgers

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2004-11-01 16:44 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-10-26 10:09 How to populate a property list? Hattuari
2004-10-26 12:28 ` Thien-Thi Nguyen
2004-10-27 20:38   ` Hattuari
2004-10-31 14:39     ` Kai Grossjohann
2004-10-26 15:24 ` Kevin Rodgers
2004-10-30 12:05   ` Hattuari
2004-10-30 17:12     ` Thien-Thi Nguyen
2004-10-30 17:54       ` Hattuari
2004-10-30 20:17         ` Thien-Thi Nguyen
2004-10-31  8:32           ` Hattuari
2004-10-31  8:57             ` Thien-Thi Nguyen
2004-10-31 15:23             ` Hattuari
2004-11-01 16:44         ` Kevin Rodgers
2004-10-31 14:36 ` Kai Grossjohann

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.