develooper Front page | perl.perl6.language.objects | Postings from August 2000

Re: RFC for $ME class variable (was Re: RFC 124 (v1) Sort order for any hash)

From:
merlyn
Date:
August 19, 2000 09:32
Subject:
Re: RFC for $ME class variable (was Re: RFC 124 (v1) Sort order for any hash)
Message ID:
m1zom9jjnx.fsf@halfdome.holdit.com
>>>>> "John" == John Siracusa <siracusa@mindspring.com> writes:

John> I don't like $ME either, but my alternative is probably even more
John> blasphemous: use $self.  "It usurps a variable name that has been legal for
John> customer use in prior Perls!" you re-exclaim.  Not if it only appears in a
John> new-to-Perl-6 construct like:

John> method get_polite_age(<neat stuff could go here>)
John> {
John>   return ($self->age >= 40) ? 39 : $self->age;
John> }

Well, that I could support.  Although having the p52p6 translator
recognize which subs should really be methods might be a bit messy,
and then it'd have to recognize any uses of $self for a proper $self,
and not shift something into that, or whatever. :)
<voice character="Dr. Smith">The pain!  The pain!</voice>

John> But wait, it gets worse:  I'd even be happy with the bareword "self"

John> method get_polite_age(<neat stuff could go here>)
John> {
John>   return (self->age >= 40) ? 39 : self->age;
John> }

John> I know, I'm obviously crazy as a loon.  You may escort me to Perl culture
John> prison now... ;)

I'll have an adjacent cell.  I actually like that *better* than $self.
Let's not stop there though.  Perhaps we need "self" and "super" and
"thisContext".  Only half joking... this would solve a lot of the
hacking issues.  self could be a "die" if we weren't called as a
method, and then we wouldn't need to have a separate "method" type.
Oooh.  Getting better all the time!  Or maybe just return undef, and
let the method call fail on the undef, or we could check it ahead:

        if (my $me = self) {
          $me->do_this
        } else {
          $CGI::Q->do_this
        }

To steal from CGI.pm's problem.  Or, if it threw an exception:

        try {
          self->do_this
        } error {
          $CGI::Q->do_this
        }

or whatever the syntax is this week.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About