develooper Front page | perl.perl6.language | Postings from May 2005

Re: reduce metaoperator on an empty list

Thread Previous | Thread Next
From:
Damian Conway
Date:
May 31, 2005 21:15
Subject:
Re: reduce metaoperator on an empty list
Message ID:
429D365F.601@conway.org
Joe Gottman pointed out:

>>No. It returns empty string. You could think of C<join> as being
>>implemented:
>>
>>     sub join (Str $sep, *@list) { reduce { $^a ~ $sep ~ $^b } "", @list }
 >
>    If this were the case, then
> 	join '~', 'a', 'b', 'c'
>      would equal '~a~b~c' instead of 'a~b~c'

Good point. Thanks. Make that:

     sub join (Str $sep, *@list) {
         reduce { $^a ~ $sep ~ $^b } @list || ""
     }

Presuming (of course) that my earlier plea that || should preserve context 
across both operands is granted. ;-)

Damian

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About