Expressing range constraints in CNF form

ketmar via Digitalmars-d digitalmars-d at puremagic.com
Sun Jun 11 12:51:11 PDT 2017


Walter Bright wrote:

> On 6/11/2017 8:25 AM, Andrei Alexandrescu wrote:
>> Ostensibly the function is trivial:
>> bool msg(string) { return true; }
>> It doesn't change the semantics. The compiler would recognize it as an 
>> intrinsic and would print the message if the clause to its left has 
>> failed.
>
> There was a proposal a while back to enable CTFE to print messages, which 
> is probably a better solution. msg() could be something along the lines 
> of:
>
>      bool msg(string) { __ctfeprint(string); return true; }
>
> which would involve considerably less compiler magic. Furthermore, `msg` 
> could be a local private function, which would avoid "but I'm already 
> using `msg`" problems.

i think, that something like `__constraint(condition, "message")` is ok, 
and it should be built-in, just like `__traits()`. so compiler can collect 
those messages, and only show 'em if the matcher is failed to find 
anything. yeah, another hack in interpreter, but fairly small, and should 
solve "what constraint is really failed" problem.


More information about the Digitalmars-d mailing list