lua-users home
lua-l archive

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


On Thu, Jul 10, 2014 at 1:54 PM, Thiago L. <fakedme@gmail.com> wrote:
>
> On 10/07/14 02:35 PM, Roberto Waltman wrote:
>>
>>
>> On 07/10/2014 07:04, GrayFace wrote:
>>>
>>> Lua desperately needs a form of optional static typing, not those gotos
>>> with ugly syntax.
>>
>>
>> Since I used Lua for the first time, (~ 7 years ago,) my "would be nice
>> if" list includes a "freezeType(val)" function that would constrain future
>> assignments to val to its current type. Of course, if the type is table,
>> that is a very weak limitation.
>>
>> [ What about a freezeValue() ? ]
>>
> whatever[key]=value
> setmetatable(whatever,{__index={[key]=value},__newindex=function(t,k,v) if
> getmetatable(t).__index[k] then error() end rawset(t,k,v) end})
> whatever[key] = nil

The biggest thing on my list of wants for Lua is, I wish weak
references in tables could be generationally-collected.  So when you
memoize a function and keep its results in a table, you wouldn't have
to write the logic yourself to only keep the most recently used
results.  the GC would do it for you -- I just couldn't figure out a
way to bless a table with weak keys or values (or both) to opt in to
generational collection, but I still think the idea is awesome.