Re: default parameters in methods

2008-04-11 Thread John M. Dlugosz

Larry Wall larry-at-wall.org |Perl 6| wrote:


All default expressions to any parameter are defined to run in the
context that assumes any parameters to their left are already bound,
so you may safely depend on self already being set.

  


OK, so there is no technical reason why it can't work that way.

But, self the keyword is not $self the parameter (it only works in 
methods), and there are issues of trust.  So I need to describe it properly.


--John


default parameters in methods

2008-04-10 Thread John M. Dlugosz
It is not specified in the Synopses as I recall, but I believe that this is 
useful enough that it must be made to work:

   method bytes (Encoding :$encoding = .encoding)
   returns Int

or even

   method bytes (Encoding :$encoding = self!encoding)
   returns Int

That is, a named-only parameter, which may be used as an optional adverb or 
extra parameter to affect details of the function, should default to a pre-set 
value inside the instance.

If this is not allowed, the beginning of the method would always have to check 
for defaults.  That should be automatic.  And it documents the situation nicely 
in the signature, without further explanation that if the parameter is not 
supplied...

This means that the default arguments run inside the context of the method 
call, and can do anything that you would expect from their lexical position.

--John


Re: default parameters in methods

2008-04-10 Thread Larry Wall
On Fri, Apr 11, 2008 at 03:35:37AM -, John M. Dlugosz wrote:
: It is not specified in the Synopses as I recall, but I believe that this is 
useful enough that it must be made to work:
: 
:method bytes (Encoding :$encoding = .encoding)
:returns Int
: 
: or even
: 
:method bytes (Encoding :$encoding = self!encoding)
:returns Int
: 
: That is, a named-only parameter, which may be used as an optional adverb or 
extra parameter to affect details of the function, should default to a pre-set 
value inside the instance.
: 
: If this is not allowed, the beginning of the method would always have to 
check for defaults.  That should be automatic.  And it documents the situation 
nicely in the signature, without further explanation that if the parameter is 
not supplied...
: 
: This means that the default arguments run inside the context of the method 
call, and can do anything that you would expect from their lexical position.

All default expressions to any parameter are defined to run in the
context that assumes any parameters to their left are already bound,
so you may safely depend on self already being set.

Larry