[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Static typing in Lua
- From: Gavin Wraith <gavin@...>
- Date: Thu, 27 Jul 2006 07:56:12 +0100
In message
<89d273ba0607262003x2f2ffd4el98b7bccc715ccaf5@mail.gmail.com> you wrote:
> I'm trying to figure if it would be possible to add static (compile
> time) typing to Lua easily, either by adding a library or by modifying
> the language parser itself. Has anyone already looked into it and
> found something interesting ? Is the Lua core designed to allow such
> modification ? An alternative would be to add a kind of preprocessor
> to Lua. I read somewhere that there is a Lua parser written in Lua.
> Would it be capable of doing such preprocessing ?
>
> Static typing enforce some level of code correcteness and that's the
> aspect of it that I'm looking for.
I have been thinking about this a little. The function
the = function (s,x)
if assert(type(x) == s) then return x end
end
which is useful for superficial typechecking, suggests the use
of identity functions with side effects which create type
information.
I think nil has to have every type.
As to what constitutes a type perhaps one should go through
all the code in the VM looking for branching decisions, and
make an abstract definition of "a type relevant to a given
VM operation" as something that resolves branches for that
op. Or am I being silly? This is a notion analyzed from the
point of view of the cpu rather than the user, so to speak,
and so may not be quite what you mean.
--
Gavin Wraith (gavin@wra1th.plus.com)
Home page: http://www.wra1th.plus.com/