<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Nov 11, 2013 at 2:21 AM, Jacob Carlborg <span dir="ltr"><<a href="mailto:doob@me.com" target="_blank">doob@me.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im">On 2013-11-11 11:10, Timothee Cour wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
I would really like to use AST macros for the following use case:<br>
<br>
myAssert( x < y);<br>
//will print, on failure, a message, along with all values appearing<br>
inside macro myAssert:<br>
x<y failed: x=..., y=...<br>
<br>
myAssert( fun(x,y)==z1+z2)<br>
//likewise, but nesting down to all individual variables appearing<br>
inside the macro:<br>
x=..., y=..., fun(x,y)=..., z1=..., z2=..., bar(z1+z2)=...<br>
<br>
This would advantageously replace the plethora of unittest helpers found<br>
in other languages, eg: CHECK_EQ, CHECK_LEQ, etc.<br>
Invaluable for debugging or informative unittests and logs.<br>
</blockquote>
<br></div>
Agree. That's the first example in the DIP. Although a very simplified version.</blockquote><div><br></div><div>yes, I think your initial example becomes more interesting with this, as in its current form it can already be done in current D. <br>
</div><div><br></div><div>This would make error messages self-documenting:</div><div><br></div><div>myAssert(!file.exists );</div><div>// "!file. exists" failed: dump of AST:</div><div>file: string ="foobar.d"</div>
<div>|_file.exists: bool = false</div><div>  |_!file. exists: bool = false</div><div><br></div><div>In many cases, this would be so much more useful than an out of date / incomplete string error message, esp w a lot of variables involved.</div>
<div><br></div></div></div></div>