News for hackers. Stuff that matters.
Re:Losing the Magic by fuball63 on Wednesday December 07, 2022 @02:30PM (#33899040)
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

There are no comments on this comment yet.