D是否有足够的表达型系统,使其能够动态工作?

D是否有足够的表达型系统,使其能够动态工作?,d,type-systems,D,Type Systems,D是否有一个足够表达的类型系统,使其能够在静态类型框架内动态工作(即使用多个值类) 在阅读了示例代码(如果有的话)之后,我想问一下,您是否非常感谢。如果您只使用,那么D本质上是一种动态类型语言。以下是图书馆参考页中的一个使用示例: Variant a; // Must assign before use, otherwise exception ensues // Initialize with an integer; make the type int Variant b = 42; ass

D是否有一个足够表达的类型系统,使其能够在静态类型框架内动态工作(即使用多个值类)

在阅读了示例代码(如果有的话)之后,我想问一下,您是否非常感谢。

如果您只使用,那么D本质上是一种动态类型语言。以下是图书馆参考页中的一个使用示例:

Variant a; // Must assign before use, otherwise exception ensues

// Initialize with an integer; make the type int
Variant b = 42;
assert(b.type == typeid(int));

// Peek at the value
assert(b.peek!(int) !is null && *b.peek!(int) == 42);

// Automatically convert per language rules
auto x = b.get!(real);

// Assign any other type, including other variants
a = b;
a = 3.14;
assert(a.type == typeid(double));

// Implicit conversions work just as with built-in types
assert(a > b);

// Check for convertibility
assert(!a.convertsTo!(int)); // double not convertible to int

// Strings and all other arrays are supported
a = "now I'm a string";
assert(a == "now I'm a string");
a = new int[42]; // can also assign arrays
assert(a.length == 42);
a[5] = 7;
assert(a[5] == 7);

// Can also assign class values
class Foo {}
auto foo = new Foo;
a = foo;
assert(*a.peek!(Foo) == foo); // and full type information is preserved

我觉得这个问题太抽象了。你到底需要什么?但是,D是静态类型的语言,像C++一样,但是更强大。@阿伦:我不确定,但是也许<代码>变体< /代码>做你需要的。我不喜欢文章的基调。我不会说动态语言是静态语言,正如静态语言是机器代码一样。动态语言是(通常)在静态语言之上实现的抽象。完全可以在本机代码中实现动态语言,或者在动态框架上实现静态语言,或者在动态语言上实现静态语言上的动态语言!语言是从原语构建的抽象,原语可以根据语言的要求进行解释:D