At 10:56 AM 9/16/00 -0400, Michael G Schwern wrote:
>Pseudo-hashes are not a good/clean way to implement typed objects.
>Why?  Can't do multiple inheritence (without *alot* of contortions).
>And there's also the inefficiencies of untyped pseudo-hash access.
>
>Pseudo-hashes made some sense in the restrictions of Perl 5 syntax,
>but we've got room now to rethink the problem from scratch.

Well, I always found them odd on two counts: (a) weird implementation 
(sorta like grafting a submarine on a Greyhound bus - I don't mean the 
underlying C, I mean the part exposed to the user), and (b) using them for 
object attributes seemed very kludgy.

However, while we've got ways in P6 to do objects better without 
pseudo-hashes, a major benefit of them to me is nothing to do with objects, 
and that's the ability to fix the keys of a hash.  I would like to see this 
retained.

<Brainstorming> How about an attribute for hashes:

         my %foo : fixed;

And now new keys cannot be inserted into the hash just by assigning to 
their values.  As to how you could put them there... well the ideas that 
come to mind are both a little klunky, but perhaps they should be:

         keys %foo = (keys %foo, $new_key);

         exists $foo{new_key} = 1;      # This has a perverse appeal

Usually, all the keys of the hash would be known and inserted at the time 
one declared the hash, hence

         my %inventory : fixed = (apples => 0, bananas => 27, kumquats => 42);

would be allowed.

</Brainstorming>  So can we keep the option for fixed keys somehow?
--
Peter Scott
Pacific Systems Design Technologies

Reply via email to