I've implemented a dictionary locale rather than a class that encapsulates data.
A dictionary is 2 boxes. One for list of keys (as symbols), the other for list of values. If you box that (now just one box), and associate it with a key, you have a new dictionary. I provide a dsl to do this in one step, where key1 is the key to "whole" sub dictionary. ". kvdsL 'key1 ` keys1 keys2 ` 1 2' NB. ". will process last "cut" in this case storing numeric values. ┌─────┬────────────┐ │`key1│┌──────────┐│ │ ││┌──────┬─┐││ │ │││`keys1│1│││ │ │││`keys2│2│││ │ ││└──────┴─┘││ │ │└──────────┘│ └─────┴────────────┘ without dsl, this can also be done as: 'key1' kvbulk < 'keys1 keys2' kvbulk 1 2 You can access the deep keys1, the long way: 'keys1' kv 'key1' kv d=. ". kvdsL 'key1 ` keys1 keys2 ` 1 2' 1 or the short way. 'key1 ` keys2 keys1 keynotfound' kvd d 2 1 kv also supports multiple key requests. for kvd(eep), the last box (as cut by `) can have multiple keys (space separated). Results are unboxed if internals of dictionary allow native data, and in order of key proviided, and any missing keys don't affect result. If only missing keys provided, then i.0 returned. A readable list of test code and test output (strong focus on embedded dictionaries) at https://raw.githubusercontent.com/Pascal-J/kv/main/README.md On Friday, February 11, 2022, 06:51:00 p.m. EST, Raoul Schorer <raoul.scho...@gmail.com> wrote: Cool! So, to follow up on my newbie assessment from a few days ago: How did you handle the problem of dict in dict? Maybe you've written that above, but explain like I'm 5 ;-) Cheers! Raoul Le ven. 11 févr. 2022 à 23:52, 'Pascal Jasmin' via Programming < programm...@jsoftware.com> a écrit : > https://github.com/Pascal-J/kv/blob/main/kv.ijs > > follows closely to spec I proposed earlier this week. > > > intended for coinsert 'kv' into any other locale. (should be) safe for > coinsert_z_ 'kv' (base needs extra coinsert 'z' call) > > unique key implied access even when non-unique keys permitted. > > create(bulk), add, del, update/set all have versions to allow/avoid > duplicates. 1 suffix permits duplicates > > optimized for bulk operations, where arguments to functions are either a > list of keys, or a kv dictionary. > > kv dictionary always y argument. modifications return copies. > > A DSL is provided to permit one line string descriptions of the simplest > dictionaries. > > Non-unique key implementation can still provide unique key expected > behaviour. add appending a duplicate value creates an undo operation when > del deletes the last value. > > kvadd1 instead of kvadd > > Multiple internal keys also permit using kv with meaningful order and > /.(key) "applications" and classifiers. > > tosym replacement for s: cut instead of leading delimiter. tosym on > symbols returns the symbols instead of error. > > values kept native numeric or string (padded) if possible. Otherwise boxed. > > values can hold other kv structures, and so may wish to hold 3 independent > dictionaries for each data type: numeric, string, boxed. > > kv (get) function returns values only for keys found, returns i.0 if no > keys found. > > adding or updating unboxed values will promote to boxed if internal values > are boxed. > > deep operations are supported, where typical kv right arguments (set add) > will when provided with nested k1;(kv) : > > will modify kv deeply with (k0 kvbulk (keys;vals) set kvdata will set at > k0 level. > > get/del can access/del at infinte depth. > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm