On Saturday, 14 April 2012 at 19:40:06 UTC, Aleksandar Ružičić
wrote:
On Saturday, 14 April 2012 at 19:17:52 UTC, Xan wrote:
Hi,
I try to translate a script I wrote in Fantom
[www.fantom.org]. In my script, I have a type "Tag" defined as
a triple of:
- String (the name of the tag),
- Type (the type of the tag: could be Str, Date, Int, etc.)
- Obj (the value of the tag; Fantom has Objects of Top-Class
hierachy).
(normally the tag has Type = Obj.Type, but you can manually
set).
For example,
you could have:
(name, Str#, "John")
or
(date, Date#, 2011-09-02)
(# is the Fantom way for specifying type: Str# is the sys::Str
type)
Is there any way for emulating this? My main trouble is how to
define Type and Object in D.
Thanks in advance,
Xan.
PS: Please, be patient, I'm a newbee.
For "Type" look at enum (http://dlang.org/enum.html) and for
"Object" look at std.variant
(http://dlang.org/phobos/std_variant.html).
And since Variant can tell you what type it contains you might
no longer need that "Type" parameter.
I think it's not what I expect. Can I have a generic object type?
Something like an assigment like:
Any a
?
With templates?
Please, guide me. I'm a newbee