On Tuesday, March 25, 2003, at 12:59 PM, Smylers wrote:
Michael Lazzaro writes:
Larry Wall wrote:
We don't have a word for "START" right now.  It's somewhat equivalent
to
    state $foo //= 0

unless $foo gets undefined, I suppose.

Assuming we have a static-like scope called C<state>, one can
definitely see the use of having an assignment variant for "not yet
initialized" or "doesn't yet exist", the proposed spelling of which was
C<::=>.

I'm unconvinced by the need for a cryptic way to distinguish undefined from uninitialized.
<snip>
Or, at least, if we want to make such a distinction here it should be
because we come up with good examples where the distinction is useful,
doing something that couldn't easily be achieved in some other way --
and that that usefulness is thought to outway the additional complexity
of having another assignment operator in the language and having to
distinguish it when teaching or learning Perl.

I suppose my own most common example is a hash representing a cache... it's entirely possible for C<undef> to be calculated and cached, but that doesn't mean the cache entry is invalid and should be recalculated every time -- a nonextant key would mean the cache entry is invalid.


  {
    $cache.{ $key } = $cache.load($key)
        if not exists $cache.{ $key };
    $cache.{ $key };
  }

In my own experiences, code similar to the above is awfully common. An assign-if-not-present form (at least for hashes, but in a magical fairy world, for arrays/params/whatever, too) such as:

$cache.{ $key } __= $cache.load($key);

would be a lot cleaner, and maybe a little faster, since it's testing C<$cache.{ $key }> once instead of -- what, 2.5 or 3 times, I guess, depending on how you count it?

Your mileage may vary, of course -- I must confess I need the undefined vs. noexists distinction all the time, but it's quite possible I code weirdly compared to other people. :-/

MikeL



Reply via email to