lua-users home
lua-l archive

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


I think there is no need in const at all.

function ups(nane <const>)
  print("name=",name) -- mistype in argument name
end

ups "name"

I see no real application for const in dynamic language like lua

local t <const> = { x=1 }
t.x=2 -- wtf?

If you need const. It could be emulated in runtime using metatables:
function const(c)
    return setmetatable({},{__index=c,
        __newindex=function(t,n,v) error "const is read only" end
    })
end
local my = const { x=1, y=2, e=2.71, pi=3.14, person=const { name="a", age=1 } }
print(my.pi)

ср, 9 окт. 2019 г. в 21:15, Egor Skriptunoff <egor.skriptunoff@gmail.com>:

>
> On Wed, Oct 9, 2019 at 8:25 PM Pierre Chapuis wrote:
>>
>> > Constant variables help reasoning about the code, but I think the
>> > current syntax is a bit verbose, and may limit its adoption.
>> > A concise syntax that declares the const property may ease its adoption. For
>> > example: `const var = whatever`
>>
>> For what it's worth, I agree with this.
>>
>
>
> +1