Hi Darren.

Darren Duncan wrote:
In a project of mine I'm looking to use Perl 6 Range values to represent continuous interval values in the most generic manner possible, meaning that the endpoint values could literally be of any type at all. [...] for a realistic example:

  my $a = ['Foo', 17] ^.. ['Foo', 23];

... I would expect $a to be a Range and to be able to get those arrayrefs out of it. [...]

Bottom line, is my example line with the "['Foo',17]" valid Perl 6 or not, and if not then what could be done about it?
The short version is that your example shouldn't be valid Perl 6, because both ordering and successor functions are missing.

Look in synopsis 02 and 03 for documentation, but note that this particular corner of Perl 6 IMHO still is in flux.

My opinion is that for any domain (integers, real numbers, strings, complex numbers, two-element arrays consisting of a string and a number (your example) and anything else you can come up with), you have two requirements that must be met in order to be able to create a well defined Range:

  1. There must be a compare operator that can decide which of  two
     objects from the given domain is the greatest (for strings, ge and
     for numbers >). Lets call it >.
  2. There must be a successor function, so that given an object from
     the given domain, say a, successor(a) returns one and only one
     value from the same domain.
  3. Given b = successor(a), there is no c so that b > c > a (using the
     same operator as above).

And finally, if there are multiple, competing variations for the same domain, I say that they should be left out of Perl 6.
Also, in what Synopsis is it documented what the methods are to extract the endpoints et al from a Range object. Or what are they called?
Here is some meta-help: if you ever have a Perl 6 object and need to know its methods and attributes, use the introspection API. There is a description here:

http://rakudo.org/node/51

Regards,

Michael.

Reply via email to