On Wednesday, February 12, 2003, at 05:50 PM, Deborah Ariel Pickett wrote:
All right, I'm prepared to buy that. Now how would it extend to hashes?

A %hash in list context returns a list of its pairs (NOTE4)
A %hash in scalar context returns a reference to itself (NOTE1)
A %hash in numeric (scalar) context returns (?)
A %hash in string (scalar) context returns (?)

A $hashref in list context returns a hashref (NOTE2)
A $hashref in scalar context returns a hashref
A $hashref in numeric (scalar) context returns (?)
A $hashref in string (scalar) context returns (?)

(NOTE4): Or is it a flattened list of key-values?
As far as NOTE4, I don't think they've decided yet. At least, I can't seem to find confirmation of it.

One possibility for the (?) part is of course that numeric context returns the number of keys, and that string context returns a pretty-printed list of key => value pairs. That would seem the most obvious answer, but it might not be the right one. We have to get that verified too.

And how would it extend to the finer-grained contexts we're getting in
Perl6 (integer numeric scalar context, hashref context, ...)?  Our
complete list of contexts now is quite a hierarchy.
Yeah, I'm waiting eagerly for A6 to talk about that, but it shouldn't be too hard. Certainly, context seems to be a simple tree. So 'want' can return true for multiple things...

my int $i = foo();
...

# now inside foo:

want scalar; # true
want numeric; # true
want int; # true
want str; # false

I've been told with great consistency that there's not really going to be complete, typedef-style contexts... e.g., you'll be able to tell "hash" context, but you won't be able to tell the difference between "hash of ints" and "hash of strs" context. Which is a shame, IMO, since multimethods could benefit from as much info as possible, but we'll see what they come up with.


An @array in nonbinding list context returns a list of its elements.
An @array in binding list context returns the symbol table reference for
itself
An @array in nonbinding scalar context returns a reference to itself.
An @array in binding scalar context returns the symbol table reference for
itself

Would that fly? If so, I'd expect the new generic want() operator to be
able to detect it.
Huh, I never really thought of it that way, but I suppose it would have to be something like that. So you can overload the binding operator C<:=>...

MikeL



Reply via email to