Q: Why is a protoobject considered undef?

Carl Mäsak cmasak at gmail.com
Sat Mar 6 12:58:50 UTC 2010

Austin (>), Jonathan (>>), Austin (>>>):
>>> One of the things that has been griping my wagger recently is the fact
>>> that P6protoobject overrides vtable_defined so that protoobjects are always
>>> considered undef.
>>> Is there a good reason for this?
>> Yes; proto-objects are what fill the niche of (typed) undefined values in
>> Perl 6.
> I have no clue what that means. Can you elaborate?

When I do...

  my Int $foo;

...what ends up sitting in the variable $foo is the 'type object' (the
object formerly known as 'protoobject') Int.


  my $foo;

...will store an undefined Any type object in $foo.

The utility of type objects being undefined is that that meshes well
with them being stored in the variables from the beginning. The reason
we want to store type objects in the variables upon declaration is so
that we can do things like

  my Dog $fido .= new;

...which is short for....

  my Dog $fido = Dog.new;

This works exactly because the type object is already in the variable
when the '.=' is called.

// Carl

More information about the parrot-dev mailing list