[this might have been missed for those following threads, so reposting]

> Everything in Perl becomes an object, using existing object-syntax. Out of
> plain sight, there would be essentially three base classes: Scalar, List,
> and Hash.

Arg! You beat me to it. :-) This was the next RFC on my list.

> Stricter typing would be imposed (as needed) at the object level
> without the need for new keywords. The Scalar base class would know about a
> fixed number of types, perhaps: ref, int, long, bool, and string.

I would say that this should be done differently. For example, we WANT
people *NOT* to have to use objects if they don't want to (or at least,
not know they're using objects). I think:

   my int $n = 1;

Should simply turn around and do something like this:

   $n->CREATE;
   $n->STORE(1);
   $n->TYPE(int);    # only called if type given

Then, when *used* in a valid int context NUMBER would be called:

   $ans = $n + $x;   # $n->NUMBER->PLUS($x)
   $n = 8.5;         # error, because of $n->TYPE(int)

However, nobody should ever have to call something like $n->NUMBER or
$n->asInt if they don't want to. And they definitely shouldn't have to
know they exist. You should still be able to write a large Perl script
without having to even know Perl supports OO at all.

>  $myScalar->chop;
> 
> or
> 
>  chop $myScalar;

This is good. Simple, but works great.

In fact, I would say the following:

   1. Operator, type, and data handling is done internally by
      ALLCAPS methods (like STORE, NUMBER, etc, see RFC 159)

   2. Functional methods like chop, print, new, and so on are
      simply directly translated via Perl's indirect object
      syntax

So, you can define methods that override the Perl core functions, or
else the core functions are used for you. For example:

   print $FILEHANDLE @data;

This would try $FILEHANDLE->print, or CORE::print if it doesn't exist.

More examples:

   my $name = "Nate";    # $name->STORE("Nate")
   chomp $name;          # $name->chomp || CORE::chomp($name)

That way,

>  $firstName->commit; # or ->rollback

could be written

   commit $firstname   # or rollback $firstname

Take your pick.

> It could work the same way in Perl 6. That would mean that older code could
> very easily get along with newer code, because all of the same operators
> would still be there and they would still work as expected.

Exactly. Perfect. Right on.

-Nate

Reply via email to