generality of Range

2009-10-04 Thread Darren Duncan

A question.

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.


I just wanted to confirm that that would work in the general case, where I might 
want to do nothing more than:


  my $a = $b .. $c;
  my $a = $b ^.. $c;
  my $a = $b ..^ $c;
  my $a = $b ^..^ $c;

... plus invoke methods of $a to extract the values $b,$c and indicators of 
whether $b or $c are included within the range or not (how you read the 
distinction between the presence or absence of either or both ^.


As long as I don't try to iterate the range or something, I would expect the 
above to work for any possible value of $b or $c; 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.


On a tangent, it would be nice if Range were parameterizable like Seq say; such 
as:

  has Range of Int $foo;

... and then $foo would only accept Range values whose endpoints are Int.

Now in order for what I ask to work, Range has to be lazy enough that it won't 
for example test that $b is before $c when constructing the Range object, and 
will only complain if necessary when you try to use it where that matters.


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?


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?


Thank you in advance.

-- Darren Duncan


r28589 - docs/Perl6/Spec

2009-10-04 Thread pugs-commits
Author: pmichaud
Date: 2009-10-04 16:26:35 +0200 (Sun, 04 Oct 2009)
New Revision: 28589

Modified:
   docs/Perl6/Spec/S08-capture.pod
Log:
[S08]:  Some notes where online discussions are at odds with the spec.


Modified: docs/Perl6/Spec/S08-capture.pod
===
--- docs/Perl6/Spec/S08-capture.pod 2009-10-04 10:28:18 UTC (rev 28588)
+++ docs/Perl6/Spec/S08-capture.pod 2009-10-04 14:26:35 UTC (rev 28589)
@@ -119,8 +119,14 @@
   say $a[1];
 
 In that case, you'll get C2, (3, 4) (or whatever is implemented in
-the .Str method of that specific Parcel). But, you should be able to:
+the .Str method of that specific Parcel). 
 
+[Update:  The above (and much of what follows below) doesn't conform 
+to the latest discussion on parcels; parcels flatten under item assignment. 
+See Lhttp://irclog.perlgeek.de/perl6/2009-09-23#i_1532822.]
+
+But, you should be able to:
+
   say $a[1;0];
 
 Which is going to return C2, which is almost the same as:
@@ -221,6 +227,9 @@
 The latter is provided as an alternative for situations where you want
 to preserve the code in 7-bits only.
 
+[Update: C@%a might not work out as a capture sigil -- 
+See Lhttp://irclog.perlgeek.de/perl6/2009-09-21#i_1523801.]
+
 =head1 Additions
 
 Please post errors and feedback to perl6-language.  If you are making



r28590 - docs/Perl6/Spec

2009-10-04 Thread pugs-commits
Author: pmichaud
Date: 2009-10-04 16:27:33 +0200 (Sun, 04 Oct 2009)
New Revision: 28590

Modified:
   docs/Perl6/Spec/S08-capture.pod
Log:
[S08]:  Update mime-type for .pod document.



Property changes on: docs/Perl6/Spec/S08-capture.pod
___
Added: svn:mime-type
   + text/plain; charset=UTF-8



r28591 - docs/Perl6/Spec

2009-10-04 Thread pugs-commits
Author: pmichaud
Date: 2009-10-04 16:28:27 +0200 (Sun, 04 Oct 2009)
New Revision: 28591

Modified:
   docs/Perl6/Spec/S08-capture.pod
Log:
[S08]:  Update svn:eol-style property.



Property changes on: docs/Perl6/Spec/S08-capture.pod
___
Added: svn:eol-style
   + native



Re: generality of Range

2009-10-04 Thread Michael Zedeler

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.



Re: generality of Range

2009-10-04 Thread yary
I'm confused between using ranges to generate a lazy list and using
them as criteria to match against.

These exclude continuous (non-countable) types-

...
  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).

Rationals and reals can't participate in ranges by the above, which in
a sense make sense. You can't ask for all rationals/reals between two
endpoints, or the next rational number bigger than 0. But it does
make sense to ask is $x between 0 and 1 exclusive?

There was a big discussion about this on the list recently but I don't
recall the resolutions.

And in Darren's example, could one declare a comparator and successor
operator for lists, and then get the example to produce ['Foo', 18],
['Foo', 19], ['Foo', 20], ['Foo', 21], ['Foo', 22], ['Foo', 23] ?

-y


Re: generality of Range

2009-10-04 Thread Minimiscience

On Oct 4, 2009, at 12:47 PM, yary wrote:

There was a big discussion about this on the list recently but I don't
recall the resolutions.


The resolution was r28344: http://dev.pugscode.org/changeset/28344.   
The short version is that ranges are now primarily used for testing  
inclusion in intervals; if you want a list of values in an interval,  
use ... instead.


-- Minimiscience


r28595 - docs/Perl6/Spec

2009-10-04 Thread pugs-commits
Author: moritz
Date: 2009-10-04 19:15:29 +0200 (Sun, 04 Oct 2009)
New Revision: 28595

Modified:
   docs/Perl6/Spec/S03-operators.pod
Log:
[S03] thinko

Modified: docs/Perl6/Spec/S03-operators.pod
===
--- docs/Perl6/Spec/S03-operators.pod   2009-10-04 17:15:19 UTC (rev 28594)
+++ docs/Perl6/Spec/S03-operators.pod   2009-10-04 17:15:29 UTC (rev 28595)
@@ -537,7 +537,7 @@
 
 Increment of a CBool (in a suitable container) turns it true.
 Decrement turns it false regardless of how many times it was
-previously incremented.  This is useful if your C%seen array is
+previously incremented.  This is useful if your C%seen hash is
 actually a CKeySet, in which case decrement actually deletes it
 from the CKeySet.
 



r28596 - docs/Perl6/Spec

2009-10-04 Thread pugs-commits
Author: moritz
Date: 2009-10-04 19:15:43 +0200 (Sun, 04 Oct 2009)
New Revision: 28596

Modified:
   docs/Perl6/Spec/S03-operators.pod
Log:
[S03] be more consequent in removing :by

Modified: docs/Perl6/Spec/S03-operators.pod
===
--- docs/Perl6/Spec/S03-operators.pod   2009-10-04 17:15:29 UTC (rev 28595)
+++ docs/Perl6/Spec/S03-operators.pod   2009-10-04 17:15:43 UTC (rev 28596)
@@ -678,7 +678,7 @@
 
 ^$limit
 
-Constructs a range of C0 ..^ $limit or locates a metaclass as a shortcut
+Constructs a range of C0 ..^ +$limit or locates a metaclass as a shortcut
 for C$limit.HOW.  See L/Range and RangeIterator semantics.
 
 =back
@@ -3109,7 +3109,7 @@
 
 Smart matching against a CRange object smartmatches the
 endpoints in the domain of the object being matched, so fractional
-numbers are Cnot truncated before comparison to integer ranges:
+numbers are Inot truncated before comparison to integer ranges:
 
 1.5 ~~ 1^..^2  # true, equivalent to 1  1.5  2
 2.1 ~~ 1..2# false, equivalent to 1 = 2.1 = 2
@@ -3141,10 +3141,6 @@
 
 for ^4 { say $_ } # 0, 1, 2, 3
 
-or with :by
-
-for ^4 :by(0.5) { say $_ } # 0, 0.5, 1.5, 2.0, 2.5, 3.0, 3.5
-
 If applied to a type name, it indicates the metaclass instance instead,
 so C^Moose is short for CHOW(Moose) or CMoose.HOW.  It still kinda
 means what is this thing's domain in an abstract sort of way.
@@ -3171,15 +3167,7 @@
 
 In other words, operators of numeric and other ordered types are
 generally overloaded to do something sensible on CRange objects.
-In particular, multiplicative operators not only multiply the endpoints
-but also the by of the CRange object:
 
-(1..11:by(2)) * 5   # same as 5..55:by(10)
-5,15,25,35,45,45,55
-
-Conjecture: non-linear functions might even produce non-uniform by values!
-Think of log scaling, for instance.
-
 =back
 
 =head1 Chained comparisons



r28597 - docs/Perl6/Spec/S32-setting-library

2009-10-04 Thread pugs-commits
Author: moritz
Date: 2009-10-04 19:15:53 +0200 (Sun, 04 Oct 2009)
New Revision: 28597

Modified:
   docs/Perl6/Spec/S32-setting-library/Numeric.pod
Log:
[S32/Numeric] major overhaul

* Most methods that were in Num are now Numeric
* sign() and the rounding methods are now in Real
* document (at least partially) Rat, Num and Int

Modified: docs/Perl6/Spec/S32-setting-library/Numeric.pod
===
--- docs/Perl6/Spec/S32-setting-library/Numeric.pod 2009-10-04 17:15:43 UTC 
(rev 28596)
+++ docs/Perl6/Spec/S32-setting-library/Numeric.pod 2009-10-04 17:15:53 UTC 
(rev 28597)
@@ -28,7 +28,7 @@
 repository under /docs/Perl6/Spec/S32-setting-library/Numeric.pod so edit it 
there in
 the SVN repository if you would like to make changes.
 
-This documents Bit, Int, Num, Rat, Complex, and Bool.
+This documents Bit, Int, Numeric, Rat, Complex, and Bool.
 
 XXX So where are Bit, Int, and Rat
 
@@ -52,13 +52,17 @@
 
 =back
 
-=head2 Num
+=head2 Numeric
 
-The following are all defined in the CNum role:
+CNumeric is a role for everything that's a scalar number. So CNum, CInt,
+CRat, CComplex and other numeric types do that role. However it is an
+abstract interface, so C$number.WHAT will never return CNumeric. Users who
+provide their own scalar numeric types are encouraged to implement the
+CNumeric role.
 
-BAPI document: LNum
+The following are all defined in the CNumeric role:
 
-CNum provides some constants in addition to the basic
+CNumeric provides some constants in addition to the basic
 mathematical functions.
 
 constant pi is export = 3.14159_26535_89793_23846_26433_83279_50288;
@@ -68,74 +72,43 @@
 
 =item succ
 
- our Num multi method succ ( Num $x: ) is export
- our Int multi method succ ( Int $x: ) is export
+ our Numeric multi method succ ( Numeric $x: ) is export
+ our Int multi method succ ( Int $x: ) is export
 
 Returns the successor of C$x. This method is used by C prefix:++  and
 C postfix:++  to increment the value in a container.
 
 =item pred
 
- our Num multi method pred ( Num $x: ) is export
- our Int multi method pred ( Int $x: ) is export
+ our Numeric multi method pred ( Numeric $x: ) is export
+ our Int multi method pred ( Int $x: ) is export
 
 Returns the predeccessor of C$x. This method is used by C prefix:-- 
 and C postfix:--  to decrement the value in a container.
 
 =item abs
 
- our Num multi method abs ( Num $x: ) is export
+ our Numeric multi method abs ( Numeric $x: ) is export
 
 Absolute Value.
 
-=item floor
-
- our Int multi method floor ( Num $x: ) is export
-
-Returns the highest integer not greater than C$x.
-
-=item ceiling
-
- our Int multi method ceiling ( Num $x: ) is export
-
-Returns the lowest integer not less than C$x.
-
-=item round
-
- our Int multi method round ( Num $x: ) is export
-
-Returns the nearest integer to C$x.  The algorithm is Cfloor($x + 0.5).
-(Other rounding algorithms will be given extended names beginning with 
round.)
-
-=item truncate
-
- our Int multi method truncate ( Num $x: ) is export
-
-Returns the closest integer to C$x whose absolute value is not greater
-than the absolute value of C$x.  (In other words, just chuck any
-fractional part.)  This is the default rounding function used by
-implicit integer conversions.
-
-You may also truncate using explicit integer casts, either CInt() for
-an arbitrarily large integers, or Cint() for native integers.
-
 =item exp
 
- our Num multi method exp ( Num $exponent: Num :$base = Num::e ) is export
+ our Numeric multi method exp ( Numeric $exponent: Numeric :$base = Num::e ) 
is export
 
 Performs similar to C$base ** $exponent. C$base defaults to the
 constant Ie.
 
 =item log
 
- our Num multi method log ( Num $x: Num $base = Num::e ) is export
+ our Numeric multi method log ( Numeric $x: Numeric $base = Num::e ) is export
 
 Logarithm of base C$base, default Natural. Calling with C$x == 0 is an
 error.
 
 =item log10
 
- our Num multi method log10 (Num $x:) is export
+ our Numeric multi method log10 (Numeric $x:) is export
 
 A base C10 logarithm, othewise identical to Clog.
 
@@ -148,34 +121,9 @@
 unary Crand function in Perl 6, so just multiply Crand by your
 desired multiplier.  For picking a random integer you probably want
 to use something like C(1..6).pick instead.
-
-=item sign
-
- our Int multi method sign ( Num $x: ) is export
-
-Returns 1 when C$x is greater than 0, -1 when it is less than 0, 0 when it
-is equal to 0, or undefined when the value passed is undefined.
-
-=item srand
-
- multi method srand ( Num $seed: )
- multi srand ( Num $seed = default_seed_algorithm())
-
-Seed the generator Crand uses. C$seed defaults to some combination
-of various platform dependent characteristics to yield a non-deterministic 
seed.
-Note that you get one Csrand() for free when you start a Perl program, so
-you Imust call Csrand() yourself if you wish to specify a deterministic 
seed
-(or if you wish to be 

Re: generality of Range

2009-10-04 Thread Jon Lang
yary wrote:
 I'm confused between using ranges to generate a lazy list and using
 them as criteria to match against.

Indeed.  It was my understanding that there was a recent change to
Ranges so that they now exist primarily to be used as matching
criteria.  If you wish to generate a list, the preferred approach
these days is the ... infix operator:

1 .. 100 # the range of values between 1 and 100, inclusive.
1, 2 ... 100 # a list of integers.

The ability to generate a lazy list using a Range object is now of
secondary importance, and should not be a required feature anymore.
In particular, :by was removed from Range.

-- 
Jonathan Dataweaver Lang


Re: r28597 - docs/Perl6/Spec/S32-setting-library

2009-10-04 Thread Jon Lang
How do pred and succ work when given Complex values?

More generally: if Complex does Numeric, then Numeric doesn't include
Ordered (or whatever it's called), because Complex doesn't do Ordered.
 As such, you can't used Numeric for any function that depends on the
value being Ordered.

On Sun, Oct 4, 2009 at 10:15 AM,  pugs-comm...@feather.perl6.nl wrote:
 @@ -255,7 +284,7 @@

  =item IStandard Trig Functions

 - Num multi method func ( Num  $x: TrigBase $base = $?TRIGBASE ) is export
 + Nuermic multi method func ( Nuermic  $x: TrigBase $base = $?TRIGBASE ) is 
 export

typos: s[Nuermic] = Numeric

  where Ifunc is one of:
  sin, cos, tan, asin, acos, atan, sec, cosec, cotan, asec, acosec,
 @@ -281,14 +310,58 @@

  =item atan2

 - our Num multi method atan2 ( Num $y: Num $x = 1 )
 - our Num multi atan2 ( Num $y, Num $x = 1 )
 + our Nuermic multi method atan2 ( Nuermic $y: Nuermic $x = 1 )
 + our Nuermic multi atan2 ( Nuermic $y, Nuermic $x = 1 )

More typos: s[Nuermic] = Numeric


-- 
Jonathan Dataweaver Lang


Re: r28597 - docs/Perl6/Spec/S32-setting-library

2009-10-04 Thread Moritz Lenz
Jon Lang wrote:
 How do pred and succ work when given Complex values?

By adding/substracting 1 from the real part, I'd say. Don't know if that
actually makes sense.

 More generally: if Complex does Numeric, then Numeric doesn't include
 Ordered (or whatever it's called), because Complex doesn't do Ordered.
  As such, you can't used Numeric for any function that depends on the
 value being Ordered.

Correct, that's what Real is for.

 On Sun, Oct 4, 2009 at 10:15 AM,  pugs-comm...@feather.perl6.nl wrote:
 @@ -255,7 +284,7 @@

  =item IStandard Trig Functions

 - Num multi method func ( Num  $x: TrigBase $base = $?TRIGBASE ) is export
 + Nuermic multi method func ( Nuermic  $x: TrigBase $base = $?TRIGBASE ) is 
 export
 
 typos: s[Nuermic] = Numeric

You do have a pugs commit bit, don't you?
If you find errors, feel free to correct them in the synopsis.

Cheers,
Moritz


Re: r28597 - docs/Perl6/Spec/S32-setting-library

2009-10-04 Thread Michael Zedeler

Moritz Lenz wrote:

Jon Lang wrote:
  

How do pred and succ work when given Complex values?


By adding/substracting 1 from the real part, I'd say. Don't know if that
actually makes sense.
  

It doesn't, because succ should always give the next, smallest possible
element given some ordering relation. Neither does it make sense for
real numbers. Same thing applies to pred.

It may be necessary to move methods in the Numeric class that require
ordering and countability to somewhere else.

You do have a pugs commit bit, don't you?
If you find errors, feel free to correct them in the synopsis.

I do. If anyone doesn't object, I'd be happy to move the methods down to
a subclass (or -role) - at least in the spec (not sure what to do with
the code as of now).

Regards,

Michael.




Re: r28597 - docs/Perl6/Spec/S32-setting-library

2009-10-04 Thread Moritz Lenz
Michael Zedeler wrote:
 Moritz Lenz wrote:
 Jon Lang wrote:
   
 How do pred and succ work when given Complex values?
 
 By adding/substracting 1 from the real part, I'd say. Don't know if that
 actually makes sense.
   
 It doesn't, because succ should always give the next, smallest possible
 element given some ordering relation. 

Where's that definition from? For me .succ was just the backend for
prefix and postfix ++, which desugar to $thing += 1 (except for strings,
where it's magic).

 Neither does it make sense for
 real numbers. Same thing applies to pred.
 
 It may be necessary to move methods in the Numeric class that require
 ordering and countability to somewhere else.

Well, Real implies ordering (at least to me ;-), I don't think we have a
class or role for countability.

 You do have a pugs commit bit, don't you?
 If you find errors, feel free to correct them in the synopsis.
 I do. If anyone doesn't object, I'd be happy to move the methods down to
 a subclass (or -role) - at least in the spec (not sure what to do with
 the code as of now).

The code and tests are later adapted at whim, or so ;-)

Cheers,
Moritz


Re: r28597 - docs/Perl6/Spec/S32-setting-library

2009-10-04 Thread Jon Lang
Moritz Lenz wrote:
 Jon Lang wrote:
 typos: s[Nuermic] = Numeric

 You do have a pugs commit bit, don't you?

A what?  AFAICT, I don't have any way of editing the Synopses; all I
can do is to comment on what I find.

-- 
Jonathan Dataweaver Lang


Re: r28597 - docs/Perl6/Spec/S32-setting-library

2009-10-04 Thread Moritz Lenz
Jon Lang wrote:
 Moritz Lenz wrote:
 Jon Lang wrote:
 typos: s[Nuermic] = Numeric

 You do have a pugs commit bit, don't you?
 
 A what?  AFAICT, I don't have any way of editing the Synopses;

You have now (sorry for assuming earlier that you had). A username and
password should be on the way to your email address.

svn co http://svn.pugscode.org/pugs/docs/Perl6/Spec/
cd Spec
# hack away
svn ci

Cheers,
Moritz


Re: generality of Range

2009-10-04 Thread Darren Duncan

Minimiscience wrote:
 On Oct 4, 2009, at 12:47 PM, yary wrote:
 There was a big discussion about this on the list recently but I don't
 recall the resolutions.

 The resolution was r28344: http://dev.pugscode.org/changeset/28344.
 The short version is that ranges are now primarily used for testing
 inclusion in intervals; if you want a list of values in an interval, use
 ... instead.

Jon Lang wrote:

yary wrote:

I'm confused between using ranges to generate a lazy list and using
them as criteria to match against.


Indeed.  It was my understanding that there was a recent change to
Ranges so that they now exist primarily to be used as matching
criteria.  If you wish to generate a list, the preferred approach
these days is the ... infix operator:

1 .. 100 # the range of values between 1 and 100, inclusive.
1, 2 ... 100 # a list of integers.

The ability to generate a lazy list using a Range object is now of
secondary importance, and should not be a required feature anymore.
In particular, :by was removed from Range.


What Minimiscience and Jon Lang stated has been my understanding as well, 
especially since the r28344 resolution.  A Range is primarily used as an 
interval, either to simply represent a span of values of some orderable type 
(which could be any type at all in the general case), or to test whether a given 
other value is orderable between the interval's endpoints.  And this is all that 
I want to use it for, in a general context that is orthogonal to type.  So 
supporting .succ() or .prec() in the general case isn't needed.


Now, it turns out that Synopsis 3 was the place with some of the answers I 
sought:

  http://perlcabal.org/syn/S03.html#Range_and_RangeIterator_semantics

For example, .min and .max are used to read the declared endpoint values of a 
Range.

However, I still don't see how one would retrieve the distinction between say 
1..10 and 1^..^10.  I suggest that an extra 2 methods such as 
.min_is_outside and .max_is_outside (each returns a Bool) could fit the bill, 
and in fact since I have Pugs write access I think I'll go make that addition 
myself in the above S03 section.


Now I was going to ask how to represent endpoints that are whatever if 
whatever is orthogonal to type, but then I realized the answer is simply to 
use a Whatever object, which is one of the 4 Undefined types mentioned in S02.


For example, if someone said:

  my $r = $foo..*;
  my $min = $r.min;  # $foo's value
  my $max = $r.max;  # Whatever.new()

Now maybe it would be reasonable for .max to return +Inf if $foo was an Int, but 
I would expect that for any type where $foo doesn't have a concept of 
positive-infinity, a * would just be Whatever.new() by default.


On a tangent, I was thinking that if Range really is meant to represent an 
interval in its general case, which is orthogonal to type, then Range should be 
as generic as Set or other element-type-orthogonal containers, and also support 
not only the Iterable role but the Associative role, like Set does.


You see, conceptually an interval is a set of values, where the member values 
are defined not in terms of an enumeration (as with Set, Bag, PairValSet, etc) 
but rather in terms of what values exist from the value domain of the interval's 
endpoints that are ordered between those endpoints.


And so, conceptually $a ~~ 1..10 is a set membership test, and I think it 
would be reasonable to be able to use the more semantics-specific operators that 
one uses on Set or Hash or whatever to test membership, on a Range; for example:


  $val ∈ Set.new( 42, 27, 4, 36 )
  $val ∈ 20^..40

Similarly, there should be operators or methods for testing if 2 Range overlap, 
or if one is contained in the other, or to derive 1 from 2 using intersection or 
union etc.


These are operations common with mathematical intervals (those over Real say), 
but they are orthogonal to type.


It is more just using + or - etc which are specific to the maths, or rather they 
aren't orthogonal to type but just are for types that support +/-/etc.


On a tangent, if there is any thought to make S32/Temporal have specific support 
for Instant/DateTime interval objects (which are *not* the same meaning as 
durations), I would say that a suitably generic Range should fit the bill by 
itself, as far as declaring the objects goes.  For example, Range of Instant 
or Range of DateTime should be a sufficient type declaration for a date range 
type, rather than needing to come up with something special, unless that special 
thing is just an alias for the above.


So those are some thoughts.  I probably have more.

-- Darren Duncan


Re: generality of Range

2009-10-04 Thread Moritz Lenz


Darren Duncan wrote:
 However, I still don't see how one would retrieve the distinction between say 
 1..10 and 1^..^10.  I suggest that an extra 2 methods such as 
 .min_is_outside and .max_is_outside (each returns a Bool) could fit the bill, 
 and in fact since I have Pugs write access I think I'll go make that addition 
 myself in the above S03 section.

Great.
Rakudo currently uses from_exclusive and to_exclusive, but since ranges
now always have $.from  $.to, I see no reason to stick with from in
favor of min, and to in favor of max.

 Now I was going to ask how to represent endpoints that are whatever if 
 whatever is orthogonal to type, but then I realized the answer is simply to 
 use a Whatever object, which is one of the 4 Undefined types mentioned in 
 S02.
 
 For example, if someone said:
 
my $r = $foo..*;
my $min = $r.min;  # $foo's value
my $max = $r.max;  # Whatever.new()
 
 Now maybe it would be reasonable for .max to return +Inf if $foo was an Int, 
 but 
 I would expect that for any type where $foo doesn't have a concept of 
 positive-infinity, a * would just be Whatever.new() by default.

I'd just say that Range.min and Range.max return exactly what you put
into it - (1..*).max should return * (which is a Whatever object),
(1..Inf).max should return Inf.

Cheers,
Moritz


r28612 - docs/Perl6/Spec

2009-10-04 Thread pugs-commits
Author: Darren_Duncan
Date: 2009-10-04 23:36:46 +0200 (Sun, 04 Oct 2009)
New Revision: 28612

Modified:
   docs/Perl6/Spec/S03-operators.pod
Log:
Spec S03 : add Range methods .excl_min, .excl_max

Modified: docs/Perl6/Spec/S03-operators.pod
===
--- docs/Perl6/Spec/S03-operators.pod   2009-10-04 21:21:30 UTC (rev 28611)
+++ docs/Perl6/Spec/S03-operators.pod   2009-10-04 21:36:46 UTC (rev 28612)
@@ -3084,6 +3084,17 @@
 values as a two-element list representing the interval.  Ranges are
 not autoreversing: C2..1 is always a null range.
 
+Range objects support the C.excl_min and C.excl_max methods
+representing the exclusion (has C^) or inclusion (no C^) of each
+endpoint in the Range.
+
+Range  | .min | .max | .excl_min   | .excl_max
+---+--+--+-+
+1..10  | 1| 10   | Bool::False | Bool::False
+2.7..^9.3  | 2.7  | 9.3  | Bool::False | Bool::True
+'a'^..'z'  | 'a'  | 'z'  | Bool::True  | Bool::False
+1^..^10| 1| 10   | Bool::True  | Bool::True
+
 If used in a list context, a CRange object returns an iterator that
 produces a series of values starting at the min and ending at the max.
 Either endpoint may be excluded using C^.  Hence C1..2 produces



Re: generality of Range

2009-10-04 Thread Darren Duncan

Moritz Lenz wrote:

Darren Duncan wrote:
However, I still don't see how one would retrieve the distinction between say 
1..10 and 1^..^10.  I suggest that an extra 2 methods such as 
.min_is_outside and .max_is_outside (each returns a Bool) could fit the bill, 
and in fact since I have Pugs write access I think I'll go make that addition 
myself in the above S03 section.


Great.
Rakudo currently uses from_exclusive and to_exclusive, but since ranges
now always have $.from  $.to, I see no reason to stick with from in
favor of min, and to in favor of max.


As seen in r28612, I went and made my change, but I decided to use shorter and 
probably better-descriptive names .min_excl and .max_excl, since both in math 
parlance as well as the existing S03 docs I was adding to, the base terms 
include and exclude were already in use.


Now I was going to ask how to represent endpoints that are whatever if 
whatever is orthogonal to type, but then I realized the answer is simply to 
use a Whatever object, which is one of the 4 Undefined types mentioned in S02.


For example, if someone said:

   my $r = $foo..*;
   my $min = $r.min;  # $foo's value
   my $max = $r.max;  # Whatever.new()

Now maybe it would be reasonable for .max to return +Inf if $foo was an Int, but 
I would expect that for any type where $foo doesn't have a concept of 
positive-infinity, a * would just be Whatever.new() by default.


I'd just say that Range.min and Range.max return exactly what you put
into it - (1..*).max should return * (which is a Whatever object),
(1..Inf).max should return Inf.


That sounds like exactly what I would prefer to happen.

Now, another tangent that I was going to raise ideas order-comparison-sensitive 
operations in general.


While it makes perfect sense for some type definitions to have cmp et al 
built-in, meaning that all order-comparison-sensitive operations such as cmp 
and sort and before and minmax and Range/interval value membership just 
work for them without extra help, I believe that it should be possible to apply 
a cmp at the place where any order-comparison-sensitive operations are *used*, 
not just in the type definitions of their operands.


For example, we already have:

  map { $^a mycmp $^b } @values  # spelling ?

But I believe one should be able to do that with minmax or Range uses or 
before or what-have you in a generic sense as well; for example:


  $a ∈ $b..$c ordered using { $^a mycmp $^b }  # ordered ... applies to ∈
  minmax @values ordered using { $^a mycmp $^b }

Now mind you, its possible that support for what I'm saying already exists with 
another syntax, perhaps using :trait syntax, but I don't recall.


But this is important, especially since often a type may have multiple innate 
conceptions of order, and you are best to pick one at time of use; for example, 
what collation to use for sorting text, you may not want to encode into the Str 
objects but just declare at the time of sorting/etc.


And it is important because it what lets you potentially order values of any 
types at all.


-- Darren Duncan