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

RE: reduce metaoperator on an empty list

Thread Previous | Thread Next
From:
Joe Gottman
Date:
May 31, 2005 20:19
Subject:
RE: reduce metaoperator on an empty list
Message ID:
200506010319.j513JZLv024932@ms-smtp-01-eri0.southeast.rr.com


> -----Original Message-----
> From: Damian Conway [mailto:damian@conway.org]
> Sent: Tuesday, May 31, 2005 11:14 PM
> To: perl6-language@perl.org
> Subject: Re: reduce metaoperator on an empty list
> 
> Juerd asked:
> 
> 
> >>    2+ args: interpolate specified operator
> >>    1 arg:   return that arg
> >>    0 args:  fail (i.e. thrown or unthrown exception depending on use
> fatal)
> >
> > Following this logic, does join(" ", @foo) with +@foo being 0 fail too?
> 
> No. It returns empty string. You could think of C<join> as being
> implemented:
> 
>      sub join (Str $sep, *@list) { reduce { $^a ~ $sep ~ $^b } "", @list }
> 
> Just as C<sum> is probably implemented:
> 
>      sub sum (*@list) { [+] 0, @list }
> 

   If this were the case, then
	join '~', 'a', 'b', 'c'
     would equal '~a~b~c' instead of 'a~b~c'

Joe Gottman


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