How many times have you written this (well, since this is Perl 6
grammar, you've probably *never* written this, but you get the idea)

    my $foo = %hash{$key} || 'some default';

Annoying, and you've got to scatter this sort of thing all over the
code, even if just to avoid "use of uninitialized value" warnings.

Wouldn't it be nice if there was a way to change the default value of
a hash?  So instead of undef you'll get whatever default you like?

Well, if we go through with making hashes and arrays objects under the
hood (I'm assuming of classes HASH and ARRAY for the purposes of this
discussion) why not just allow:

    %hash.default('some default');

then your code simplifies to:

    my $foo = %hash{$key};

so if $key does not exist you'll get 'some default' instead of undef.

The same thing can be applied to arrays.


PS  Once again, this is Ruby thievery.

-- 

Michael G. Schwern   <[EMAIL PROTECTED]>    http://www.pobox.com/~schwern/
Perl6 Quality Assurance     <[EMAIL PROTECTED]>       Kwalitee Is Job One
Maybe they hooked you up with one of those ass-making magazines.
        -- brian d. foy as misheard by Michael G Schwern

Reply via email to