D对这些功能是否足够强大? [英] Is D powerful enough for these features?

查看:78
本文介绍了D对这些功能是否足够强大?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在最长的时间内,我想设计一种将可扩展性与效率(以及安全性,易用性等)结合在一起的编程语言,最近我重新发现了D,我想知道D 2.0是否真的是我想要的语言使自己.我最喜欢的是元编程的潜力.从理论上讲,D的 traits 系统能否在编译时启用以下功能?

For the longest time I wanted to design a programming language that married extensibility with efficiency (and safety, ease-of-use, etc.) I recently rediscovered D and I am wondering if D 2.0 is pretty much the language I wanted to make myself. What I love most is the potential of metaprogramming; in theory, could D's traits system enable the following features at compile time?

  1. 运行时反射:编译时反射功能是否足以在Java/.NET中构建运行时反射系统?

  1. Run-time reflection: Are the compile-time reflection features sufficient to build a run-time reflection system a la Java/.NET?

代码转换:使用元程序创建C#/C ++/etc.您每次编译D程序的版本(如果可以传播doc注释,则是加分点).

Code conversion: Using a metaprogram, create C#/C++/etc. versions of your D program every time you compile it (bonus point if doc comments can be propagated).

特质.我不是说D内置的元编程特征,而是

Traits. I don't mean the metaprogramming traits built into D, I mean object-oriented traits for class composition. A D program would indicate a set of traits to compose, and a metaprogram would compose them.

单位推断引擎:给出了用于可选地指示单位的某种符号,例如unit(value),D元程序可以检查以下代码,推断正确的单位并在最后一行发出错误消息吗? (我为 boo 编写了这样的东西,所以我可以向您保证在整个程序范围内这都是可能的):

Unit inference engine: Given some notation for optionally indicating units, e.g. unit(value), could a D metaprogram examine the following code, infer the correct units, and issue an error message on the last line? (I wrote such a thing for boo so I can assure you this is possible in general, program-wide):

auto mass = kg(2.0);
auto accel = 1.0;                      // units are strictly optional
auto force = mass*accel;
accel += metresPerSecondSquared(9.81); // units of 'force' and 'accel' are now known
force += pounds(3.0);                  // unit mismatch detected

推荐答案

运行时反射:编译时反射功能是否足以在Java/.NET中构建运行时反射系统?

Run-time reflection: Are the compile-time reflection features sufficient to build a run-time reflection system a la Java/.NET?

是的.您可以使用 __traits 获得在编译时所需的所有信息,并生成运行时反射所需的运行时数据结构.

Yes. You can get all the information you need at compile time using __traits and produce the runtime data structures you need for runtime reflection.

代码转换:使用元程序创建C#/C ++/etc.您每次编译D程序的版本(如果可以传播doc注释,则是加分点).

Code conversion: Using a metaprogram, create C#/C++/etc. versions of your D program every time you compile it (bonus point if doc comments can be propagated).

不,无论D多么强大,它都是根本不可能的.某些功能根本无法转移.例如,D有一个内联汇编器,不可能100%转换为C#.任何语言都不能无损地转换为所有其他语言.

No, it simply isn't possible no matter how powerful D is. Some features simply do not transfer over. For example, D has an inline assembler, which is 100% impossible to convert to C#. No language can losslessly convert to all other languages.

特质.我不是说D中内置的元编程特性,而是指类组合的面向对象特性. D程序将指示要构成的一组特征,而元程序将构成它们.

Traits. I don't mean the metaprogramming traits built into D, I mean object-oriented traits for class composition. A D program would indicate a set of traits to compose, and a metaprogram would compose them.

为此,您可以使用模板混合包,尽管它们不提供方法排除.

You can use template mixins for this, although they don't provide method exclusion.

单位推断引擎:给出了用于可选地指示单位的某种符号,例如unit(value),D元程序可以检查以下代码,推断正确的单位并在最后一行发出错误消息吗? (我为boo写了这样的东西,所以我可以向您保证在整个程序范围内这都是可能的):

Unit inference engine: Given some notation for optionally indicating units, e.g. unit(value), could a D metaprogram examine the following code, infer the correct units, and issue an error message on the last line? (I wrote such a thing for boo so I can assure you this is possible in general, program-wide):

是的,这在D语言中很简单.至少有一个实现 已经.

Yes, this is straightforward in D. There's at least one implementation already.

这篇关于D对这些功能是否足够强大?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆