Re: .map/.reduce with larger arity

2009-03-09 Thread Martin D Kealey
On Mon, 9 Mar 2009, Larry Wall wrote:

> the only difference between C and C is that you can only use
> C at the start of a statement.  But we're more liberal about where
> statements are expected in Perl 6, so you can say things like:
>
> my @results = do for @list -> $x {...};
> my @results = (for @list -> $x {...});
>
> and either of those is equivalent to:
>
> my @results = map -> $x {...}, @list;
>
> I also Officially Don't Care if you use map in a void context. :)

(Good.)

 Maybe we should just treat "map" as a synonym for "for". 


I'd like to be able to use grep, map, etc in a currying fashion. Can I do:

my &square_list := -> $x { $x * $x }.map();

And if so, what is the signature of &square_list ?

Maybe that's why there's a difference between "for" and "map"

@list = @array.map(&code);

&iterator = &code.for($signature);
@list = iterator(@list);

But I suspect they should logically be the other way around:

&iterator = &code.map($signature);
@list = iterator(@list);

@list = @array.for(&code);

-Martin


Re: .map/.reduce with larger arity

2009-03-09 Thread Larry Wall
On Mon, Mar 09, 2009 at 11:38:29AM -0500, Patrick R. Michaud wrote:
: On Sun, Mar 08, 2009 at 09:31:19PM -0700, Larry Wall wrote:
: > On Sun, Mar 08, 2009 at 09:36:17PM +0100, Moritz Lenz wrote:
: > : But both pugs and rakudo respect the arity of the code ref passed to it,
: > : so that (1..6).map({$^a + $^b + $^c}) returns the list (6, 15), which is
: > : very nice and very DWIM'my.
: > : 
: > : But it opens the question what should happen if there is a number of
: > : items in the list that's not easily divisible by the arity - should the
: > : rest just be padded with undef's? or just ignored? Or fail() with a
: > : friendly error message?
: > 
: > I think the basic rule has to be simply can the signature bind to
: > the remaining arguments.  If not, we get a warning on unused arguments.
: > We can mark arguments as optional if that's what we mean.  
: > [...]
: > My gut feeling is that
: > placeholder variables probably should not be considered optional; in
: > most cases a non-divisible number of arguments indicates a logic error
: > in the program, and an earlier message is better, even at the expense
: > of thowing away some (possibly valid) partial data.  Especially since
: > we do have a way to indicate that partial data is acceptable:
: > 
: > -> $a, $b?, $c? { $a + ($b//0) + ($c//0) }
: 
: Presumably whatever we decide for C also applies to C, yes?
: 
: for 1..4 -> $a, $b, $c { ... }  # error
: for 1..4 -> $a, $b, $c? { ... } # error
: for 1..4 -> $a, $b?, $c? { ... }# ok

Yes, the only difference between C and C is that you can
only use C at the start of a statement.  But we're more liberal
about where statements are expected in Perl 6, so you can say things
like:

my @results = do for @list -> $x {...};
my @results = (for @list -> $x {...});

and either of those is equivalent to:

my @results = map -> $x {...}, @list;

I also Officially Don't Care if you use map in a void context. :)

Larry


r25775 - docs/Perl6/Spec

2009-03-09 Thread pugs-commits
Author: lwall
Date: 2009-03-09 23:46:07 +0100 (Mon, 09 Mar 2009)
New Revision: 25775

Modified:
   docs/Perl6/Spec/S05-regex.pod
Log:
more result object demotion


Modified: docs/Perl6/Spec/S05-regex.pod
===
--- docs/Perl6/Spec/S05-regex.pod   2009-03-09 22:33:54 UTC (rev 25774)
+++ docs/Perl6/Spec/S05-regex.pod   2009-03-09 22:46:07 UTC (rev 25775)
@@ -35,7 +35,7 @@
 
 =head1 New match result and capture variables
 
-The underlying match result object is now available as the C<$/>
+The underlying match object is now available via the C<$/>
 variable, which is implicitly lexically scoped.  All user access to the
 most recent match is through this variable, even when
 it doesn't look like it.  The individual capture variables (such as C<$0>,
@@ -781,7 +781,7 @@
 
 This has the effect of capturing the square root of the numified string,
 instead of the string.  The C part is matched but is not returned
-unless the first C is later overridden by another C.
+as part of the result object unless the first C is later overridden by 
another C.
 
 These closures are invoked with a topic (C<$_>) of the current match
 state (a C object).  Within a closure, the instantaneous
@@ -2461,16 +2461,6 @@
 In this case the result object is always a string when doing string
 matching, and a list of one or more elements when doing array matching.
 
-Additionally, the C object delegates its C calls
-(such as C<+$match> and C<~$match>) to its underlying result object.
-The only exception is that C handles boolean coercion itself,
-which returns whether the match had succeeded at least once.
-
-This means that these two work the same:
-
-/  { make $moose as Moose } /
-/  { make $$moose as Moose } /
-
 =item *
 
 When used as an array, a C object pretends to be an array of all
@@ -2591,6 +2581,8 @@
  /;
 say $();  # says 'bar'
 
+The result object is available in the C object via a C<< . >> lookup.
+
 =back
 
 =head2 Subpattern captures



r25774 - docs/Perl6/Spec

2009-03-09 Thread pugs-commits
Author: lwall
Date: 2009-03-09 23:33:54 +0100 (Mon, 09 Mar 2009)
New Revision: 25774

Modified:
   docs/Perl6/Spec/S05-regex.pod
Log:
~ and + now just stringify/numify the matched string, not the result object


Modified: docs/Perl6/Spec/S05-regex.pod
===
--- docs/Perl6/Spec/S05-regex.pod   2009-03-09 22:24:01 UTC (rev 25773)
+++ docs/Perl6/Spec/S05-regex.pod   2009-03-09 22:33:54 UTC (rev 25774)
@@ -14,9 +14,9 @@
Maintainer: Patrick Michaud  and
Larry Wall 
Date: 24 Jun 2002
-   Last Modified: 8 Mar 2009
+   Last Modified: 9 Mar 2009
Number: 5
-   Version: 89
+   Version: 90
 
 This document summarizes Apocalypse 5, which is about the new regex
 syntax.  We now try to call them I rather than "regular
@@ -2411,8 +2411,8 @@
 
 =item *
 
-In string context it evaluates to the stringified value of its
-I, which is usually the entire matched string:
+In string context it evaluates to the stringified value of its match,
+which is usually the entire matched string:
 
  print %hash{ "{$text ~~ /<.ident>/}" };
  # or equivalently:
@@ -2422,8 +2422,8 @@
 
 =item *
 
-In numeric context it evaluates to the numeric value of its
-I, which is usually the entire matched string:
+In numeric context it evaluates to the numeric value of its match,
+which is usually the entire matched string:
 
  $sum += /\d+/;
  # or equivalently:



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

2009-03-09 Thread pugs-commits
Author: wayland
Date: 2009-03-09 23:24:01 +0100 (Mon, 09 Mar 2009)
New Revision: 25773

Modified:
   docs/Perl6/Spec/S32-setting-library/Rules.pod
Log:
Updated in line with Larry's changes to S05


Modified: docs/Perl6/Spec/S32-setting-library/Rules.pod
===
--- docs/Perl6/Spec/S32-setting-library/Rules.pod   2009-03-09 22:19:26 UTC 
(rev 25772)
+++ docs/Perl6/Spec/S32-setting-library/Rules.pod   2009-03-09 22:24:01 UTC 
(rev 25773)
@@ -33,7 +33,7 @@
method Int to(){...}
method Int chars() {...}
method orig()  {...}
-   method Str text()  {...}
+   method Str()   {...}
 }
 
 =head2 Cursor



r25772 - docs/Perl6/Spec

2009-03-09 Thread pugs-commits
Author: lwall
Date: 2009-03-09 23:19:26 +0100 (Mon, 09 Mar 2009)
New Revision: 25772

Modified:
   docs/Perl6/Spec/S12-objects.pod
Log:
clarify semantics of invocant type checking on exported methods


Modified: docs/Perl6/Spec/S12-objects.pod
===
--- docs/Perl6/Spec/S12-objects.pod 2009-03-09 22:02:28 UTC (rev 25771)
+++ docs/Perl6/Spec/S12-objects.pod 2009-03-09 22:19:26 UTC (rev 25772)
@@ -12,9 +12,9 @@
 
   Maintainer: Larry Wall 
   Date: 27 Oct 2004
-  Last Modified: 5 Mar 2009
+  Last Modified: 9 Mar 2009
   Number: 12
-  Version: 74
+  Version: 75
 
 =head1 Overview
 
@@ -1055,11 +1055,25 @@
 a colon, or to omit the colon entirely in the case of a method with
 no arguments other than the invocant.  Many standard methods (such
 as C and C) are automatically exported to the
-global namespace by default.  For other exported methods, you will not
+C namespace by default.  For other exported methods, you will not
 see the multi sub definition unless you C the class in your scope,
 which will import the multi sub lexically, after which you can call it
 using normal subroutine call syntax.
 
+In the absence of an explicit type on the method's invocant, the
+exported multi sub's first argument is implicitly constrained to
+match the class in which it was defined or composed, so for instance
+the multi version of C requires its first argument to be of
+type C or one of its subclasses.  If the invocant is explicitly
+typed, that will govern the type coverage of the corresponding multi's
+first argument, whether that is more specific or more general than
+the class's invocant would naturally be.  (But be aware that if it's
+more specific than C<::?CLASS>, the binding may reject an otherwise
+valid single dispatch as well as a multi dispatch.)  In any case,
+it does no good to overgeneralize the invocant if the routine itself
+cannot handle the broader type.  In such a situation you must write
+a wrapper to coerce to the narrower type.
+
 Note that explicit use of a syntactic category as a method name
 overrides the choice of dispatcher, so
 



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

2009-03-09 Thread pugs-commits
Author: wayland
Date: 2009-03-09 23:02:28 +0100 (Mon, 09 Mar 2009)
New Revision: 25771

Modified:
   docs/Perl6/Spec/S32-setting-library/Basics.pod
Log:
Removed "is export" from true/not, as per pmichaud++ s suggestion


Modified: docs/Perl6/Spec/S32-setting-library/Basics.pod
===
--- docs/Perl6/Spec/S32-setting-library/Basics.pod  2009-03-09 21:54:20 UTC 
(rev 25770)
+++ docs/Perl6/Spec/S32-setting-library/Basics.pod  2009-03-09 22:02:28 UTC 
(rev 25771)
@@ -36,8 +36,8 @@
 
  our multi method undefine( $self: ) is export {...}
 
- method not() is export {...}
- method true() is export {...}
+ method not() {...}
+ method true() {...}
  }
 
 =item defined
@@ -75,11 +75,11 @@
 
 =item not
 
- method not() is export {...}
+ method not() {...}
 
 =item true
 
- method true() is export {...}
+ method true() {...}
 
 XXX Copied from S02 -- should it be deleted from there?  
 



r25770 - docs/Perl6/Spec

2009-03-09 Thread pugs-commits
Author: lwall
Date: 2009-03-09 22:54:20 +0100 (Mon, 09 Mar 2009)
New Revision: 25770

Modified:
   docs/Perl6/Spec/S02-bits.pod
   docs/Perl6/Spec/S05-regex.pod
Log:
.i should be \i
.text should be .Str


Modified: docs/Perl6/Spec/S02-bits.pod
===
--- docs/Perl6/Spec/S02-bits.pod2009-03-09 21:49:00 UTC (rev 25769)
+++ docs/Perl6/Spec/S02-bits.pod2009-03-09 21:54:20 UTC (rev 25770)
@@ -895,7 +895,7 @@
 Since native types cannot represent Perl's concept of undefined values,
 in the absence of explicit initialization, native floating-point types
 default to NaN, while integer types (including C) default to 0.
-The complex type defaults to NaN + NaN.i.  A buf type of known size
+The complex type defaults to NaN + NaN\i.  A buf type of known size
 defaults to a sequence of 0 values.  If any native type is explicitly
 initialized to C<*> (the C type), no initialization is attempted
 and you'll get whatever was already there when the memory was allocated.

Modified: docs/Perl6/Spec/S05-regex.pod
===
--- docs/Perl6/Spec/S05-regex.pod   2009-03-09 21:49:00 UTC (rev 25769)
+++ docs/Perl6/Spec/S05-regex.pod   2009-03-09 21:54:20 UTC (rev 25770)
@@ -2546,7 +2546,7 @@
 $/.to  # the final match position
 $/.chars   # $/.to - $/.from
 $/.orig# the original match string
-$/.text# substr($/.orig, $/.from, $/.chars)
+$/.Str # substr($/.orig, $/.from, $/.chars)
 
 Within the regex the current match state C<$¢> also provides
 



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

2009-03-09 Thread pugs-commits
Author: wayland
Date: 2009-03-09 22:49:00 +0100 (Mon, 09 Mar 2009)
New Revision: 25769

Modified:
   docs/Perl6/Spec/S32-setting-library/Numeric.pod
Log:
Changed real to re, and imaginary to im, as perl moritz_++ suggestion


Modified: docs/Perl6/Spec/S32-setting-library/Numeric.pod
===
--- docs/Perl6/Spec/S32-setting-library/Numeric.pod 2009-03-09 21:43:40 UTC 
(rev 25768)
+++ docs/Perl6/Spec/S32-setting-library/Numeric.pod 2009-03-09 21:49:00 UTC 
(rev 25769)
@@ -210,15 +210,15 @@
 Returns (magnitude, angle) corresponding to the complex number.
 The magnitude is non-negative, and the angle in the range C<-π ..^ π>.
 
-=item real
+=item re
 
-method real() {...}
+method re() {...}
 
 Returns the real part of the complex number.  
 
-=item imaginary
+=item im
 
-method imaginary() {...}
+method im() {...}
 
 Returns the imaginary part of a complex number.  
 



Re: Masak List, take 3

2009-03-09 Thread Timothy S. Nelson

On Mon, 9 Mar 2009, Patrick R. Michaud wrote:


On Fri, Mar 06, 2009 at 01:37:16PM +1100, Timothy S. Nelson wrote:

I guess the way I decide things like this is:
-   If it's a method on a role/object, then it lives in S32
-   If it's not a method, then it lives in S29


Do we have many things that aren't methods?


	As few as possible :).  The things that remain in S29 are mostly not 
methods, but even a few of those are.



* Should there be a way to extract information about a Rat's
numerator/denominator? What methods does a Rat have?


I'm also curious about extracting real and imaginary components
from Complex.


Specced.  Feel free to suggest name changes.


# true(), not(), also methods


On?


C is a method on Object (S02:3391), I suspect that
C is also (S03:3282).

Beyond that, I think that what one would think of as
true() or not() are really prefix: and prefix:,
and not "functions" in the normal sense.


	Operators, rather than functions?  But if they're also methods, won't 
they have to be defined separately, rather than putting "is export" on the 
method?


:)


-
| Name: Tim Nelson | Because the Creator is,|
| E-mail: wayl...@wayland.id.au| I am   |
-

BEGIN GEEK CODE BLOCK
Version 3.12
GCS d+++ s+: a- C++$ U+++$ P+++$ L+++ E- W+ N+ w--- V- 
PE(+) Y+>++ PGP->+++ R(+) !tv b++ DI D G+ e++> h! y-

-END GEEK CODE BLOCK-



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

2009-03-09 Thread pugs-commits
Author: wayland
Date: 2009-03-09 22:43:40 +0100 (Mon, 09 Mar 2009)
New Revision: 25768

Modified:
   docs/Perl6/Spec/S32-setting-library/Basics.pod
   docs/Perl6/Spec/S32-setting-library/Numeric.pod
Log:
Added real/imaginary to Complex, and true/not to Object


Modified: docs/Perl6/Spec/S32-setting-library/Basics.pod
===
--- docs/Perl6/Spec/S32-setting-library/Basics.pod  2009-03-09 19:50:03 UTC 
(rev 25767)
+++ docs/Perl6/Spec/S32-setting-library/Basics.pod  2009-03-09 21:43:40 UTC 
(rev 25768)
@@ -31,10 +31,13 @@
 The following are defined in the C role:
 
  role  Object {
- our Bool multi method defined ($self:) {...}
- our Bool multi method defined ($self: ::role ) {...}
+ our Bool multi method defined ($self:) is export {...}
+ our Bool multi method defined ($self: ::role ) is export {...}
 
- our multi method undefine( $self: ) {...}
+ our multi method undefine( $self: ) is export {...}
+
+ method not() is export {...}
+ method true() is export {...}
  }
 
 =item defined
@@ -70,6 +73,25 @@
 should place the object in the same state as if it was just
 declared.
 
+=item not
+
+ method not() is export {...}
+
+=item true
+
+ method true() is export {...}
+
+XXX Copied from S02 -- should it be deleted from there?  
+
+The definition of C<.true> for the most ancestral type (that is, the
+C type) is equivalent to C<.defined>.  Since protoobjects are
+considered undefined, all protoobjects (including C itself)
+are false unless the type overrides the definition of C<.true>
+to include undefined values.  Instantiated objects default to true
+unless the class overrides the definition.  Note that if you could
+instantiate an C it would be considered defined, and thus true.
+(It is not clear that this is allowed, however.)
+
 =head2 Any
 
 The following are defined in the C role:

Modified: docs/Perl6/Spec/S32-setting-library/Numeric.pod
===
--- docs/Perl6/Spec/S32-setting-library/Numeric.pod 2009-03-09 19:50:03 UTC 
(rev 25767)
+++ docs/Perl6/Spec/S32-setting-library/Numeric.pod 2009-03-09 21:43:40 UTC 
(rev 25768)
@@ -210,6 +210,18 @@
 Returns (magnitude, angle) corresponding to the complex number.
 The magnitude is non-negative, and the angle in the range C<-π ..^ π>.
 
+=item real
+
+method real() {...}
+
+Returns the real part of the complex number.  
+
+=item imaginary
+
+method imaginary() {...}
+
+Returns the imaginary part of a complex number.  
+
 =back
 
 =head2 The :Trig tag



Re: r25745 - docs/Perl6/Spec

2009-03-09 Thread Patrick R. Michaud
On Mon, Mar 09, 2009 at 10:53:12AM -0700, Larry Wall wrote:
> : - PGE doesn't implement  by default, because that's not (yet?)
> :   part of the spec.  It only appears in PCT::Grammar, for people
> :   using the Parrot Compiler Toolkit to create languages.
> 
> I have wanted  a number of times, particularly after generic
> tokens that might or might end in \w.  So feel free to spec it.

Now done in r25767.  I went ahead and removed  and fixed
up the , , , and  descriptions while I was
at it.

Pm


r25767 - docs/Perl6/Spec

2009-03-09 Thread pugs-commits
Author: pmichaud
Date: 2009-03-09 20:50:03 +0100 (Mon, 09 Mar 2009)
New Revision: 25767

Modified:
   docs/Perl6/Spec/S05-regex.pod
Log:
[spec]:  Update S05: remove , add , revise , , , and 
.


Modified: docs/Perl6/Spec/S05-regex.pod
===
--- docs/Perl6/Spec/S05-regex.pod   2009-03-09 17:33:17 UTC (rev 25766)
+++ docs/Perl6/Spec/S05-regex.pod   2009-03-09 19:50:03 UTC (rev 25767)
@@ -1619,9 +1619,9 @@
 
 =back
 
-=head2 Predefined Metasyntax
+=head2 Predefined Subrules
 
-The following symbols are predefined entries in the metasyntax.  
+These are the predefined subrules for any grammar or regex:
 
 =over
 
@@ -1669,25 +1669,31 @@
 
 Match a single alphanumeric character. This is equivalent to <+alpha +digit> .
 
-= item * word
+=item * wb
 
-Match a single word character, viz., alphanumeric plus '_'.
+Returns a zero-width match that is true at word boundaries.  A word
+boundary is a spot with a "\w" on one side and a "\W" on the other
+side (in either order), counting the beginning and end of the string
+as matching "\W".
 
-=item * wb
+=item * ww
 
-Returns true if we're at a word boundary. A word boundary is a spot between 
two characters, one which matches , the other matches <-word>, counting 
the imaginary characters off the beginning and end of the string as matching a 
<-word>.
+Matches between two word characters (zero-width match).
 
 =item * ws
 
-Match whitespace between tokens.
+Matches required whitespace between two word characters, optional
+whitespace otherwise.  This is roughly equivalent to  C<<  \s* >>
+(C isn't required to use the C subrule).
 
 =item * space
 
-Match a single whitespace character. Hence C<  > is equivalent to C< 
+ >.
+Match a single whitespace character (same as C< \s > ).
 
 =item * blank
 
-Match a single "blank" character. Differs from C<  > which include 
C's etc.
+Match a single "blank" character -- in most locales, this corresponds
+to space and tab.
 
 =item * before C
 



Re: .map/.reduce with larger arity

2009-03-09 Thread Larry Wall
On Mon, Mar 09, 2009 at 02:40:43PM -0300, Daniel Ruoso wrote:
: Em Dom, 2009-03-08 às 21:31 -0700, Larry Wall escreveu:
: > I think the basic rule has to be simply can the signature bind to
: > the remaining arguments.  If not, we get a warning on unused arguments.
: 
: Just to put here an idea I sent on irc...
: 
: What if Signature.ACCEPTS set $/ with the matched arguments?
: 
: That way we can both know how many arguments the Signature can receive
: as well as allow us to use the match as the capture to that call...
: 
:   ... $capture ~~ $signature ...;
:   my $args_matched = @($/).elems;
:   &code.(|$/);

That API still would not tell the match whether signature must match the
entire capture (what you want for normal binding) or can stop part way
(what you want for map and friends).

Larry


Re: r25745 - docs/Perl6/Spec

2009-03-09 Thread Larry Wall
: - PGE doesn't implement  by default, because that's not (yet?)
:   part of the spec.  It only appears in PCT::Grammar, for people
:   using the Parrot Compiler Toolkit to create languages.

I have wanted  a number of times, particularly after generic
tokens that might or might end in \w.  So feel free to spec it.

: - AFAICT, apostrophe and hyphen are not yet "word characters" in
:   the sense of being members of \w .  That is, they're considered
:   to be valid in identifiers, but only when they are immediately
:   preceded by a word character and immediately followed by an 
:   alphabetic character.  Otherwise they're not part of the
:   identifier.  (At least, that's how the current STD.pm reads.)

That's correct, we can ignore ' and - for that purpose.

Larry


Re: r25745 - docs/Perl6/Spec

2009-03-09 Thread Patrick R. Michaud
On Mon, Mar 09, 2009 at 10:32:02AM -0700, jerry gay wrote:
> > To make things a bit quicker for people writing custom versions of
> >  (which may need to include "comment whitespace"), the Parrot
> > Compiler Toolkit also provides an optimized  rule that matches
> > only between a pair of word characters.  Then the default definition
> > of  becomes
> >
> >    token ws {  \s* }
>
> if you need a mnemonic to help you remember what 'ww' means, use 'within 
> word'.
> 
> this reminds me that pge's  may be incorrect in its treatment of
> .  these characters (<['-]> by default) are word
> characters, but i don't think that's been tested, and i don't think
> it's been implemented, either.

A couple of clarifications:

- PGE doesn't implement  by default, because that's not (yet?)
  part of the spec.  It only appears in PCT::Grammar, for people
  using the Parrot Compiler Toolkit to create languages.

- AFAICT, apostrophe and hyphen are not yet "word characters" in
  the sense of being members of \w .  That is, they're considered
  to be valid in identifiers, but only when they are immediately
  preceded by a word character and immediately followed by an 
  alphabetic character.  Otherwise they're not part of the
  identifier.  (At least, that's how the current STD.pm reads.)

Pm


Re: .map/.reduce with larger arity

2009-03-09 Thread Daniel Ruoso
Em Dom, 2009-03-08 às 21:31 -0700, Larry Wall escreveu:
> I think the basic rule has to be simply can the signature bind to
> the remaining arguments.  If not, we get a warning on unused arguments.

Just to put here an idea I sent on irc...

What if Signature.ACCEPTS set $/ with the matched arguments?

That way we can both know how many arguments the Signature can receive
as well as allow us to use the match as the capture to that call...

  ... $capture ~~ $signature ...;
  my $args_matched = @($/).elems;
  &code.(|$/);

daniel



Re: r25745 - docs/Perl6/Spec

2009-03-09 Thread jerry gay
On Mon, Mar 9, 2009 at 10:16, Patrick R. Michaud  wrote:
>> On Sun, Mar 08, 2009 at 09:43:17AM +0100, pugs-comm...@feather.perl6.nl 
>> wrote:
>> =item * ws
>>
>> Match whitespace between tokens.
>>
>> =item * space
>>
>> Match a single whitespace character. Hence C<  > is equivalent to C< 
>> + >.
>
>
> The definitions of  and  above are incorrect, or at least
> misleading.   matches required whitespace between pairs of word
> characters; it's optional whitespace otherwise.  The default definition
> of  is something like:
>
>    token ws {|| \s* }
>
> It's certainly _not_ the case that  is equivalent to + .
>
> To make things a bit quicker for people writing custom versions of
>  (which may need to include "comment whitespace"), the Parrot
> Compiler Toolkit also provides an optimized  rule that matches
> only between a pair of word characters.  Then the default definition
> of  becomes
>
>    token ws {  \s* }
>
> Grammars can change this to things like:
>
>    token ws {  [ \s+ || '#' \h* \n ]* }
>
if you need a mnemonic to help you remember what 'ww' means, use 'within word'.

this reminds me that pge's  may be incorrect in its treatment of
.  these characters (<['-]> by default) are word
characters, but i don't think that's been tested, and i don't think
it's been implemented, either.

~jerry


Re: r25745 - docs/Perl6/Spec

2009-03-09 Thread Patrick R. Michaud
> On Sun, Mar 08, 2009 at 09:43:17AM +0100, pugs-comm...@feather.perl6.nl wrote:
> =item * ws
> 
> Match whitespace between tokens.
> 
> =item * space
> 
> Match a single whitespace character. Hence C<  > is equivalent to C< 
> + >.


The definitions of  and  above are incorrect, or at least
misleading.   matches required whitespace between pairs of word
characters; it's optional whitespace otherwise.  The default definition
of  is something like:

token ws {|| \s* }

It's certainly _not_ the case that  is equivalent to + .

To make things a bit quicker for people writing custom versions of
 (which may need to include "comment whitespace"), the Parrot
Compiler Toolkit also provides an optimized  rule that matches 
only between a pair of word characters.  Then the default definition 
of  becomes 

token ws {  \s* }

Grammars can change this to things like:

token ws {  [ \s+ || '#' \h* \n ]* }

Pm


Re: Masak List, take 3

2009-03-09 Thread Patrick R. Michaud
On Fri, Mar 06, 2009 at 01:37:16PM +1100, Timothy S. Nelson wrote:
>   I guess the way I decide things like this is:
> - If it's a method on a role/object, then it lives in S32
> - If it's not a method, then it lives in S29

Do we have many things that aren't methods?

>> * Should there be a way to extract information about a Rat's  
>> numerator/denominator? What methods does a Rat have?

I'm also curious about extracting real and imaginary components
from Complex.

>> # true(), not(), also methods
>
>   On?

C is a method on Object (S02:3391), I suspect that 
C is also (S03:3282).

Beyond that, I think that what one would think of as
true() or not() are really prefix: and prefix:,
and not "functions" in the normal sense.

Pm


Re: .map/.reduce with larger arity

2009-03-09 Thread Patrick R. Michaud
On Sun, Mar 08, 2009 at 09:31:19PM -0700, Larry Wall wrote:
> On Sun, Mar 08, 2009 at 09:36:17PM +0100, Moritz Lenz wrote:
> : But both pugs and rakudo respect the arity of the code ref passed to it,
> : so that (1..6).map({$^a + $^b + $^c}) returns the list (6, 15), which is
> : very nice and very DWIM'my.
> : 
> : But it opens the question what should happen if there is a number of
> : items in the list that's not easily divisible by the arity - should the
> : rest just be padded with undef's? or just ignored? Or fail() with a
> : friendly error message?
> 
> I think the basic rule has to be simply can the signature bind to
> the remaining arguments.  If not, we get a warning on unused arguments.
> We can mark arguments as optional if that's what we mean.  
> [...]
> My gut feeling is that
> placeholder variables probably should not be considered optional; in
> most cases a non-divisible number of arguments indicates a logic error
> in the program, and an earlier message is better, even at the expense
> of thowing away some (possibly valid) partial data.  Especially since
> we do have a way to indicate that partial data is acceptable:
> 
> -> $a, $b?, $c? { $a + ($b//0) + ($c//0) }

Presumably whatever we decide for C also applies to C, yes?

for 1..4 -> $a, $b, $c { ... }  # error
for 1..4 -> $a, $b, $c? { ... } # error
for 1..4 -> $a, $b?, $c? { ... }# ok

Pm


Re: r25745 - docs/Perl6/Spec

2009-03-09 Thread Larry Wall
On Sun, Mar 08, 2009 at 09:43:17AM +0100, pugs-comm...@feather.perl6.nl wrote:
: added new rule  to enable definition of .

 is bad design, because people will think it matches a whole word,
and it's unnecessary because it duplicates \w.

Larry


Re: Recursive Runtime Role Reapplication Really Rebounds

2009-03-09 Thread Ovid

- Original Message 

> From: Ovid 

> Eventually, the code broke and threw a bunch of weird "recursive inheritance" 
> warnings due to multiple anonymous classes being applied to the object.  This 
> was *real fun* to debug, but I can imagine a scenario for this being natural:
> 
> Your REST interface returns XML, but sometimes someone wants YAML.  So you 
> have:
> 
>   $resultset does Role::Serializable::XML
> 
> But sometimes:
> 
>   $resultset does Role::Serializable::YAML
> 
> Since you cache resultsets if they've not changed, you could easily have the 
> XML 
> and YAML roles getting reapplied at runtime multiple times.  

Could this issue be mitigated with temp variables?

  {
  temp $resultset does Role::Serializable::YAML;
  print $resultset.as_string;
  }

 
Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6