[This somewhat elderly draft was found lying about an edit
buffer, but I do not believe it was ever sent yet.]
>Now, the possibility to either pass individual scalars to a sub, or an
>array, (or several arrays, or a mixture of arrays and scalars) and Perl
>treating them as equivalent, that is pretty much the most important
>feature of Perl. IMO. Perl would not be Perl without it.
Well, "most important" is an interestingly strong way of phrasing it.
But how to deal with variadicity in an intuitive fashion is hard.
You seem to have to sacrifice compile-time knowledge, or else
programmer-convenience. Tim Bunce had some ideas on this once.
I still almost always end up first using no protos and then employing
extensive run-time comparisons, such as this sequence might illustrate:
confess "need args" unless @_;
confess "need even args" unless @_ % 2 == 0;
confess "keys mustn't be refs"
if grep { ref }, @_[map { 2*$_} 0.. int($#_/2)] }
confess "values must be hashrefs"
if grep { reftype($_) ne 'HASH' }, @_[map {1+2*$_} 0.. int($#_/2)] }
confess "values must be Frobulants"
if grep { $_->isa("Frobulant") }, @_[map {1+2*$_} 0.. int($#_/2)] }
I should like to see the context coercer née prototype that satisfies
criteria such as these. Yes, I cannot imagine that Damian doesn't already have
a syntax for such :-) but what about compile-time versus run-time issues?
Could the prototype people please report whether Tim Bunce's issues with
prototypes have been intentionally/adequately addressed?
--tom