December 04, 2015 Re: Palindromes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Meta | 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 are not encouraged; imports in a struct or a template are.
That's interesting food for thought. At this point, I am just trying trying to transliterate my C++ and Ruby solutions for project Euler problems to D, and trying to get a better grasp on the D type system. Compile-time optimization isn't of much interest to me right now, but I am glad you pointed out that is something else to consider.
|
December 03, 2015 Re: Palindromes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jim Barnett | 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; import std.string; // ← wrong place mixin template A(T) { string a() { T[] array; // ... return format("%(%s, %)", array); } } "if std.string is not imported at the actual mixin site, then the compiler would not be able to find the definition of format() at that point" module a; mixin template A(T) { string a() { import std.string; // ← right place T[] array; // ... return format("%(%s, %)", array); } } Ali |
Copyright © 1999-2021 by the D Language Foundation