On Thursday, December 5, 2002, at 07:53 AM, Austin Hastings wrote:
This is a terribly important question, for divvy() and everything else. Whether or not the description of "context" of a sub/block has the same robustness as the "arguments" of that sub/block has big implications for multimethods, among other things.And in general, without resorting to something hideous like scanf, is there going to be some more-advanced want() variant that allows saying@a, $i, $j, @b, %w, $k, @c = scramble(...);
I would hope that, minimally, the return type is considered part of the (multimethod) signature, and that you can test for at least the scalar types:
my int $i = bar(...); # so these are
my str $s = bar(...); # the same sub, but
my MyClass $o = bar(...); # different multimethod variants.
In my fantasy world (which I visit quite often), P6 context has descriptive capabilities matching those that can be assigned to args.
(@a,@b) = foo(...); # same sub,
(@a,@b,@c) = foo(...); # different multimethod variants.
my int @arr = zap(...); # ... you get the idea ...
my num @arr = zap(...);
my MyClass @arr = zap(...);
my Array of Array of Hash of MyClass @arr = zap(...);
That last one leads to the obvious question of what C<want> returns in the case of compound types:
my Array of Array of Hash of MyClass @arr = zap(...);
... then inside zap ...
want scalar; # false;
want list; # true (but what spelling?)
want Array; # true (but what spelling?)
want Array of Array; # true
want Array of Array of Hash; # true
want Array of Array of Hash of MyClass; # true
want Hash; # false
want MyClass; # false
want Array of int; # false
my $want = want; # 'Array of Array of Hash of MyClass'; (?)
my @want = want; # qw(Array, Array, Hash, MyClass); (?)
If we have such functionality, than divvy() and other multimethods can be tailored to DWYM even in quite specific contexts, and a lot of things become much easier.
MikeL