Go Programming talk [OT]

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon Jun 7 17:55:06 PDT 2010


On 06/07/2010 07:44 PM, Jesse Phillips wrote:
> On Sun, 06 Jun 2010 18:13:36 -0400, bearophile wrote:
>
>> At 9.30 you can see the switch used on a type type :-) You can see a
>> similar example here:
>> http://golang.org/src/pkg/exp/datafmt/datafmt.go Look for the line
>> switch t := fexpr.(type) {
>>
>> ...
>>
>> Bye,
>> bearophile
>
> That isn't a type type. Untested D code
>
> void fun(T, U)(T op, U y) {
>
>      switch(typeof(y)) {
>           case "immutable(char)[]":
>           case "int":
>      }
> }

Actually the uses are not equivalent. A closer example is:

class A {}

void main() {
     Object a = new A;
     switch (typeid(a).name) {
         case "object.Object":
             writeln("it's an object");
             break;
         case "test.A":
             writeln("yeah, it's an A");
             break;
         default:
             writeln("default: ", typeid(a).name);
             break;
     }
}

Go stores the dynamic types together with objects, so what looks like a 
simple typedef for int is in fact a full-fledged class with one data 
member. Those objects are stored on the garbage-collected heap.


Andrei


More information about the Digitalmars-d mailing list