[Submission] D Slices

Ali Çehreli acehreli at yahoo.com
Tue May 31 13:22:27 PDT 2011


On 05/31/2011 09:09 AM, KennyTM~ wrote:

 > BTW, Ruby has both of them
 >
 >  >> a = [0,1,2,3,4,5,6]
 > => [0, 1, 2, 3, 4, 5, 6]
 >  >> a[3..5]
 > => [3, 4, 5]
 >  >> a[3...5]
 > => [3, 4]

Isn't that too subtle? I wonder whether that's a common problem in Ruby 
programming.

That reminds me of uniform(), Phobos's experiment in open/closed ending: :)

import std.random;

void main()
{
     // Also available: "()", "[)" (the default) and "(]"
     auto result = uniform!"[]"(0, 5);
     assert((result >= 0) && (result <= 5));
}

Ali



More information about the Digitalmars-d mailing list