Compiler as dll
grauzone
none at example.net
Sat Jan 31 05:59:43 PST 2009
dsimcha wrote:
> == Quote from Yigal Chripun (yigal100 at gmail.com)'s article
>> Static languages can have Variant/box types that'll give most of the
>> same functionality of dynamic languages. so, instead of instantiating
>> list!(int), list!(string), etc, you can get one list!(Variant)..
>> C# provide such a feature with a keyword instead of rellying on templates.
>> The real difference is that static languages have mostly read-only RTTI.
>> (Java provides a very limited capability to reload classes, IIRC)
>> a scripting language allows you to manipulate Types and instances at
>> run-time, for example you can add/remove/alter methods in a class and
>> affect all instances of that class, or alter a specific instance of a
>> class. This cannot be done in a static language.
>
> Out of curiosity, does anyone actually use Variant in D? When I was new to the
> language, I thought it was a great idea, but then I discovered D templates, so now
> I never use it.
I use a Box (Variant with less features) for some kind of command line
parser.
First, one can register a callback to handle a command. This callback
takes a Box[] to carry the command arguments. When you register a
command, you pass a TypeInfo[] to tell the parser how many argument
there are and what type they must have (the Box[] types will be exactly
the same as in TypeInfo[]). The catch is, that the parser can
automatically display help messages and useful error messages if parsing
fails. The command callback doesn't need to care about this.
Second, you can register argument parsers. An argument parser is just a
simple callback again. It takes a string and returns a Box. So you can
add parsers for types, which are completely unknown to the command line
parser code.
This is nice and simple. How would you do it without Box?
More information about the Digitalmars-d
mailing list