lua-users home
lua-l archive

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


On Thu, Nov 8, 2012 at 12:53 PM, David Given <dg@cowlark.com> wrote:
> It's much easier to think of this as *all* values being passed by
> reference... it's just that numbers, like strings, are immutable and
> cannot be changed. Therefore:
>
> a = a + 1
>
> ...does not *change* the value of the thing a points at. Instead it
> creates a new number with the value (a+1) and then reassigns a to point
> at the new number instead of the old one.

What about:

function f (a)
  a = a + 1
end

function g ()
  a = 1
  f(a)
  -- what is a?
end

-- 
- Patrick Donnelly