[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [NoW] Once more about to-be-closed variables
- From: Chris Smith <space.dandy@...>
- Date: Wed, 3 Jul 2019 10:51:50 +0100
> On 3 Jul 2019, at 08:10, Sean Conner <firstname.lastname@example.org> wrote:
> It was thus said that the Great Egor Skriptunoff once stated:
>> On Wed, Jul 3, 2019 at 9:19 AM Sean Conner <email@example.com> wrote:
>>>> Besides, it would be useful to have non-constant to-be-closed variables
>>> So, what exactly should happen in this code?
>>> local <toclose> f = io.open("a")
>>> local x = f
>>> f = io.open("b") -- should 'a' be closed? or not because of x
>>> f = io.open("c") -- should 'b' be closed?
>> In your example only the last value in variable f would be evicted.
> Is that because of 'x'? Or because that's the end of the scope?
It sounds like it might be better to have __assign and __deassign meta-functions, rather than <toclose>:
f = io.open(‘a’) — __assign called on result of io.open(‘a’)
local x = f — implicit f.__assign()
local y = x — implicit x.__assign()
y = ’something else’ — implicit y.__deassign() followed by (’something else’).__assign()
end — implicit x.__deassign() and y.__deassign() because they are going out of scope.
Chris Smith <firstname.lastname@example.org>