www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - why does this error out?

reply steven kladitis <steven_kladitis yahoo.com> writes:
void main() {
     import std.stdio, std.algorithm, std.range, std.conv;

     enum digSum = (int n) => n.text.map!(d => d - '0').sum;
//    enum harshads = iota(1, int.max).filter!(n => n % digSum(n) 
== 0);
     enum harshads = iota(1, 256).filter!(n => n % digSum(n) == 0);
     harshads.take(20).writeln;
     harshads.filter!(h => h > 1000).front.writeln;
}

// this compiles but always prints 1 number and gets 
object.Error (0): Access Violation
Nov 09 2015
parent reply Cauterite <cauterite gmail.com> writes:
Here's the output I get (DMD v2.068.2):

[1, 3, 10, 12, 21, 30, 100, 102, 111, 120, 201, 210]
core.exception.AssertError std\range\package.d(4603): Assertion 
failure
Nov 09 2015
parent reply lobo <swamplobo gmail.com> writes:
On Tuesday, 10 November 2015 at 04:34:22 UTC, Cauterite wrote:
 Here's the output I get (DMD v2.068.2):

 [1, 3, 10, 12, 21, 30, 100, 102, 111, 120, 201, 210]
 core.exception.AssertError std\range\package.d(4603): Assertion 
 failure
iota.front() is complaining the range is empty from this line. harshads.filter!(h => h > 1000).front.writeln; your hardas has no values > 1000 so the filter is empty. hardwas was seeded with iota(1,256), so the maximum value will be 252. bye, lobo
Nov 09 2015
parent reply steven kladitis <steven_kladitis yahoo.com> writes:
On Tuesday, 10 November 2015 at 05:14:29 UTC, lobo wrote:
 On Tuesday, 10 November 2015 at 04:34:22 UTC, Cauterite wrote:
 Here's the output I get (DMD v2.068.2):

 [1, 3, 10, 12, 21, 30, 100, 102, 111, 120, 201, 210]
 core.exception.AssertError std\range\package.d(4603): 
 Assertion failure
iota.front() is complaining the range is empty from this line. harshads.filter!(h => h > 1000).front.writeln; your hardas has no values > 1000 so the filter is empty. hardwas was seeded with iota(1,256), so the maximum value will be 252. bye, lobo
with dmd 2.069 I always get --> [1 and then the error no matter what I canhe that line to.
Nov 10 2015
parent reply lobo <swamplobo gmail.com> writes:
On Tuesday, 10 November 2015 at 14:25:19 UTC, steven kladitis 
wrote:
 On Tuesday, 10 November 2015 at 05:14:29 UTC, lobo wrote:
 On Tuesday, 10 November 2015 at 04:34:22 UTC, Cauterite wrote:
 Here's the output I get (DMD v2.068.2):

 [1, 3, 10, 12, 21, 30, 100, 102, 111, 120, 201, 210]
 core.exception.AssertError std\range\package.d(4603): 
 Assertion failure
iota.front() is complaining the range is empty from this line. harshads.filter!(h => h > 1000).front.writeln; your hardas has no values > 1000 so the filter is empty. hardwas was seeded with iota(1,256), so the maximum value will be 252. bye, lobo
with dmd 2.069 I always get --> [1 and then the error no matter what I canhe that line to.
Hmm, that's different to what I get. On linux 64 bit with dmd 2.069 I get this: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 18, 20, 21, 24, 27, 30, 36, 40, 42] core.exception.AssertError std/range/package.d(4691): Assertion failure Note the assertion is same as before; hardas has no values > 252 so filter!(h => h < 1000) results in an empty range. bye, lobo
Nov 11 2015
parent lobo <swamplobo gmail.com> writes:
On Thursday, 12 November 2015 at 02:36:23 UTC, lobo wrote:
 On Tuesday, 10 November 2015 at 14:25:19 UTC, steven kladitis 
 wrote:
 On Tuesday, 10 November 2015 at 05:14:29 UTC, lobo wrote:
 [...]
with dmd 2.069 I always get --> [1 and then the error no matter what I canhe that line to.
Hmm, that's different to what I get. On linux 64 bit with dmd 2.069 I get this: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 18, 20, 21, 24, 27, 30, 36, 40, 42] core.exception.AssertError std/range/package.d(4691): Assertion failure Note the assertion is same as before; hardas has no values > 252 so filter!(h => h < 1000) results in an empty range. bye, lobo
that should be filter!(h => h > 1000)
Nov 11 2015