HaloO Everybody,

here's a an idea from me about makeing range object a bit like
junctions. That is a range object has a $.min and $.max and the
following comparison behaviour:

str  num

lt   <   strictly inside  ---------+
gt   >   strictly outside  ------+ |
eq   ==  exactly on boundary --+ | |
                               | | | negation
ne   !=  not on boundary     --+ | |
le   <=  inside or on boundary --+ |
ge   >=  outside or on boundary ---+

# strictly inside
($a <  3..6) === (3 <  $a <  6) === (3 <  $a && $a <  6)

#strictly outside
($a >  3..6) === (3 >  $a >  6) === (3 >  $a || $a >  6)

# inside or boundary
($a <= 3..6) === (3 <= $a <= 6) === (3 <= $a && $a <= 6)

# outside or boundary
($a >= 3..6) === (3 >= $a >= 6) === (3 >= $a || $a >= 6)

Please note what light the comaprisons sheds on chained comparison
in general!

The driving idea is to make the .. range not a list constructing
operator but a real uncountably infinite set of reals bounded by
the two nums. The measure of the interval always beeing the difference.

 +(3..7) == 7 - 3 == 4

Such a range might be interated of course. But only if the stepping
is given. Well, a range might be subdivided into subranges. But I'm
unsure what the default number of sections should be---10 perhaps?

   (3..7) == (3..4..5..6..7) # array/list of subranges
              [0][1][2][3]

   (3..7)[2] == 5..6

   (3..7).split(10) ==   # or perhaps (3..7)/10 returning a list
   (3.0..3.4..3.8..4.2..4.6..5.0..5.4..5.8..6.2..6.6..7.0)
    [0]  [1]  [2]  [3]  [4]  [5]  [6]  [7]  [8]  [9]
    [-10][-9] [-8] [-7] [-6] [-5] [-4] [-3] [-2] [-1]

   # step = (7-3)/10 = 0.4

Driving it even further we get closure bounded ranges. Here is
a circle with radius 5:

  my Point $p = ( x => 2, y => 3);

  $circle = $p..{ (.x - self.min.x)**2
                 +(.y - self.min.y)**2 <= 5**2 };

The self is the range and .x and .y are applied to $_
when it comes to inside checking as in

  if $some_point < $circle { ... }

I'm not sure how usefull this numerics inspired idea fits into Perl6.


The former meaning of .. constructing a list could be implemented
with ,, and ;; as follows.

 + ^5 == +(0,1,2,3,4) == 5

 +(3,,7) == +(3,4,5,6,7) == 5

The mnemonic is that the ,, is just filling the left out parts
by iterating, indicated by parens here:

 +(1,,5,5,,8) == +(1,(2,3,4),5,5,(6,7),8) == 7

Note the duplicated 5 which was there before expansion.
Left out ends default to 0 naturally:

  (,,7)   == ( 0,, 7) == ( 0, 1, 2, 3, 4, 5, 6, 7)
    (7,,) == ( 7,, 0) == ( 7, 6, 5, 4, 3, 2, 1, 0)
 (,,-7)   == ( 0,,-7) == ( 0,-1,-2,-3,-4,-5,-6,-7)
   (-7,,) == (-7,, 0) == (-7,-6,-5,-4,-3,-2,-1, 0)

But counting over zero doesn't duplicate the 0 of course:

(-3,,3) == (-3,-2,-1, 0, 1, 2, 3)

Here are some ideas how to extend to semicolon list:

  +(1,2 ;; 3,4) == +(1,2,3 ; 2,3,4) == 2 * 3 == 6

  +(1;1 ;; 3;3) == +( (1;1),(1;2),(1;3),
                      (2;1),(2;2),(2;3),
                      (3;1),(3;2),(3;3) ) == 9

Combining , and .. gives

  +(1..5,5..8) == 2  # List of Range

not a list from 1 to 8 or so.

Comments?
--

Reply via email to