Re: Playing with ranges and ufcs

2013-02-28 Thread Andrea Fontana
On Wednesday, 27 February 2013 at 23:43:49 UTC, bearophile wrote: void main() { auto a = [0,1,2,3,4,5,6,7,8,9][5 .. 2]; } I tried it too, hoping for something like [5,4,3] or at least [4,3,2] (== [0,1,2,3,4,5,6,7,8,9][2..5].reverse)

Re: Playing with ranges and ufcs

2013-02-27 Thread bearophile
Jonathan M Davis: Because then it more closely matches how arrays work. The only part that doesn't is that it's fully tied to -release rather than -noboundschecked. I see, thank you. Honestly, I think that that's a complete pipe dream anyway, I will keep dreaming for some more decades. I

Re: Playing with ranges and ufcs

2013-02-27 Thread Jonathan M Davis
On Thursday, February 28, 2013 00:35:08 bearophile wrote: > Jonathan M Davis: > > What it should be doing is using version(assert) to throw a > > RangeError if the > > arguments are invalid, but the addition of version(assert) is > > quite recent > > (previously, the best that could have been done

Re: Playing with ranges and ufcs

2013-02-27 Thread Jonathan M Davis
On Thursday, February 28, 2013 00:46:56 bearophile wrote: > > To do the same with user-defined structures time ago I have > > suggested this, that is currently closed waiting for a better > > > solution: > What I meant to say is that if the assert(i <= j) is inside the > pre-condition then there's

Re: Playing with ranges and ufcs

2013-02-27 Thread bearophile
To do the same with user-defined structures time ago I have suggested this, that is currently closed waiting for a better solution: What I meant to say is that if the assert(i <= j) is inside the pre-condition then there's a hope to run it at compile time introducing some new trick inside the

Re: Playing with ranges and ufcs

2013-02-27 Thread bearophile
auto opSlice(size_t i, size_t j) in { assert(i <= j, "some message here"); } body { auto retval = this.save; retval._index += i; return takeExactly(retval, j - i); } This is the bug opened by Andrea Fontana for this thread: http://d.puremagic.com/issues/show_bug.cgi?id=9612 At

Re: Playing with ranges and ufcs

2013-02-27 Thread bearophile
Jonathan M Davis: What it should be doing is using version(assert) to throw a RangeError if the arguments are invalid, but the addition of version(assert) is quite recent (previously, the best that could have been done was to assert). Do you mean something like this? auto opSlice(size_t i,

Re: Playing with ranges and ufcs

2013-02-27 Thread bearophile
Andrea Fontana: Done! I was about to file it myself, so I have added a bit more meat to your bug report. Bye, bearophile

Re: Playing with ranges and ufcs

2013-02-27 Thread Andrea Fontana
On Wednesday, 27 February 2013 at 22:48:06 UTC, bearophile wrote: Andrea Fontana: writeln(iota(10).cycle()[5..2].take(4)); print: [5, 6, 7, 8] Shouldn't [5..2] slice throw a compile/runtime error? Please file it in bugzilla. The opSlice of cycle() lacks those pre-conditions or tests, and

Re: Playing with ranges and ufcs

2013-02-27 Thread Jonathan M Davis
On Wednesday, February 27, 2013 23:48:05 bearophile wrote: > Andrea Fontana: > > writeln(iota(10).cycle()[5..2].take(4)); > > > > print: > > > > [5, 6, 7, 8] > > > > > > Shouldn't [5..2] slice throw a compile/runtime error? > > Please file it in bugzilla. > > The opSlice of cycle() lacks thos

Re: Playing with ranges and ufcs

2013-02-27 Thread bearophile
Andrea Fontana: writeln(iota(10).cycle()[5..2].take(4)); print: [5, 6, 7, 8] Shouldn't [5..2] slice throw a compile/runtime error? Please file it in bugzilla. The opSlice of cycle() lacks those pre-conditions or tests, and there are not enough unittests in Phobos to catch this simple bug

Playing with ranges and ufcs

2013-02-27 Thread Andrea Fontana
This command: writeln(iota(10).cycle()[5..2].take(4)); print: [5, 6, 7, 8] Shouldn't [5..2] slice throw a compile/runtime error?