Am Mon, 16 Apr 2012 20:52:16 +0200
schrieb "Xan" <xancor...@gmail.com>:

> Uf!, it's more than I can process....
> It's really a **complicated** thing to do that in D.

Too much information, yes. Too complicated no. :)
D is statically typed (Fantom allows both static and dynamic typing). That 
means that for every variable in your program you know beforehand what type it 
is. You say you have String, Type and Obj. Here we cannot say what type Obj is, 
because it depends on what Type says. Now you want something from a statically 
typed language, that it wasn't designed for.

You may want to adapt to the style of a statically typed language and use a 
struct:

import std.datetime;

struct Person {
        string name;  // a person has a field 'name' of type string
        Date   date;
}

This means that you cannot change the type of 'date' or 'name', and you cannot 
have a person without a date.

If you really, *really*, REALLY need the full flexibility, you can use 
Variants. You can store any data in a Variant, so it would replace Type and Obj 
in your code.

struct Tag {
        string description; // <String>: store "name", "date", etc. in this
        Variant data;       // <Type & Obj>: store "John" or Date(2012, 4, 25) 
in this
}

Many more solutions are possible, but we'd need to take a look at your code. 
Also one solution may be more flexible while another is faster. It depends a 
bit on what you expect. Every language has its pros and cons. Dynamic typing is 
not one of D's strengths, but execution speed is, for example.

-- 
Marco

Reply via email to