dicts (map 'm' type?)

David A. Wheeler dwheeler@dwheeler.com
Thu Jan 27 19:51:03 PST 2005


Havoc Pennington wrote:
> I had yet another idea of how to do dicts.
> 
> Reviewing previous ideas, we have:
> 
>  - in the Introspect() data, hint that an array of struct is really a
> dict
>  - in the signature, have a typecode preceding the array of struct
> indicating
>    that it's really a dict
...
> Here is my latest idea. The signature for a method that takes a
> dict<string,int> is
> "a{si}" or "array of dict entry of string,int"
> 
> In other words rather than introducing a dict type, introduce a dict
> entry type.



Just to round out the options, here's yet another option:
have a 'map' type (say 'm' for 'map') that has exactly
the same meaning as an array ('a') EXCEPT
that it requires that keys be unique.
This is very much like the 2nd option you listed -
"in the signature, have a typecode preceding the array of
struct indicating that it's really a dict", except instead
of having a prefix to 'a' that then requires special casing,
just have a single typecode that tells you what
you need to know.

You could require a map to only contain structures;
if you require that the first structure element be the key,
it's pretty straightforward. E.G., a map of string to int:
   m(si)

You could even allow non-structs to be in a map, where
each is a key; that would basically be a set.
Not sure that's worth it, though a simple notation saying
"this is a set" is kind of interesting.

I've no idea if that's any better than the other
options, but at least it's yet another option.

--- David A. Wheeler



More information about the dbus mailing list