The Expressive C++17 Coding Challenge in D

Steven Schveighoffer schveiguy at yahoo.com
Thu Feb 15 19:36:33 UTC 2018


On 2/15/18 2:11 PM, Seb wrote:

> I reworded the entire paragraph and it now shows the AST:
> 
> https://seb.wilzba.ch/b/2018/02/the-expressive-c17-coding-challenge-in-d/#4-whats-up-with-this-enforce 

eh...

"string which is an alias for an array of const(char) elements"

It's not actually, it's an array of immutable(char) elements.

But I think the reason we see const(char)[] delegate and not 
immutable(char)[] delegate, is that enforce's actual signature is:

T enforce(E : Throwable = Exception, T)(T value, lazy const(char)[] msg 
= null, string file = __FILE__, size_t line = __LINE__)

Not lazy string as you originally said.

https://dlang.org/phobos/std_exception.html#.enforce

In fact, you can see "string" output by the AST generator in other 
places (e.g. void main(string[] args) ), so even that whole explanation 
that it has "resolved" string already is misleading ;)

BTW, I have to click on the AST button on run.dlang.io (at least on my 
browser) to see the generated AST, it's not done automatically.

> My idea was that we have this subtextual message: "look, D isn't 
> complicated and we can always look behind the scenes".

I like the message, a lot! I think it's a very nice way to show some 
well-written D code while explaining each part so they make sense to 
outsiders.

-Steve


More information about the Digitalmars-d-announce mailing list