To help LDC/GDC

Manu turkeyman at gmail.com
Tue Apr 9 05:24:28 PDT 2013


On 9 April 2013 21:30, tn <no at email.com> wrote:

> On Tuesday, 9 April 2013 at 08:33:53 UTC, Manu wrote:
>
>> On 9 April 2013 18:04, Dicebot <m.strashun at gmail.com> wrote:
>>
>>  On Tuesday, 9 April 2013 at 07:57:37 UTC, Manu wrote:
>>>
>>>  Are you saying the example above is not actually valid code?
>>>>
>>>> struct Foo {
>>>>     int a = 0;
>>>>     pure int bar( int n ) { // Weakly pure
>>>>         a += n;
>>>>         return a;
>>>>     }
>>>> }
>>>>
>>>> That's not pure. Call it twice with the same args, you'll different
>>>> answers. How can that possibly be considered pure in any sense?
>>>> And it's useless in terms of optimisation, so why bother at all? What
>>>> does
>>>> it offer?
>>>>
>>>>
>>> It is valid code. It is "weak pure". "pure' keyword means both
>>> "strong pure" or "weak pure" depending on function body. Crap.
>>>
>>>
>> How can 'weak pure' reasonably be called any kind of 'pure'? It's not pure
>> at all. The function returns a completely different result when called
>> twice.
>>
>
> The returned results are different because the parameters you are calling
> it with are different. Note that for member functions 'this' is also passed
> implicitly as a ref parameter. On the second call it has different value
> than on the first call. If you don't want to allow mutating 'this' you
> should make the function const, thus making the implicit 'this' parameter
> const ref.
>

Ah, yes. Good point. I don't know how I missed that point prior!
Okay sir, I buy your argument! :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130409/5b2a3a5a/attachment.html>


More information about the Digitalmars-d mailing list