Version 46 of Everything is a dict

Updated 2007-04-29 11:28:51 by suchenwi

Richard Suchenwirth 2007-04-29 - Of course not. Before 8.5, the concept of dict isn't even supported by the Tcl core (though an extension is available for 8.4).

But playing with Picol, and as usual pondering how to make things simpler, the following two-third-baked ideas occurred to me:

  • A callframe (the set of variables local to a proc, or globals in a namespace) could be done as a dict
  • A namespace itself needs one dict for commands, one for its child namespaces, and a callframe. As dicts can be nested, these could all go into one dict again.
  • An interpreter again needs as minimum a namespace, and a dict of its slave interpreters
  • Variable values can be dicts already, or "scalars" (by which I here mean non-dict values, but they could be lists). Stressing it a bit, a scalar could be implemented as a one-element dict with NULL key.

One consequence of this could be to expose more of the internals to the scripting side. For instance, if _C is the commands dict of the current namespace, and _V the same for variables,

 dict keys $::_C ;# info commands
 dict keys $::_V ;# info globals

so generic dict routines could replace the more specific ones.

Further phantasizing,

 dict set ::_C foo {call MyFooImpl}

could do the registering of a C-coded command, where the generic call command locates the given symbol in symbol tables, prepares objc/objv and.. calls it.

What do y'all think?


Category Discussion