Damian Conway wrote:
>
> That's indeed precisely what I meant. In fact, all list-returning built-ins
> ought to be optimized this way.
I think we're pretty much agreed on this point, but I have a tangential
question about want().
By RFC 21, it looks like the call would be
if ( want 'LIST' ) {
$num_to_return = want;
# do stuff
}
I'm basing this on the description which says:
> If C<want> is called in any other context without arguments, it returns
> a list consisting of the expectation count, followed by all aspects that
> are currently true.
However, at one time the discussion had implied that in a scalar
context, you could use want as so:
if ( want eq 'LIST' ) { }
That is, it doesn't return the expectant count as arg1, but rather what
is wanted. This syntax I actually prefer, since you could easily switch
very quickly like so:
$want = want;
return $want eq 'LIST' ? do_list_stuff :
$want eq 'SCALAR' ? do_scalar_stuff :
...
You get the idea. It also allows you to have a function which
automatically is generated or dispatched:
my $func = lc want . "_func";
return &$func(@_);
Since RFC 21 is still on v1, my question is: Which is it? Personally, I
like the second one better. Now, if in a scalar context want() returned
a polymorphic object:
$want = want;
return $want eq 'LIST' ? do_list_stuff($want->numargs) :
$want eq 'SCALAR' ? do_scalar_stuff($want->someotherparam) :
...
Then it seems we have the best of both worlds. Input?
-Nate