Message from discussion
is static?
Newsgroups: perl.perl6.language
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!nntp.perl.org
Return-Path: <u...@stemsystems.com>
Mailing-List: contact perl6-language-h...@perl.org; run by ezmlm
Delivered-To: mailing list perl6-langu...@perl.org
Delivered-To: perl6-langu...@perl.org
To: Damian Conway <dam...@conway.org>
Cc: Larry Wall <la...@wall.org>, perl6-langu...@perl.org
Subject: Re: is static?
References: <001201c2eb58$1373c9c0$cf6e1918@carolina.rr.com> <15988.34979.963066.105078@gargle.gargle.HOWL> <20030317183235.GA23045@wall.org> <3E768A47.5020504@conway.org>
Date: Mon, 17 Mar 2003 22:03:29 -0500
In-Reply-To: <3E768A47.5020504@conway.org> (Damian Conway's message of "Tue, 18 Mar 2003 13:53:59 +1100")
Message-ID: <x7d6kpz88u.fsf@mail.sysarch.com>
Lines: 63
User-Agent: Gnus/5.090015 (Oort Gnus v0.15) Emacs/21.2 (sparc-sun-solaris2.8)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-SMTPD: qpsmtpd/0.21-dev, http://develooper.com/code/qpsmtpd/
X-Spam-Check-By: one.develooper.com
X-Spam-Status: No, hits=-0.1 required=7.0 tests=CARRIAGE_RETURNS,IN_REP_TO,RCVD_IN_MULTIHOP_DSBL,RCVD_IN_UNCONFIRMED_DSBL,REFERENCES,SPAM_PHRASE_00_01,USER_AGENT,USER_AGENT_GNUS_UA version=2.44
X-SMTPD: qpsmtpd/0.20, http://develooper.com/code/qpsmtpd/
Approved: n...@nntp.perl.org
From: u...@stemsystems.com (Uri Guttman)
>>>>> "DC" == Damian Conway <dam...@conway.org> writes:
DC> Larry wrote:
>> : sub foo() {
>> : has $s //= 0; : $s ++ ;
>> : }
>> : : print foo, foo, foo;
DC> Futhermore, this approach opens another vermiferous can. I would argue
DC> that C<//=> is the wrong way to initialize it, since that effectively
DC> prevents C<undef> values from being used with such variables.
so don't put the //= 0 there and it will be undef. in fact why would the
// be needed if you can just do:
has $s = 0 ;
also i think has implies a class level attribute here which is not the
same in my mind as
my $s is static = 0 ;
which is private to the sub (and any nested subs).
DC> Hence, I would argue, one ought to simply mark it with a trait:
my use of is static was a trait. i chose 'is' for that reason. it was a
compile time trait that the var was to be allocated (and optionally
initialized) only once and it would be not on the stack and would keep
its value between calls to foo().
DC> sub foo() {
DC> my $s is retained = 0;
DC> $s++;
DC> }
DC> Other possible trait names:
DC> is kept
DC> is preserved
DC> is permanent
DC> is reused
DC> is saved
DC> is stored
DC> is restored
DC> is irrepressible
DC> Yes, the names are all considerably longer than a C<has> declarator,
DC> but I see that as a bonus. Persistent behaviour by a lexical is
DC> unusually enough that it ought to be loudly and clearly marked.
DC> Oh, and note that I very deliberately did not suggest C<is static>!
but that is a good name IMO. $s is static vs dynamic (on the stack). the
other overloaded meanings of static from c/c++ are baggage we can drop.
uri
--
Uri Guttman ------ u...@stemsystems.com -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Damian Conway Perl Classes - January 2003 -- http://www.stemsystems.com/class