<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2013/4/11 John Colvin <span dir="ltr"><<a href="mailto:john.loughran.colvin@gmail.com" target="_blank">john.loughran.colvin@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class=""><div class="h5">On Thursday, 11 April 2013 at 10:03:39 UTC, deadalnix wrote:<br>
<blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
On Thursday, 11 April 2013 at 08:36:13 UTC, Joseph Rushton Wakeling wrote:<br>
<blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
On 04/10/2013 08:39 PM, Walter Bright wrote:<br>
<blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Sure there is. Declare the function as pure, and the function's parameters as<br>
const or immutable.<br>
</blockquote>
<br>
Sure, I accept that. What I was meaning, though, was an up-front declaration<br>
which would make the compiler shout if those necessary conditions were not met.<br>
<br>
i.e.<br>
<br>
pure foo(int n) { ... } // compiles<br>
<br>
strong pure bar(int n) { ... } // compiler instructs you to make<br>
// variables const or immutable<br>
</blockquote>
<br>
Both are strongly pure.<br>
</blockquote>
<br></div></div>
is foo strongly pure because of n being a value type that cannot contain any indirection? (i.e. as far as the outside world is concerned you don't get any side effects whatever you do with it).<br>
<br>
Is the same for structs that contain no indirection? Or do they have to be const/immutable?<br>
</blockquote></div><br></div><div class="gmail_extra">It is same for structs that has no *mutable* indirections. In below, all functions are strongly pure.</div><div class="gmail_extra"><br></div><div class="gmail_extra">
module x;</div><div class="gmail_extra">struct S1 { int n; }</div><div class="gmail_extra">struct S2 { immutable int[] arr; }</div><div class="gmail_extra">struct S3 { int[] arr; }</div><div class="gmail_extra"><br></div>
<div class="gmail_extra">pure int foo0(int n);</div><div class="gmail_extra">pure int foo1(S1); // S1 has no indirections<br></div><div class="gmail_extra">pure int foo2(S2); // S2 has no *mutable* indirections<br></div>
<div class="gmail_extra"><div class="gmail_extra">pure int foo3(immutable ref S3 x); // foo3 cannot access any mutable indirections<br></div><div class="gmail_extra"><div class="gmail_extra"><br></div><div class="gmail_extra">
Kenji Hara</div></div></div></div>