[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Suggestion: arbitrary constant types
- From: 云风 Cloud Wu <cloudwu@...>
- Date: Tue, 27 Apr 2021 10:14:39 +0800
Gé Weijers <ge@weijers.org> 于2021年4月26日周一 下午11:41写道:
> "local print <const> = print" cannot guarantee that the routine "print" is the standard routine, as another module can override it. I have replaced "print" with a userdata object that had a "__call" metamethod before to redirect "print" output away from the console.
>
> A table that's assigned to a 'const' variable can still be modified as well, only the variable referencing it can't be changed.
>
> An example:
>
> local T <const> = { 1,2,3 }
> some_function(T)
>
> There is no guarantee that T has not changed. I don't think the language will support your idea without substantial changes to the syntax and semantics.
So, I suggest " if it assigns a global var to a const local var, the
var is evaluated during the loading stage rather than running."
It's like adding an import table to the chunk. I don't think the
syntax needs to change (but the semantics will be a little different).
And if you replaced "print" before loading the chunk, it works well, too.
--
http://blog.codingnow.com