develooper Front page | perl.perl5.porters | Postings from July 2001

prototype ideas

Thread Next
From:
Jeff 'japhy/Marillion' Pinyan
Date:
July 30, 2001 11:33
Subject:
prototype ideas
Message ID:
Pine.GSO.4.21.0107301418460.28213-100000@crusoe.crusoe.net
How far are we thinking of taking the current prototype system, before
Perl 6?  If we still have unnamed prototypes, I have some suggestions:

  prototype	meaning
  ---------	-------
  \?		auto-reference
  @@		a list, BUT AT LEAST ONE ARGUMENT*
  $|$$$$	one scalar, or four** (Casey West's idea)
  $+		one or more scalars (like $;$$$...)
  \@+		one or more array references (like \@;\@\@\@...)

* sub foo (@) can take NO args, and sub foo ($@) is subtly different
** $;$$$ means 1, 2, 3, or 4 args -- $|$$$$ means 1 or 4 args

Maybe we'd want to use the '...' sequence to mean "or more", like in C's
variadic functions.

  sub max_array (\@...) {
    my ($size, $aref) = (0, []);
    $size < @$_ and ($size, $aref) = (scalar @$_, $_) for @_;
    return wantarray ? ($aref, $size) : $aref;
  }

This allows me to say:

  my $biggest_array = max_array(@a, @b, @c, @d);

The ... does not need to be final, either!

  sub store_sizes (\@...\%) {
    my $href = pop;
    $href->{$_} = @$_ for @_;
  }

  store_sizes(@a, @b, @c, @d, %size);

I am ready to take on the task of implementing these, I just want to know
the general approval/disapproval.

-- 
Jeff "japhy" Pinyan      japhy@pobox.com      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **



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