>>>>> "DC" == Damian Conway <[EMAIL PROTECTED]> 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  ------  [EMAIL PROTECTED]  -------- 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

Reply via email to