lua-users home
lua-l archive

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




On May 22, 2019, at 10:59 AM, lua-l-request@lists.lua.org wrote:

Message: 3
Date: Wed, 22 May 2019 10:11:41 -0300
From: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Subject: Re: Thoughts on new syntax for toclose
To: Lua mailing list <lua-l@lists.lua.org>
Message-ID: <20190522131141.GF13251@arraial.inf.puc-rio.br" style="font-family: Courier; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">20190522131141.GF13251@arraial.inf.puc-rio.br>
Content-Type: text/plain; charset=utf-8

 There's also <const> as well.  But you can't combine them:

Sources say you needn't:

https://github.com/lua/lua/blob/d9f40e3f6fb61650240c47d548bee69b24b07859/lparser.c#L1679

The manual also says that:

 3.3.8 – To-be-closed Variables
 [...]
 A to-be-closed variable behaves like a constant local variable, [...]

-- Roberto

Doesn't that make <const> redundant (and somewhat confusing)?

Dropping <const> would then require setting the __close metamethod to nil to get the desired behavior, which would quickly get ugly - but isn't that also an issue for <toclose> variables?

So letting my imagination run free, how about these for inspiration:
local foo <const> = 3
local foo <{__close=myclosefoo}> = some_expression
local foo <{__close=myclosefoo, __tostring=prettyprint}> = some_table

In other words, call setmetatable from the declaration, which would convert the two separate statements needed now into one, which seems cleaner to me.