pure vs std.range.retro
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 pureness 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. --
Re: pure vs std.range.retro
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
Re: pure vs std.range.retro
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
Re: pure vs std.range.retro
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 Çehreli acehr...@yahoo.com wrote: 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 -- 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. --