syntax question on parameter lists

2008-04-10 Thread John M. Dlugosz
S06 shows how to define named-only parameters, marked with a prefix :.  But 
no example shows anything more than a bare parameter name.  No type is ever 
given!

Looking through my copy of STD.pm, I'm baffled, as it seems not to take types 
in parameter lists at all.

So, is it
  method bytes ( Encoding :$encoding ) returns Int

or 

  method bytes ( : Encoding $encoding ) returns Int

?

I'm guessing that the latter would be confused with use of : after the 
invocant, and it follows that

  method bytes (Encoding :encoding($override_encoding)) returns Int

would work.


Re: syntax question on parameter lists

2008-04-10 Thread Larry Wall
On Fri, Apr 11, 2008 at 03:26:02AM -, John M. Dlugosz wrote:
: S06 shows how to define named-only parameters, marked with a prefix :.  But 
no example shows anything more than a bare parameter name.  No type is ever 
given!
: 
: Looking through my copy of STD.pm, I'm baffled, as it seems not to take types 
in parameter lists at all.

It's at the top of token parameter where there is a type_constraint*.

: So, is it
:   method bytes ( Encoding :$encoding ) returns Int
: 
: or 
: 
:   method bytes ( : Encoding $encoding ) returns Int
: 
: ?
: 
: I'm guessing that the latter would be confused with use of : after the 
invocant, and it follows that
: 
:   method bytes (Encoding :encoding($override_encoding)) returns Int
: 
: would work.

Indeed.

Larry


Re: syntax question on parameter lists

2008-04-10 Thread Patrick R. Michaud
On Thu, Apr 10, 2008 at 09:18:38PM -0700, Larry Wall wrote:
 On Fri, Apr 11, 2008 at 03:26:02AM -, John M. Dlugosz wrote:
 : S06 shows how to define named-only parameters, marked with a prefix :.  
 But no example shows anything more than a bare parameter name.  No type is 
 ever given!
 : 
 : Looking through my copy of STD.pm, I'm baffled, as it seems not to take 
 types in parameter lists at all.
 
 It's at the top of token parameter where there is a type_constraint*.

Yes, but where does type_constraint resolve down to a typename?
My reading of STD.pm is that type_constraint becomes a value 
(since it's not a 'where' clause in this case), and value is currently
one of quote, number, or version.

Pm