Are there any default dmd optimizations
Nick Sabalausky
SeeWebsiteToContactMe at semitwist.com
Wed Feb 27 14:55:04 PST 2013
On Wed, 27 Feb 2013 11:42:53 +0100
Jacob Carlborg <doob at me.com> wrote:
> On 2013-02-27 00:37, Andrei Alexandrescu wrote:
>
> > Agreed, but it does happen often that a language feature is later
> > superseded by a generalization thereof.
>
> In this case it would be two features:
>
> 1. Allow to run arbitrary code at top level
> 2. Allow to pass a delegate to a function after the parameter list
>
> void unittest (void delegate () dg)
>
> unittest {
> assert(true);
> }
>
> Would be lowered to:
>
> unittest({
> assert(true);
> });
>
> Then we also can easily support named unit tests:
>
> void unittest (string name, void delegate () dg)
>
> unittest("foo") {
> assert(true);
> }
>
> Would be lowered to:
>
> unittest("foo", {
> assert(true);
> });
>
> I think it would be nice if D could get better at declarative
> programming.
>
I like that, but "run arbitrary code at top level" may be a bit of a
problem because it conflicts with allowing forward references.
Ie, for example:
void foo() { bar(); }
void bar() { i = 3; }
int i;
vs:
void main() {
void foo() { bar(); }
void bar() { i = 3; }
int i;
}
The first one works, but the second doesn't. And my understanding is
that the second one not working is a deliberate thing related to
not being in a declaration-only context.
More information about the Digitalmars-d
mailing list