Associative map data structure [I6]

Is there an associative map data structure in Inform 6, like a python dictionary e.g. {“testKey” : “testValue”} associating the key “testKey” with value “testValue”. I know I7 has the concept of relationships which can serve like associative maps, but I haven’t found anything similar yet in I6.

Sidebar: is there a comprehensive list of data structures in I6? The items I’ve found in the DM (e.g. arrays) seem scattered.

There is not.

I6 is a very low-level language: it’s basically a thin veneer over assembly language, with all its apparently-high-level features (like object tree handling) actually handled by the underlying virtual machine itself! (*)

So all I6 data structures, apart from constant strings and the object tree, effectively boil down to fixed-size arrays, which can be accessed by word or by byte. Everything else is just syntactic sugar on top of that.

Objects in the object tree do have property tables, which act a bit like associative maps, but they have some odd requirements that you wouldn’t expect in a high-level language.

(*) At least, when compiling for the Z-machine; when compiling for Glulx, some shims are added for these parts.

1 Like

There’s nothing built in, but if you want to use dictionaries in Inform 6, you could try adapting the dynamic relation code from Inform 7’s runtime library, which is in Internal/I6T/RelationKind.i6t in the I7 installation.

1 Like

You could certainly write a library for it. You would probably want to use one or two arrays for storing key-value pairs, and use @scan_table to search for keys in an efficient manner.

1 Like