develooper Front page | perl.perl6.language.subs | Postings from September 2000

RFC 212 (v1) Make length(@array) work

From:
Perl6 RFC Librarian
Date:
September 13, 2000 00:07
Subject:
RFC 212 (v1) Make length(@array) work
Message ID:
20000913070742.22542.qmail@tmtowtdi.perl.org
This and other RFCs are available on the web at
  http://dev.perl.org/rfc/

=head1 TITLE

Make length(@array) work

=head1 VERSION

  Maintainer: Nathan Torkington <gnat@frii.com>
  Date: Sep 12 2000
  Mailing List: perl6-language-subs@perl.org
  Number: 212
  Version: 1
  Status: Developing

=head1 ABSTRACT

length(@foo) should return the number of elements in
@foo.

=head1 DESCRIPTION

Presently length() has a prototype of ($) which means it coerces its
argument into scalar context.  Many newbies think of the number of
elements in an array as its "length", and try to use this function. 
Instead of the size of the array, they get a rough base-10 logarityhm
of the number of elements.

I propose to make length() return the number of elements in the array
it is passed, if its first argument begins with @.

=head1 IMPLEMENTATION

The optimizer could replace

  length @array

with

  scalar(@array)

The perl526 converter could replace

  length @array

with

  length scalar(@array)

=head1 REFERENCES

perlfunc for documentation on length() function





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