At 3:02 PM +0800 2/6/06, Audrey Tang wrote:
On 2/6/06, Darren Duncan <[EMAIL PROTECTED]> wrote:
 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.

If so, your use case can be satisfied by declaring that ::NumType (the
class object)
numifies to 0, and ::StrType stringifies to "", via the coerce<as> form.

That could be fine for some situations, but I was looking for a more generic solution for:

  my FooType $foo; # acts like we said .= new()

Essentially, that $foo is like or is a fully instantiated object on which you can call arbitrary FooType object methods as if someone set it with new(), but where in fact the user never did this.

The coercing solution won't work if the types of use are not coersions to simple data types like strings or numbers.

Thank you. -- Darren Duncan

Reply via email to