Re: RFC 171 (v1) my Dog $spot should call a constructor implicitly

[email protected] (Nathan Wiger)
Newsgroups perl.perl6.language.objects
Message-ID <[email protected]>
> What, then, happens to the following code:
> 
> my Dog $spot;
> if ($age > 12) {
>     $spot = new Doberman();
> } else {
>     $spot = new Corgi();
> }

This is a tricky case that deserves a lot of attention, but not exactly
as written. Imagine this code block:

   my int ($x, $y, $z) = (4, 5, 6);
   if ( $x < $y ) {
      $x = $z;
   }

That seems like simple enough code. But what would that = line do?

   $x = $z;     # $x->STORE($z)

That doesn't make any sense, because $z is an object of class int, and
not a number.

I'd propose the following precedence rules for assignment:

   1. If it's an object being assigned, then the old object
      gets overwritten

   2. If it's a simple value being assigned, then ->STORE
      is called

So for example:

   my int ($x, $y, $z) = (4, 5, 6);
   if ( $x < $y ) {
      $x = $z;       # $x overwritten
      $y = "15";     # $y->STORE(15)
   }

That's off the top of my head. Any input? This point should probably be
addressed in the RFC in one way or another.

-Nate
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.