Is there any hope for "lazy" and @nogc?

Guillaume Boucher guillaume.boucher.d at outlook.com
Tue Jul 31 09:06:28 UTC 2018


On Tuesday, 31 July 2018 at 07:49:40 UTC, Shachar Shemesh wrote:
> On 31/07/18 10:29, Mike Franklin wrote:
>> Please clarify if I'm missing the point.
>
> You are. I want something along the lines of:
> assertEQ(a, b, "a and b are not equal");
>
> When run, it would issue an assert that says:
> Assertion failed: 3!=7: a and b are not equal

What D really needs is power asserts.  assertEQ's and its 
companions (assertLT, assertLE, ...) feel just like hacks.

Power asserts come from Groovy and look like this 
(http://groovy-lang.org/semantics.html#_power_assertion):

assert calc(x,y) == [x,z].sum()
        |    | |  |   | |  |
        15   2 7  |   2 5  7
                  false

A poorer version exists in C++ 
(https://www.boost.org/doc/libs/1_67_0/libs/test/doc/html/boost_test/testing_tools/boost_test_universal_macro.html)
and of course any language with decent metaprogramming facilities 
can implement them as a library solution (such as Rust: 
https://github.com/gifnksm/power-assert-rs and Go: 
https://github.com/ToQoz/gopwt).
If you can not go the route of metaprogramming, provide an assert 
backend (Javascript: 
https://github.com/power-assert-js/power-assert).
D needs something like this as well, and you can not get there 
just with lazy.


More information about the Digitalmars-d mailing list