Plists (maps / dicts) in Dialog

Dynamic Predicates limited to two parameters got me thinking about ways to represent map-like datastructures in Dialog. (Since that’s the data structure I think most programmers would normally reach for to solve problems like the one in that post.)

Anyways, here’s a snippet of Dialog that implements “plists” – which IIUC is a common way to solve this sort of problem in Lisp, where they’ve suffered from having only lists to work with for much longer. Effectively: you have lists of even length, alternating between keys and values, and a handful of helper predicates that make manipulating those lists not extremely tedious.

Still getting the hang of Dialog, so it may not be the ideal version, but perhaps interesting still…


This looks quite interesting, ill definitely have to mess aroundcwitg this a bit when i get the chance. I’m curious if your first predicate can handle nested plists or if $v would onpy matvh the whole list? If it could not find a nestd $v do you thinkbit would be possible to create a predicate whoch handles noth the case where $v is nested or not nested, or would seperate predicates be needed for both cases?

As-is, looking up a key grabs the entire corresponding value. So, for example,

($plist = [#k1 100 #k2 [#k3 70]])
(plist $plist key #k2 has value $out)

prints [#k3 70]. So a plist can contain a plist, and the lookup works just like it would for any other value. Sort of like a dict in python or an object in javascript, I guess.

(But of course that’s just what I happened to implement! This sort of datastructure is pretty flexible… if you’re looking for some other behaviour we can probably come up with something.)

1 Like