while in C++,Dog skip = new Dog();
is sufficient. But before getting very far, I realized that in Perl we have to call new (or whatever) on everything, too. Ah, but the type is still named only once:Dog skip;
since the variable is not typed.my $skip= Dog->new;
So, if Perl 6 is going to have much stronger compile-time awareness of types, perhaps we should have (to use the familiar Perl 5 syntax)
work properly.my Dog $skip; $skip->bark;
How?
My first thought was to have a typed variable autovivify to a reference of the proper type. So, since bark() is called on undef, it creates one first. Assigning a value to $skip at any point before its used would suppress that behavior.
We already autovivify undef's based on how they are used: $x->[$y] will create an array ref, and we don't hear any cries from users about "well, maybe we wanted it to be undefined to indicate an error!" as in $x= find_my_array(); $x->[$y]; so extending this to members should not be any different conceptually. If you want to allow undef to mean an exception, check for it!
Another idea is to have a typed variable use a default initializer if one is not specified in the statement. So,
would, as part of the "my" processing, call Dog->CREATE or somesuch. If you really wanted my Dog $skip= undef; you could say so.my Dog $skip;
—John
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Fun with Typed Objects 1
by chromatic (Archbishop) on Apr 02, 2003 at 20:43 UTC | |
by Elian (Parson) on Apr 02, 2003 at 20:47 UTC | |
by chromatic (Archbishop) on Apr 02, 2003 at 22:11 UTC | |
by Elian (Parson) on Apr 02, 2003 at 22:13 UTC | |
by simon.proctor (Vicar) on Apr 02, 2003 at 23:19 UTC | |
by Aristotle (Chancellor) on Apr 02, 2003 at 23:26 UTC | |
|
Re: Fun with Typed Objects 1
by erikharrison (Deacon) on Apr 03, 2003 at 06:07 UTC | |
by John M. Dlugosz (Monsignor) on Apr 03, 2003 at 16:08 UTC | |
|
Re: Fun with Typed Objects 1 (topicalize the class)
by Aristotle (Chancellor) on Apr 02, 2003 at 22:16 UTC | |
|
Re: Fun with Typed Objects 1
by dragonchild (Archbishop) on Apr 02, 2003 at 23:51 UTC | |
|
Re: Fun with Typed Objects 1
by jkahn (Friar) on Apr 04, 2003 at 00:12 UTC |