Thanks, Steven!<br><br>You don&#39;t want to know what I&#39;m up to :p.<br><br>I&#39;m using some traits to find out what kind of parameters a function takes. I&#39;m also using a demangler from phobos to find out the name of the function (But I can&#39;t find any straightforward way to get a name of a function without getting back &quot;1D_5std_5funcName&quot; etc, so I just take a hardcoded slice).<br>
<br>Anyway, I have a template function which takes as it&#39;s parameters a function (aliased to func), and some arguments (right now just one in my hardcoded code). It then creates a string which can be compiled via the mixin. It constructs the string by checking the parameter types of func, and for any ref or out parameter it detects it appends something like this to a string:<br>
&quot;long var1; long var2; long var3; &quot;.<br><br>For any non-out/ref parameters it constructs another string which will call that func (here is where I&#39;m using the demangler to get the real name of the function). So the other string would eventually look like so:<br>
&quot;funcName(argN.., var1, var2, var3);<br><br>It then concatenates both strings and returns it, creating the whole shebang:<br>&quot;int var1; double var2; funcName(argN..., var1, var2, var3);&quot;<br><br>This can then be used with mixin() at the calling site. I was inspiried to try this out when bearophile wanted some new tuple syntax assignment in D.<br>
<br>So anyway, at the calling site I have this:<br><br>mixin(unpack!(getTimes)(r&quot;C:\\cookies&quot;));<br><br>getTimes() is a Phobos function with the signature:<br>getTimes(in char[] name, out d_time ftc, out d_time fta, out d_time ftm)<br>
<br>And now I automatically have var1, var2, and var3 at my disposal. <br><br>It was just an exercise for fun but it&#39;s cool that things like this are possible in D. It would be nice if I could get the actual names of the parameters the function takes + the clear name of the function itself, that way I&#39;d actually get back variables &quot;ftc, fta, ftm&quot; back).<br>
<br>Right now the code is a big mess but I could fix it up a lot and post it here if anyone cares.<br><br><div class="gmail_quote">On Thu, Aug 5, 2010 at 9:48 PM, Steven Schveighoffer <span dir="ltr">&lt;<a href="mailto:schveiguy@yahoo.com">schveiguy@yahoo.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="im">On Thu, 05 Aug 2010 15:34:44 -0400, Tomek Sowiński &lt;<a href="mailto:just@ask.me" target="_blank">just@ask.me</a>&gt; wrote:<br>

<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Andrej Mitrovic napisał:<br>
<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hmm.. ok. Adding immutable helps. I&#39;m still a bit confused tho,<br>
 because this will not compile:<br>
<br>
string input2 = &quot;int y;&quot;;<br>
mixin(input2);<br>
</blockquote>
<br>
input2 is mutable, so theoretically there&#39;s no telling what value it holds.<br>
</blockquote>
<br></div>
Before you respond with more WTF, there is a subtlety here :)<br>
<br>
A string is aliased to immutable(char)[].  This means that the *data* pointed at is immutable but the *array* is mutable.  You can reassign a string to point at some other immutable data, or change the length of the array.  To illustrate this:<br>

<br>
string input2 = &quot;int y;&quot;;<br>
<br>
static this()<br>
{<br>
   input2 = &quot;int x;&quot;; // perfectly legal<br>
}<br>
<br>
mixin(input2); // what does this do?<br>
<br>
Now, immutable string means:<br>
<br>
immutable(immutable(char)[]), which reduces to immutable(char[]), meaning both the data pointed at *and* the array are immutable (note the distinction of where the parentheses are).  This can be used in CTFE and mixins because the compiler knows the value is completely defined at compile-time.<br>

<br>
strings (the kind where the array part is mutable) can be used as mixins as long as they are rvalues, such as the returns from functions which are CTFE capable.<br>
<br>
-Steve<br>
</blockquote></div><br>