Go Programming talk [OT]
Jesse Phillips
jessekphillips+D at gmail.com
Mon Jun 7 20:55:40 PDT 2010
Thanks, the important thing to note is that D can do what Go was doing in
the example, Sorry bearophile.
On Mon, 07 Jun 2010 19:55:06 -0500, Andrei Alexandrescu wrote:
> 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