[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Why does this work?
- From: mauro iazzi <mauro.iazzi@...>
- Date: Fri, 4 Feb 2011 14:23:41 +0100
On 4 February 2011 06:59, Wesley Smith <wesley.hoke@gmail.com> wrote:
>> Yep. "oldprint(), which is a reference to *the original* print()"
>> If none of these functions were called "print" or anything like it, and there weren't languages where print was part of the language and not just a function, I think it'd all be much simpler to understand.
>
> Functions aren't really references but values. If you assign print to
> oldprint, you can't modify oldprint by somehow modifying print.
> Functions are more like numbers. They're first class values.
As I see it a reference can be a first class value, for example tables
are first class values and are references. If a type is immutable like
Lua strings or numbers there is not effective difference, in fact
strings are managed as hashes of a single string copy.
For functions you can do
do
local v = 1
a = function () print(v) end
end
b = a
debug.setupvalue(b, 1, 2)
a()
To me this means that b is a reference to the same function as a. Am I correct?
mauro