Ordered property lists, possible bug?

Hello eggplanters,

I’m trying to create an ordered list of key-value pairs, and eggplant keeps alphabetizing my property list!

Example:


put (abc: 5, zxy: 6, cde: 7) into foo
put foo
(abc:"5", cde:"7", zxy:"6")

Is there any way to have an ordered list of key-value pairs in sensetalk?

I’d like item 2 of foo to be (xyz: 6), not (cde: 7)

Thanks,

Matt Stone

In SenseTalk, lists are ordered, but property lists are inherently unordered: each property is identified by its key, but there is no actual order to them. So you can’t ask for item 2 of a property list – it doesn’t mean anything.

To make it easier for people to work with property lists, whenever a property list is displayed, SenseTalk shows the properties in alphabetical order of their keys. This is also true of the keys() and values() functions.

So I’m afraid there isn’t any way in SenseTalk to have exactly what you’re asking for: a list of items that is both in a particular order and that has values that can be accessed by a key. You can have one or the other but not both. Depending on how you need to access the values, you might get by with a list of key/value pairs (maybe structured as a list of lists) but you’ll have to write your own functions for accessing the values by their key in that case.

[quote=“SenseTalkDoug”]In SenseTalk, lists are ordered, but property lists are inherently unordered: each property is identified by its key, but there is no actual order to them. So you can’t ask for item 2 of a property list – it doesn’t mean anything.

To make it easier for people to work with property lists, whenever a property list is displayed, SenseTalk shows the properties in alphabetical order of their keys. This is also true of the keys() and values() functions.

So I’m afraid there isn’t any way in SenseTalk to have exactly what you’re asking for: a list of items that is both in a particular order and that has values that can be accessed by a key. You can have one or the other but not both. Depending on how you need to access the values, you might get by with a list of key/value pairs (maybe structured as a list of lists) but you’ll have to write your own functions for accessing the values by their key in that case.[/quote]

Thanks SenseTalkDoug… that is what I ended up going with actually. I made a list as such:

((key,value),(key,value),…)