On Thursday, 11 April 2013 at 10:27:55 UTC, kenji hara wrote:
2013/4/11 John Colvin <john.loughran.col...@gmail.com>
On Thursday, 11 April 2013 at 10:03:39 UTC, deadalnix wrote:
On Thursday, 11 April 2013 at 08:36:13 UTC, Joseph Rushton
Wakeling wrote:
On 04/10/2013 08:39 PM, Walter Bright wrote:
Sure there is. Declare the function as pure, and the
function's
parameters as
const or immutable.
Sure, I accept that. What I was meaning, though, was an
up-front
declaration
which would make the compiler shout if those necessary
conditions were
not met.
i.e.
pure foo(int n) { ... } // compiles
strong pure bar(int n) { ... } // compiler instructs
you to make
// variables const or
immutable
Both are strongly pure.
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).
Is the same for structs that contain no indirection? Or do
they have to be
const/immutable?
It is same for structs that has no *mutable* indirections. In
below, all
functions are strongly pure.
module x;
struct S1 { int n; }
struct S2 { immutable int[] arr; }
struct S3 { int[] arr; }
pure int foo0(int n);
pure int foo1(S1); // S1 has no indirections
pure int foo2(S2); // S2 has no *mutable* indirections
pure int foo3(immutable ref S3 x); // foo3 cannot access any
mutable
indirections
Kenji Hara
right, gotcha!