On Apr 23, 2004, at 5:42 AM, Dan Sugalski wrote:
At 11:29 PM +0100 4/22/04, Simon Cozens wrote:[EMAIL PROTECTED] (Dan Sugalski) writes:my Joe $foo;
emits the code that, at runtime, finds the class ID of whatever Joe's
in scope, instantiates a new object of that class
Uh, is that right? I don't think that "my" is a constructor, more a typing
declarator.
Since any type potentially has assignment behaviour, it has to be a constructor. For example, if you've got the Joe class set such that assigning to it prints the contents to stderr, this:
my Joe $foo; $foo = 12;
should print 12 to stderr. Can't do that if you've not put at least a minimally constructed thing in the slot.
Another way to look at that would be to say that this:
my Joe $foo; $foo = $a;
is equivalent to either this pseudo-code:
my $foo; assert_type($a, "Joe"); # raise if $a isn't of type Joe $foo = $a;
or this:
my $foo; $foo = new Joe($a);
depending on the semantics that Perl6 wants for this. My point there is that you can get the semantics of "the variable is typed" without having to construct anything as a result of the declaration. In terms if your example, if Perl6 will let you define Joe such that your code prints to stderr, then it might compile down to the equivalent of:
$foo = new Joe(); $foo.assign($a);
The question is really just which semantics Perl6 is intending ("my Joe" is dynamic type checking v. autovivification). Parrot could support any of them--it's just a compilation issue.
(And of course, in the case of "$foo = 12", some checking in each scenario could be done at compile time.)
JEff