Version 0 of C struct is Tcl!

Updated 2002-10-08 22:34:51

This comes up every so often on comp.lang.tcl:

 Chris Nelson wrote:
 > For example, whereas I might write C like:
 > 
 >     struct s {
 >        int foo
 >        char bar
 >        float grill
 >     } 
 > 
 >     s.foo = 1;
 >     s.bar = 'c';
 >     s.grill = 3.14159;

 proc struct { name thingys } {
     foreach thing $thingys {
        uplevel set $name.$thing \[ list \]
     }
 }

 struct s {
   foo
   bar
   grill
 }

 set s.foo 1
 set s.bar c
 set s.grill 3.14159

Of course, you probably dont just want to init the "struct" to nulls, but to reasonable values:

 proc struct { name thingys } {
     foreach { key value } $thingys {
        uplevel set $name.$key $value 
     } 
 }

 struct s {
   foo 1
   bar c
   grill 3.14159
 }