www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - pure vs std.range.retro

reply John Carter <john.carter taitradio.com> writes:
Thanks for all your help understanding the algorithm chaining problem...

Now I have another gotcha.

This code compiles and runs OK if I remove the keyword "pure" or if I
remove the ".retro"

As I understand it retro should affect the "pure"ness of the the function.

If I put the keyword in, it fails to instantiate the template...
import std.algorithm;
import std.array;
import std.stdio;
import std.range;

pure auto huh( in uint[] digitArray, in uint value)
{
   return find!( (a,b) => (a > b))( digitArray.retro, value);
}

unittest {
   auto test = [11u, 1u, 1u, 10u];
   auto s = huh( test, 10u);
   writeln( s);
}

dmd -unittest -main  doesnt_work.d && ./doesnt_work
/usr/include/dmd/phobos/std/algorithm.d(3508): Error: pure function
'doesnt_work.huh' cannot call impure function
'std.range.retro!(const(uint)[]).retro.Result.popFront'
/usr/include/dmd/phobos/std/algorithm.d(3510): Error: pure function
'doesnt_work.huh' cannot call impure function
'std.range.retro!(const(uint)[]).retro.Result.front'
doesnt_work.d(8): Error: template instance doesnt_work.huh.find!(__lambda3,
Result, const(uint)) error instantiating

-- 
John Carter
Phone : (64)(3) 358 6639
Tait Electronics
PO Box 1645 Christchurch
New Zealand

-- 

------------------------------
This email, including any attachments, is only for the intended recipient. 
It is subject to copyright, is confidential and may be the subject of legal 
or other privilege, none of which is waived or lost by reason of this 
transmission.
If you are not an intended recipient, you may not use, disseminate, 
distribute or reproduce such email, any attachments, or any part thereof. 
If you have received a message in error, please notify the sender 
immediately and erase all copies of the message and any attachments.
Unfortunately, we cannot warrant that the email has not been altered or 
corrupted during transmission nor can we guarantee that any email or any 
attachments are free from computer viruses or other conditions which may 
damage or interfere with recipient data, hardware or software. The 
recipient relies upon its own procedures and assumes all risk of use and of 
opening any attachments.
------------------------------
Dec 22 2013
next sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
John Carter:

 Thanks for all your help understanding the algorithm chaining 
 problem...

 Now I have another gotcha.

 This code compiles and runs OK if I remove the keyword "pure" 
 or if I remove the ".retro"
Some functions can't be pure. Some functions can be pure but in Phobos are not yet pure, often because they call other basic functions that are not yet pure. And probably some functions are not yet pure because of some compiler bug/limits. To know what is your case you have to take a look at the Phobos code. Bye, bearophile
Dec 22 2013
prev sibling parent reply =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 12/22/2013 02:37 PM, John Carter wrote:

 This code compiles and runs OK if I remove the keyword "pure" or if I
 remove the ".retro"
Third option: It compiles and runs OK if you upgrade your compiler. ;) Works with DMD64 D Compiler v2.065-devel-41ebb59. Ali
Dec 22 2013
parent John Carter <john.carter taitradio.com> writes:
Yup.

That's the answer.

Upgraded to 2.064 and good things happened.

Diff shows flocks of diffs in std.range

Thanks.


On Mon, Dec 23, 2013 at 1:21 PM, Ali =C3=87ehreli <acehreli yahoo.com> wrot=
e:

 On 12/22/2013 02:37 PM, John Carter wrote:

 This code compiles and runs OK if I remove the keyword "pure" or if I
 remove the ".retro"
Third option: It compiles and runs OK if you upgrade your compiler. ;) Works with DMD64 D Compiler v2.065-devel-41ebb59. Ali
--=20 John Carter Phone : (64)(3) 358 6639 Tait Electronics PO Box 1645 Christchurch New Zealand --=20 ------------------------------ This email, including any attachments, is only for the intended recipient.= =20 It is subject to copyright, is confidential and may be the subject of legal= =20 or other privilege, none of which is waived or lost by reason of this=20 transmission. If you are not an intended recipient, you may not use, disseminate,=20 distribute or reproduce such email, any attachments, or any part thereof.= =20 If you have received a message in error, please notify the sender=20 immediately and erase all copies of the message and any attachments. Unfortunately, we cannot warrant that the email has not been altered or=20 corrupted during transmission nor can we guarantee that any email or any=20 attachments are free from computer viruses or other conditions which may=20 damage or interfere with recipient data, hardware or software. The=20 recipient relies upon its own procedures and assumes all risk of use and of= =20 opening any attachments. ------------------------------
Dec 22 2013