On Mon, 6 Dec 2004, Larry Wall wrote:

Hmm.  Also says maybe you could attach a block to a hash or array to
define what subscripting does.  Hmm.

That's tantalizing. Did you have something like this in mind:

# Count number of accesses to each key
our %counter_hash;
my %hash is subscripted
   -> $subscript { %counter_hash{$subscript}++; %hash{$subscript} };

Or even:

# Provide a "view" of the hash
my %hash is subscripted
   -> $address { %hash{address_to_zipcode($address)}};

so that users can think that they are accessing %hash{"Bloomington, IN"} when they are really accessing %hash{47401}.

Or scarier, using MMD-like stuff (I am not even thinking about syntax) we get different things based on the signature of the key, giving us the ability to differentiate between %hash{$Dog} or %hash{$Vet}.

And pretty soon somebody will define an accessor for the signature (SQL_Query $s).

It seems to me that this idea is not very far away from P5 "tying", but I may be wrong. If it is not very far away, maybe we can even have:

my %hash is subscripted -> $s{
                FETCH {...}
                STORE {...}
        }

Crazy stuff. I don't know if it is doable or even desirable, but it sure is cool!


Larry

--abhijit

Abhijit Mahabal http://www.cs.indiana.edu/~amahabal/

Reply via email to