lua-users home
lua-l archive

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


The game of values and names that is taking place here is
not by any means new.  It of course reminds of the well known
passage from `Through the looking glass':

`...The name of the song is called "Haddocks' Eyes".'
`Oh, that's the name of the song, is it?' Alice said, trying to feel
interested.
`No, you don't understand,' the Knight said, looking a little vexed.
`That's what the name is called. The name really is "The Aged
Aged Man".'
`Then I ought to have said "That's what the song is called"?' Alice
corrected herself.
`No, you oughtn't: that's quite another thing! The song is called
"Ways and Means": but that's only what it's called, you know!'
`Well, what is the song, then?' said Alice, who was by this time
completely bewildered.

More to the point, I think it is appropriate to point out that
the problem discussed has in fact little to do with argument
passing itself.  What happens in argument passing is just
the same as what takes place in an ordinary assignment
operation; the relation between x and y in "x = y" is no
different from the relation between a formal parameter and
the corresponding argument passed to it.  This is true in
many languages, Lua included.

Now, there are two popular ways to give meaning to
assignment operations, and they are customarily referred to
as `value semantics' and `reference semantics'.  The former
means copying values, the latter -- copying references.  Lua
happens to be of the latter kind, so ``x = y'' (as well as ``passing
the argument y to the parameter x'') is passing a reference.
Thus there are two references (in x and y) pointing to the same
value.  *If* a reference empowers its holder to mutate the
value being referred to (as is the case with Lua's tables), then
whatever happens to the value referred to by x is also the destiny
of y's value, because these two values are the same.