Speaking briefly, I would like it if Perl 6 provided a way for a class (or role, or meta-class, etc) to declare that all variables declared to be of that type are automatically/implicitly set to a particular value at declaration time, so that they are not undefined if the programmer using them doesn't explicitly set a value.

Here are usage examples:

  my NumType $foo; # implicitly contains a defined NumType of value 0
  my StrType $bar; # implicitly contains a defined StrType of value ''

Sure, the user could say ".= new()" or such, but I wanted a fallback if they didn't do that.

Then when they come to just use that not explicitly set variable, it contains some type-defined reasonable default value.

Presumably, the object meta-model would have an appropriate function defined for use at that time, which returns undef by default, and this function is what individual classes can override.

Part way through writing this, I had a brief chat on #perl6 with stevan (and apparently the meta-model is still quite in flux) and he said my question was related to Larry's "class but undef" idea, and that Larry should talk more about the subject.

Thank you. -- Darren Duncan

Reply via email to