Intervals in Gosu

Tuesday, November 9, 2010
Gosu has an interesting syntax for open and closed intervals:

   1..10   // Closed interval, i.e. the values 1-10 inclusive.
   1|..|10 // Open interval, the values 2-9

Having an easy syntax for open and closed intervals solves a number of problems I've been having: Sometimes you want intervals to be closed, other times half-open. For example, Python slice objects are half-open, and would be much less useful if they were fully open or fully closed. The interval notation would make it easy to do Python-style slices:

  let s = "Hello, world!";
  Console.out.printLn(s[0..|5]); // Prints "Hello"

0 comments:

Post a Comment