On Mon, 6 Jan 2003, Michael Lazzaro wrote:

> So we're using "is Blah" here as a method of creating an
> already-instantiated object, not just typing a variable(?)  But that,
> in turn, would imply that:
>
>     my Foo $a;     # declares $a as holding objects of type C<Foo>
>     my $a is Foo;  # instantiates $a as a C<Foo>.
>
> Oh dear.  That looks quite wrong.

I'm still not buying the autoinstantiation argument.  All the other
(non-M.L.) threads I have read are requiring
   my $a is Foo = .new;  # or some such...

Both your examples above create the varible $a, but it contains the value
of undef, not an instance of Foo.

OTOH, you can autoinstantiate arrays and hashes like this:

  $a[3]{fum};

which will create an array(ref) in $a containing 3 undefs and a hash(ref)
which contains a single key "fum" with the value of undef.

It would be nice if objects could "inherit" this sort of functionality
from arrays and or hashes.  Or perhaps it's a DIY thing:

  class Foo {

  method do_it ( $x ) {
    $_ //= .new;
    ...
  }

  }

which may not be entirely syntactically correct, but hopefully you get the
idea.  It would be really easy to do if something like a class invariant
existed which ran _before_ each method...

~ John Williams


Reply via email to