Version 4 of huddle

Updated 2008-06-03 12:48:23 by kanryu

Tcl's containers are very simple, but it is not distinguished mutually.

Although the advantage on code description also exists, it becomes a big fault at the time of file reading and the beginning.


Huddle provides a generic Tcl-based serialization/intermediary format. Currently, each node is wrapped in a tag with simple type information. Huddle object can contain both dicts and list with mixed. Also it can add other types with user-callback. http://sourceforge.net/tracker/index.php?func=detail&aid=1970893&group_id=12883&atid=362883


AK let me try to describe it in my own words.

  1. Huddle provides a generic Tcl-based serialization format
  2. The entries in that format are tagged with simple type information
  3. The currently the known types are 'L' for list, and 'D' for dict.
  4. When converting huddle-notation to other serialization formats like JSON or YAML this type information is used to select the proper notation.
  5. And when going from JSON/YAML/... to huddle their notation can be used to select the proper huddle type.
  6. In that manner huddle can serve as a common intermediary format.
  7. The nice thing about its notation that Tcl can read this format directly
    (list/dict commands) without the need for a special parser.

Working Sampple:

 # create as a dict
 % set bb [huddle create a b c d]
 HUDDLE {D {a {s b} c {s d}}}

 # create as a list
 % set cc [huddle list e f g h]
 HUDDLE {L {{s e} {s f} {s g} {s h}}}
 % set bbcc [huddle create bb $bb cc $cc]
 HUDDLE {D {bb {D {a {s b} c {s d}}} cc {L {{s e} {s f} {s g} {s h}}}}}
 % set folding [huddle list $bbcc p [huddle list q r] s]
 HUDDLE {L {{D {bb {D {a {s b} c {s d}}} cc {L {{s e} {s f} {s g} {s h}}}}} {s p} {L {{s q} {s r}}} {s s}}}

 # normal Tcl's notation
 % huddle strip $folding
 {bb {a b c d} cc {e f g h}} p {q r} s

 # get a sub node
 % huddle get $folding 0 bb
 HUDDLE {D {a {s b} c {s d}}}
 % huddle gets $folding 0 bb
 a b c d

 # overwrite a node
 % huddle set folding 0 bb c kkk
 HUDDLE {L {{D {bb {D {a {s b} c {s kkk}}} cc {L {{s e} {s f} {s g} {s h}}}}} {s p} {L {{s q} {s r}}} {s s}}}

 # remove a node
 % huddle remove $folding 2 1
 HUDDLE {L {{D {bb {D {a {s b} c {s kkk}}} cc {L {{s e} {s f} {s g} {s h}}}}} {s p} {L {{s q}}} {s s}}}
 % huddle strip $folding
 {bb {a b c kkk} cc {e f g h}} p {q r} s

 # dump as a JSON stream
 % huddle jsondump $folding
 [
   {
     "bb": {
       "a": "b",
       "c": "kkk"
     },
     "cc": [
       "e",
       "f",
       "g",
       "h"
     ]
   },
   "p",
   [
     "q",
     "r"
   ],
   "s"
 ]

Currently, you can get the library at head of tcllib CVS(http://tcllib.cvs.sourceforge.net/tcllib/tcllib/modules/yaml/ ) that is used to implement YAML library.