lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


John Belmonte wrote:
John D. Ramsdell wrote:

Section 2.4 of the 5.1 beta manual includes the following text:

  Because of the lexical scoping rules, local variables can be freely
  accessed by functions defined inside their scope. For instance:

     local counter = 0
     function inc (x)
        counter = counter + x
        return counter
     end

  A local variable used by an inner function is called an upvalue, or
  external local variable, inside the inner function.

First, let me point out that an upvalue is not a type of value, and an
external local variable is not a type of variable.  Confusingly, both
of these terms refer to a type of variable reference.  Since Lua is
now lexically scoped, you can use established terms to describe its
scoping rules.  Let me suggest the following replacement for the last
paragraph.

  In the displayed example, each reference to the variable counter in
  the function inc refers to a local variable that is bound outside
  the inc function's body.  In other words, the variable refers to a
  binding inherited from the scope in which the function is defined.
  A variable reference that refers to such a binding is called
  inherited binding reference.


Roberto, in his talks, freely admits that "upvalue" is not the best
term.  However, do we want to replace every instance of "upvalue" in the
C API with "inherited_binding_reference"?  Please let's not have another
naming and meaning debate on this as in 2001.

I think upvalue is a completely reasonable and clear term. Any terminology used will be obtuse to those new to the language. So it is better to have a short and easy-to-remember. I find "inherited binding reference" to be at least as obtuse as upvalue :-)

--
chris marrin                ,""$,
chris@marrin.com          b`    $                             ,,.
                        mP     b'                            , 1$'
        ,.`           ,b`    ,`                              :$$'
     ,|`             mP    ,`                                       ,mm
   ,b"              b"   ,`            ,mm      m$$    ,m         ,`P$$
  m$`             ,b`  .` ,mm        ,'|$P   ,|"1$`  ,b$P       ,`  :$1
 b$`             ,$: :,`` |$$      ,`   $$` ,|` ,$$,,`"$$     .`    :$|
b$|            _m$`,:`    :$1   ,`     ,$Pm|`    `    :$$,..;"'     |$:
P$b,      _;b$$b$1"       |$$ ,`      ,$$"             ``'          $$
 ```"```'"    `"`         `""`        ""`                          ,P`
"As a general rule,don't solve puzzles that open portals to Hell"'