[% setvar title Rename the C operator %]

This file is part of the Perl 6 Archive

Note: these documents may be out of date. Do not use as reference!

To see what is currently happening visit http://www.perl6.org/

TITLE

Rename the local operator

VERSION

  Maintainer: J. David Blackstone <jdavidb@dfw.net>
  Date: 4 Aug 2000
  Last Modified: 26 Sep 2000
  Mailing List: perl6-language@perl.org
  Number: 19
  Version: 2
  Status: Frozen

ABSTRACT

The local operator of Perl5 and earlier does not do what it claims to and should be renamed.

DESCRIPTION

New Perl programmers are often confused by the behavior of the local operator, especially since a great deal of old educational material exists showing the obsolete practice of using local to create subroutine arguments and local variables.

local does not provide variables that are local to the enclosing scope. Instead it permits what is known as dynamic assignment, the ability to temporarily assign a value to a variable such that the variable's original value will be restored when the current scope is exited. Relying on this mechanism to provide what most people think of as local variables (lexical scoping) can sometimes fail.

local is useful in many cases and should be retained but renamed to reflect its action.

Although the majority of the Perl community is agreed that this operator must be renamed, no consensus emerged as to what the new name should be. The author's favorites are now and dynsave, although I find myself remembering a quote from a Tom Christiansen post about the subject where he went on to discuss the possiblity of "scopetemp"ing a lexical, so that seems catchy, too.

IMPLEMENTATION

Many replacement names have been proposed for local on the perl6-language list, and I am sure there are others that were proposed on p5p in earlier days.

A list of other proposed replacement names includes (but is not limited to, since I certainly have forgotten some):

now

dynsave

pushpop (to reflect the fact that the variable's old value is pushed onto a stack and popped off when the scope containing the use of the operator is exited)

save

clone (not a good idea, in my opinion. I think that means making an exact copy of an object.)

temp

savetemp

tempsave

scopetemp

current

scratchpad

deliver

preserve

saveval

tempval

saverestore

myval

pushval

contain

detach

revalue

let (I'm not sure this was a proposal)

None of these completely satisfies me, at the moment, and there does not appear to be any consensus among the group.

REFERENCES

The perlfunc manpage