[BristolBathPM] Perl 6 "elems"
Alex Francis
alex.francis at gmail.com
Sat Jun 20 20:25:15 BST 2009
I finally got round to reading a little about Perl 6 - Gabor's blog
post / mailout:
http://szabgab.com/blog/2009/06/1245228625.html
One thing that leapt out to me was this bit:
--quote--
Instead of the quite ugly $#array notation used in Perl 5 (that
returns the highest index in the array) fetching the number of
elements of array is done in Perl 6 by the elems() function. Actually
I think the object oriented writing is much nicer here:
use v6;
my @names = <foo bar baz>;
say elems @names; # 3
say @names.elems; # 3
--end quote--
"elems" seems a pretty odd choice of word. Does anyone know why any of
'length', 'count' or 'size' wasn't chosen for this?
Maybe there's an archived discussion somewhere that explains the rationale?
I did find this RFC requesting length( @array ) -
http://dev.perl.org/perl6/rfc/212.html
Ah... answers own question: http://dev.perl.org/perl6/doc/design/apo/A02.html
Basically, "length" is ambiguous / would require overloading for
different arguments, hence "elems" is more specific, explicit and less
likely to be misinterpreted. I still think "count" would have been
clearer, but hey ho.
Alex
More information about the BristolBathPM
mailing list