I think this is one of many steps in the right direction. Actually, I have a 
class item defined in my fork as:

class foo
  reserve bar scalar;
  member bar {
    default(bar) = '1';
    set(bar) = {some code};
    get(bar) = {some code};
    ensure(bar) = {some code};
    confirm(bar) = {some code};
  };
};

Part is stolen from C# and some from ruby and and some from some language I 
saw some time ago but don't remember what it was.

On Monday 24 September 2001 10:06 pm, Michael G Schwern wrote:
> 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.

Reply via email to