<div dir="ltr"><div>can your '<span style="font-family:arial,sans-serif;font-size:12.727272033691406px">inspect' method handle:</span></div><div><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">* multiple arguments?</span></div>
<div><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">* expressions?</span></div><div><br></div><div>I wrote a function that does both, it's one of those things that are very useful for quick debugging:<br>
</div><div><br></div><div>import util.prettyprint;</div><div>void main(){</div><div> int x=23;</div><div> double y=2.4;</div><div> writelnL(x,y,x*y);</div><div>}</div><div><br></div><div>//output:</div><div><div>file test.d:7 {</div>
<div> x=int{23},</div><div> y=double{2.4},</div><div> x*y=double{55.2},</div><div>}</div></div><div><br></div><div>-----</div><div>The way it works:</div><div>void writelnL(string file=__FILE__, Line_t line=__LINE__, T...)(T args){</div>
<div>...</div><div>auto argNames=getArgNamesFromFile(file,line);<br></div><div>...<br></div><div>}<br></div><div><br></div><div>This reads at runtime file/line and caches the information with memoize to avoid re-reading the same file/line multiple times. I had also tried reading the file/line at compile time using import(file)[line] but that resulted in massive compile time slow-downs even when the actual writelnL wasn't used at runtime. Then the code parses the line to extract each argument names using a simplified D grammar. </div>
<div><br></div><div>However this still has some runtime penalty (reading a whole file just for 1 line) and is doing more work than necessary, as compiler has access to this info.</div><div>I've already asked for this in the past (see email: "feature request: __ARGS__ for logging (cf __FILE__, __LINE__, __FUNC___):</div>
<div><br></div><div>but Jacob pointed out that AST macros would make this un-necessary (like wise with another proposal I made "proposal: a new string litteral to embed variables in a string" ):</div><div><br></div>
<div>"<span style="font-size:12.727272033691406px;font-family:arial,sans-serif">I don't think that </span><span class="" style="font-size:12.727272033691406px;font-family:arial,sans-serif">__ARGS__</span><span style="font-size:12.727272033691406px;font-family:arial,sans-serif"> is a bad idea, I just think that there are several features in D which could be replaced with a library solution using AST macros (if those were available)"</span></div>
<div><span style="font-size:12.727272033691406px;font-family:arial,sans-serif"><br></span></div><div>So let's either get a roadmap for introducing AST macros (preferred) or let's allow this very simple <span style="font-family:arial,sans-serif;font-size:12.727272033691406px">__ARGS__ in the language.</span> </div>
<div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Nov 9, 2013 at 11:05 AM, Rob T <span dir="ltr"><<a href="mailto:alanb@ucora.com" target="_blank">alanb@ucora.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Saturday, 9 November 2013 at 11:07:08 UTC, Dicebot wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Saturday, 9 November 2013 at 09:12:21 UTC, Rob T wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
It works except when passing a variable contained inside a struct or class due to a missing "this" during evaluation, I'm also worried about template bloat.<br>
<br>
I figure mixins may help, but not if it's same or less convenient to use as the double entry method.<br>
<br>
Any suggestions, or is it just impossible or not worth trying?<br>
</blockquote>
<br>
I have not found good workaround for this so far and consider it a main use case for template alias parameter enhancement.<br>
</blockquote>
<br></div></div>
Do you know if there's already a enhancement request posted for this? I'll make one if not.<br>
</blockquote></div><br></div>