On Apr 23, 2004, at 8:54 AM, Larry Wall wrote:


On Fri, Apr 23, 2004 at 08:42:28AM -0400, Dan Sugalski wrote:

: 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.

Yes. More typically, the type of the value needs to be checked
at assignment time, if we can't intuit its safety at compile time.
From an abstract point of view the constructor in question isn't so much
constructing a Joe object as a container for a Joe object--though, of
course, optimizations happen. So in the Parrot engine the containers
and containees are a bit more incestuous than it would appear from
the abstract language level. That's okay.

So what does "$foo = 12" in that context actually mean in Perl6? I _think_ there are three possibilities for what it could mean:


1) Store 12 in the $foo variable. Since 12 isn't a Joe, that's an error.
2) Attempt to convert 12 to a Joe, and store that. If (and only if) that can't be done, it's an error.
3) Take any existing Joe in $foo, and call some setter method, passing 12 as a parameter to that method. (This one has implications for what happens if $foo doesn't yet hold a Joe v. if it does.)


It sounded like you were starting to say (1), but then that wouldn't ever cause 12 to be printed to stderr (since no assignment operator would be called).

JEff



Reply via email to