<div dir="ltr">I like the idea. I really don't like having the overhead of inner functions just for compile-time enforcement.</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Dec 28, 2012 at 2:58 PM, bearophile <span dir="ltr"><<a href="mailto:bearophileHUGS@lycos.com" target="_blank">bearophileHUGS@lycos.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Often recursive functions need some "bookkeeping" default arguments that aren't meant to be used by the user, they are meant to be used only by recursive calls:<br>

<br>
<br>
void radixSort(uint[] items, in uint shiftBits=24) {<br>
    ...<br>
    if (shiftBits > 0) {<br>
        ...<br>
        radixSort(array[...], shiftBits - 8);<br>
    }<br>
}<br>
void main() {<br>
    auto array = new uint[n];<br>
    ...<br>
    array.radixSort();<br>
}<br>
<br>
<br>
<br>
So this call is a bug:<br>
<br>
void main() {<br>
    ...<br>
    array.radixSort(26);<br>
}<br>
<br>
<br>
To avoid bugs and to not expose such private arguments I sometimes define an inner function (or a private function in a struct/class). Now the only argument of the outer function is 'items', and no mistakes can happen using radixSort2():<br>

<br>
<br>
void radixSort2(uint[] items) {<br>
    void radix(in uint shiftBits=24) {<br>
        ...<br>
        if (shiftBits > 0) {<br>
            ...<br>
            radixSort(array[...], shiftBits - 8);<br>
        }<br>
    }<br>
    radix();<br>
}<br>
<br>
<br>
This has some disadvantages.<br>
<br>
An alternative idea (that I maybe I proposed years ago in a weaker form) is to introduce 'private' default arguments (they must have a default value):<br>
<br>
<br>
void radixSort3(uint[] items, private in uint shiftBits=24) {<br>
    ...<br>
    if (shiftBits > 0) {<br>
        ...<br>
        radixSort(array[...], shiftBits - 8);<br>
    }<br>
}<br>
<br>
<br>
The 'private' means that only radixSort3 is allowed to set a shiftBits argument value. So this is reported as compilation error:<br>
<br>
void main() {<br>
    ...<br>
    array.radixSort(26);<br>
}<br>
<br>
<br>
A more detailed proposal, almost a DEP:<br>
<a href="http://d.puremagic.com/issues/show_bug.cgi?id=9229" target="_blank">http://d.puremagic.com/issues/<u></u>show_bug.cgi?id=9229</a><br>
<br>
Is this little feature worth the amount of language complexity increase it causes?<br>
<br>
Bye,<br>
bearophile<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Bye,<br>Gor Gyolchanyan.
</div>