March 27, 2015
On Friday, 27 March 2015 at 14:29:05 UTC, Shammah Chancellor wrote:
> Pure functions returning impure functions.  *BOOM* My brain just exploded.
>
> -Shammah

I am not sure when this would happen, but why disallow it ?
March 27, 2015
On Friday, 27 March 2015 at 14:29:05 UTC, Shammah Chancellor wrote:
> On 2015-03-23 09:45:39 +0000, Dicebot said:
>
>> I think this was not intended and is simply a side effect of limited D call graph analysis. Relaxing that limitation makes sense to me because unused impure function can be used for compile-time reflection or returned from pure function as a result (you need to ensure it does not capture pure functions as closure context in that case)
>
> Pure functions returning impure functions.  *BOOM* My brain just exploded.
>
> -Shammah

As long it is exactly the same impure function for given set of arguments (including the context if any) it should comply it pure requirements, shouldn't it?
March 27, 2015
On Fri, Mar 27, 2015 at 05:28:54PM +0000, Dicebot via Digitalmars-d wrote:
> On Friday, 27 March 2015 at 14:29:05 UTC, Shammah Chancellor wrote:
> >On 2015-03-23 09:45:39 +0000, Dicebot said:
> >
> >>I think this was not intended and is simply a side effect of limited D call graph analysis. Relaxing that limitation makes sense to me because unused impure function can be used for compile-time reflection or returned from pure function as a result (you need to ensure it does not capture pure functions as closure context in that case)
> >
> >Pure functions returning impure functions.  *BOOM* My brain just exploded.
> >
> >-Shammah
> 
> As long it is exactly the same impure function for given set of arguments (including the context if any) it should comply it pure requirements, shouldn't it?

Makes sense to me.

What I'm more concerned about is whether the current compiler implementation may accidentally allow leakage of the pure function's internal context, which would break purity.


T

-- 
If you want to solve a problem, you need to address its root cause, not just its symptoms. Otherwise it's like treating cancer with Tylenol...
March 29, 2015
On Friday, 27 March 2015 at 17:47:26 UTC, H. S. Teoh wrote:
> What I'm more concerned about is whether the current compiler
> implementation may accidentally allow leakage of the pure function's
> internal context, which would break purity.
>
>
> T
please explain your reasoning with a bit of example code.
I am not sure if I get where/when impurity would be introduced.
March 30, 2015
On Sunday, 29 March 2015 at 12:29:13 UTC, Stefan Koch wrote:
> On Friday, 27 March 2015 at 17:47:26 UTC, H. S. Teoh wrote:
>> What I'm more concerned about is whether the current compiler
>> implementation may accidentally allow leakage of the pure function's
>> internal context, which would break purity.
>>
>>
>> T
> please explain your reasoning with a bit of example code.
> I am not sure if I get where/when impurity would be introduced.

void delegate() metafoo() pure
{
    int x;
    return () { x = 42; }; // now stack frame of pure function
                           // is available externally
                           // no idea what may happen
}

March 30, 2015
On Monday, 30 March 2015 at 13:18:44 UTC, Dicebot wrote:
> On Sunday, 29 March 2015 at 12:29:13 UTC, Stefan Koch wrote:
>> On Friday, 27 March 2015 at 17:47:26 UTC, H. S. Teoh wrote:
>>> What I'm more concerned about is whether the current compiler
>>> implementation may accidentally allow leakage of the pure function's
>>> internal context, which would break purity.
>>>
>>>
>>> T
>> please explain your reasoning with a bit of example code.
>> I am not sure if I get where/when impurity would be introduced.
>
> void delegate() metafoo() pure
> {
>     int x;
>     return () { x = 42; }; // now stack frame of pure function
>                            // is available externally
>                            // no idea what may happen
> }

Maybe even better:

void delegate() metafoo pure
{
    int x;
    if (x > 0)
    {
        return () => x -= 1;
    }
    else
    {
        return () => x += 1;
    }
}
March 30, 2015
On Monday, 30 March 2015 at 13:18:44 UTC, Dicebot wrote:
> On Sunday, 29 March 2015 at 12:29:13 UTC, Stefan Koch wrote:
>> On Friday, 27 March 2015 at 17:47:26 UTC, H. S. Teoh wrote:
>>> What I'm more concerned about is whether the current compiler
>>> implementation may accidentally allow leakage of the pure function's
>>> internal context, which would break purity.
>>>
>>>
>>> T
>> please explain your reasoning with a bit of example code.
>> I am not sure if I get where/when impurity would be introduced.
>
> void delegate() metafoo() pure
> {
>     int x;
>     return () { x = 42; }; // now stack frame of pure function
>                            // is available externally
>                            // no idea what may happen
> }

Hmmm... Where's the (conceptual) difference to this:

struct S {
    int x;
    void foo() pure {
        x = 42;
    }
}

S* metafoo() pure {
    auto s = new S;
    return s;
}

Why should your example be impure?
1 2
Next ›   Last »