--- Comment #3 from Denis Shelomovskij <> 2012-06-02 
14:29:01 MSD ---
(In reply to comment #1)
> The current behavior is by design, and perfectly fine – note that `pure` in D
> just means that a function doesn't access global (mutable) state. A pointer
> somewhere isn't a problem either, since the caller must have obtained the
> address from somewhere, and if it was indeed from global state, the calling
> code couldn't be pure.

OK. Looks like everything works but I don't understand how. So could you please
answer the question (read this to the end).

According to
> Pure functions are functions that produce the same result for the same 
> arguments.

And my original question is
> The Question: What exactly does these pure functions consider as `argument
value` and as `returned value`?

int f(in int* p) pure;

void g()
    auto arr = new int[5];
    auto res = f(arr.ptr);

    assert(res == f(arr.ptr));

    assert(res == f(arr.ptr + 1)); // *p isn't changed

    arr[1] = 7;
    assert(res == f(arr.ptr)); // neither p nor *p is changed

    arr[0] = 7;
    assert(res == f(arr.ptr)); // p isn't changed
Which asserts must pass?

The second assert is here according to  (yes, it's "Indirections in
the Return Type?" section, but sentences looks general and I think it can be
treated this way):
> The first essential point are addresses, respectively the definition of 
> equality applied when considering referential transparency. In functional 
> languages, the actual memory address that some value resides at is usually of 
> little to no importance. D being a system programming language, however, 
> exposes this concept.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to