Proposal: Relax rules for 'pure'
Michel Fortin
michel.fortin at michelf.com
Thu Sep 23 14:39:21 PDT 2010
On 2010-09-23 16:24:20 -0400, Tomek Sowiński <just at ask.me> said:
> Michel Fortin napisał:
>
>> The interesting thing with this change is that you can now call
>> mutators functions on the local variables inside the pure function,
>> because those can be made pure. You can't even iterate over a range
>> inside a pure function without this!
>>
>> pure int test() {
>> int result;
>> auto r = iota(0, 10);
>> while (!r.empty) {
>> result += r;
>> r.popFront(); // can't be pure by current rules!
>> }
>> return result;
>> }
>
> It's because popFront() can't be made pure. It could be if there was
> @tail immutable in the
> language -- pure functions would mark their arguments with @tail
> immutable instead of
> immutable. That allows popFront() to advance the range.
I know popFront() can't be made pure by the current rules. The proposal
that started this thread is to relax 'pure' so that popFront() can be
made pure. I was simply pointing a use case for that.
And to tell the truth, I have no idea where a tail-immutable qualifier
would be helpful in this situation... could you elaborate?
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the Digitalmars-d
mailing list