Patrick R. Michaud wrote:
> On Wed, Sep 17, 2008 at 08:37:36PM +0800, Chris Davaz wrote:
>> I am confused about how we should setup method signatures:
>> 
>> Let's take a look at a line in any-str.pir:
>> 
>>  46 .sub 'comb' :method :multi(_)
>>  47     .param pmc regex
>>  48     .param int count        :optional
>>  49     .param int has_count    :opt_flag
>> 
>> As you can see we have one parameter specified in :multi which is _ (any
>> type). However we also have two .param lines, 47 and 48. So here are some
>> questions:
>> 
>> I noticed 'self' is implicitly defined, however does 'self' eat up a
>> parameter? Should we always have one parameter in :multi specified for the
>> object the method is running on?
> 
> Yes, the first argument of the :multi refers to the invocant.
I didn't know this (shame on me), which resulted in some brokenness, it
seems. Particularly Str.split looks like this:

.sub 'split' :method :multi('String')

Which should probably be

.sub 'split' :method :multi(_, 'String')

Sadly this change breaks Str.reverse, which calls split with empty
string on its invocant:

.sub 'reverse' :method :multi('String')
    .local pmc retv

    retv = self.'split'('')
    retv = retv.'reverse'()
    retv = retv.join('')

    .return(retv)
.end

(With the "correct" signature for Str.split this dies with "no
applicable methods").

Moritz

-- 
Moritz Lenz
http://moritz.faui2k3.org/ |  http://perl-6.de/

Reply via email to