[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Possible language extension: colon-notation in an expression as shorthand for instance-specific method
- From: junk <junk@...>
- Date: Tue, 27 Jan 2009 03:31:03 -0500
I'll say off the bat that i'm very much for this extension. A behavior
complexity issue does, however, come to mind: what do we do with a
method reference once the object is referred to nowhere else but in said
method? As far as I can tell, there are three possible approaches:
simple: treat the method reference exactly as if it were a closure over
the object.
object ownership: methods cease to exist once the object ceases to exist
weak upvalue: a method's reference to the object is weak (just as a weak
tables's entries): once all references to the object disappear, it may
be garbage collected. That is, the garbage collector disregards the
method's object reference when doing its thing.
That is:
local foo = {
bar = function(self, meh)
return self.x .. meh
end,
x = "hey "
}
local foosmethod = foo:bar
print(foosmethod("dude"))
-- >> "hey dude"
foo = nil
print(foosmethod("dude"))
-- simple: >> "hey dude"
-- object ownership: >> nil
-- weak upvalue: >> error: can't index self (a nil value)
- Leo