Re: Palindromes

2015-12-03 Thread Ali Çehreli via Digitalmars-d-learn
On 12/03/2015 04:23 PM, Jim Barnett wrote: > The `import` statement inside the `for`-loop kind of smells to me. In addition to what others have explained, local imports are necessary for template mixins: http://ddili.org/ders/d.en/mixin.html#ix_mixin.import,%20local Quoting: module a; im

Re: Palindromes

2015-12-03 Thread Jim Barnett via Digitalmars-d-learn
On Friday, 4 December 2015 at 03:33:55 UTC, Meta wrote: I have never seen a language that encourages the user to specify dependencies inside a loop. I am hoping I misunderstood something here. Sorry, I thought you were referring more generally to nested imports. No, imports in a while loop ar

Re: Palindromes

2015-12-03 Thread Meta via Digitalmars-d-learn
On Friday, 4 December 2015 at 01:10:41 UTC, Jim Barnett wrote: Really? If it leads to "hard to detect errors", I have a hard time believing that can be "idiomatic D". It's used throughout the standard library, granted I don't think there's any occurrences of importing inside a while loop. The

Re: Palindromes

2015-12-03 Thread Brad Anderson via Digitalmars-d-learn
On Friday, 4 December 2015 at 00:50:17 UTC, Meta wrote: On Friday, 4 December 2015 at 00:26:23 UTC, Jim Barnett wrote: On Friday, 4 December 2015 at 00:23:45 UTC, Jim Barnett wrote: The `import` statement inside the `for`-loop kind of smells to me. Sorry, inside the `while` loop In D it's

Re: Palindromes

2015-12-03 Thread Jim Barnett via Digitalmars-d-learn
On Friday, 4 December 2015 at 00:50:17 UTC, Meta wrote: On Friday, 4 December 2015 at 00:26:23 UTC, Jim Barnett wrote: On Friday, 4 December 2015 at 00:23:45 UTC, Jim Barnett wrote: The `import` statement inside the `for`-loop kind of smells to me. Sorry, inside the `while` loop In D it's

Re: Palindromes

2015-12-03 Thread Meta via Digitalmars-d-learn
On Friday, 4 December 2015 at 00:26:23 UTC, Jim Barnett wrote: On Friday, 4 December 2015 at 00:23:45 UTC, Jim Barnett wrote: The `import` statement inside the `for`-loop kind of smells to me. Sorry, inside the `while` loop In D it's considered idiomatic, but it can also cause some very h

Re: Palindromes

2015-12-03 Thread Jim Barnett via Digitalmars-d-learn
On Friday, 4 December 2015 at 00:23:45 UTC, Jim Barnett wrote: The `import` statement inside the `for`-loop kind of smells to me. Sorry, inside the `while` loop

Re: Palindromes

2015-12-03 Thread Jim Barnett via Digitalmars-d-learn
On Thursday, 3 December 2015 at 23:42:31 UTC, Nordlöw wrote: On Thursday, 3 December 2015 at 21:40:05 UTC, Jim Barnett wrote: Thanks for reading. My version slightly adjusted version: /** Returns: If range is a palindrome larger than $(D minLength). See also: http://forum.dlang.org/thr

Re: Palindromes

2015-12-03 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 3 December 2015 at 21:40:05 UTC, Jim Barnett wrote: Thanks for reading. My version slightly adjusted version: /** Returns: If range is a palindrome larger than $(D minLength). See also: http://forum.dlang.org/thread/dlfeiszyweafpjioc...@forum.dlang.org#post-vpzuaqxvtdpzpeuor

Re: Palindromes

2015-12-03 Thread Jim Barnett via Digitalmars-d-learn
On Thursday, 3 December 2015 at 22:14:02 UTC, Justin Whear wrote: I don't think you want reverse because it works in-place; you'd need to make a copy to compare against. std.range.retro is probably what you're looking for: bool isPalindrome(R)(R range) if (isBidirectionalRange!R) { re

Re: Palindromes

2015-12-03 Thread Justin Whear via Digitalmars-d-learn
s a shorter expression to detect > palindromes if efficiency isn't the primary concern. So I am interested > in seeing implementations of `isPalindrome` that utilize > `std.algorithm.mutation.reverse`, or anyone who cares to enlighten me > why that might be a misguided thing to wa

Palindromes

2015-12-03 Thread Jim Barnett via Digitalmars-d-learn
urn true; } I recognize it's more efficient in terms of CPU time and memory than my C++ solution, but I suspect there is a shorter expression to detect palindromes if efficiency isn't the primary concern. So I am interested in seeing implementations of `isP