lua-users home
lua-l archive

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


On Thu, Jul 10, 2014 at 10:35 AM, Roberto Waltman <techie@rwaltman.com> 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() ? ]

Well, you could go the LISP route and define compound types using
predicates. freezePredicate(val, pred) would then evaluate pred(val)
on assignment and if it returns false it throws an error.

This scheme allows duck typing, implicitly handling polymorphism as a
result, and allows you to define the predicate based on the operations
you actually care about instead of an overly-strict type.

In my thesis project, this was the scheme I used to evaluate formal
proofs about code.

/s/ Adam