Hacker News new | ask | show | jobs
by fuball63 1287 days ago
This reminds me of a technique I learned from this StackOverflow answer [1] that is about creating structs/records with TCL lists and dicts. It apparently comes from LISP philosophy:

  proc mkFooBarRecord {foo bar} {
     # Keep index #0 for a "type" for easier debugging
     return [list "fooBarRecord" $foo $bar]
  }
  proc getFoo {fooBarRecord} {
     if {[lindex $fooBarRecord 0] ne "fooBarRecord"} {error "not fooBarRecord"}
     return [lindex $fooBarRecord 1]
  }

The magic number is sort of like the "0" index of the "Type" field with dicts. field.

[1] https://stackoverflow.com/a/5532898