[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: A thought about <const>
- From: David Heiko Kolf <david@...>
- Date: Tue, 11 Jun 2019 20:10:21 +0200
Coda Highland wrote:
> However, non-assignable variables are pretty useful. There are some
> compiler optimizations that can happen when you know a variable is
> read-only, and of course asserting that something is read-only can help
> avoid programming mistakes.
This point currently raises some questions for me. I appreciate const
statements in an API, as they clearly document that a variable or a
parameter will not be changed.
However, in Lua locals are (as the name says) already limited to a
single file so they are not part of an API and any compiler looking at
the file could already see that it is only assigned once even without a
const statement.
So I get the impression that the proposed const statement adds very little.
I would actually prefer if the const statement is not added to Lua, as
the use cases of const and toclose would at least for me be completely
different:
E.g. I like to copy multiple dependency functions to constants at the
beginning of my libraries:
local strsub, strrep, gmatch, strformat =
string.sub, string.rep, string.gmatch, string.format
local _ENV = nil
But I need a non-scoped error message:
local <toclose> f, err = io.open("demo.txt")
Or do I miss some significant use case of a local const statement in Lua?
Best regards,
David