Skip to content
MTK358 edited this page Dec 9, 2013 · 1 revision

A list of some important features that are missing from the language, some of which I don't know a good solution for:

Support for modules/namespaces/multiple source files

Modules have to be included at compile time, to be able to use types and constants from them. The problem is that if you put their code directly into the output file, the local variables from all the modules can quickly add up to the 200 local variable limit.

The top-level local variables of a module could be stored in a table instead, but this would require it to know about 2 kinds of local variables, and it would break the idea that the top-level is just another function.

Or it could work just like Lua modules where you explicitly create an object containing the module's public variables and functions, and then return it from the top-level function. But then what about types/constants?

Something like the last idea might be best, since it would be nice if modules written in this language could be used seamlessly from Lua code.

Methods, operators, and how to add them to classes/structs

Currently classes simply define a type of table that enforces that all the fields are used and contain the correct type of value. It's really simple to implement and easy to understand that way, but it doesn't support attaching methods to the class.

So what would be a good way to associate methods and operators with a class (and other types, including structs)?

If classes were allowed to contain methods, I'm afraid that would be a duplicate of the functionality of namespaces/modules, and it would have to behave slightly differently to support features like virtual methods.

As for operators, for classes it might make sense to use metamethods. But for structs it would have to work differently, since they're not represented with tables. Also it's common for operators (including the ones built into Lua's primitive types) to support a few different parameter types, and I don't see how to do that without function overloading.

Allowing recursive functions in local variables

Currently you can't create a recursive (or mutually recursive) function in a local variable:

let f = fn (x: float -> float) (
    if (x == 1) (
        1
    ) else (
        x * f(x - 1) # error: f doesn't exist
    )
);

Pre-declaring it doesn't work:

var f;
f = fn <stuff...>;

since it will complain that f doesn't contain a valid value yet when it is used. Also it uses a mutable variable, even though we don't actually want the variable the function is in to be changed later.

Loading code at runtime

One of the main advantages of a scripting language is the ability to load/unload code at runtime. For this to work with static types, it would probably be necessary for the host program to somehow expose some of its types to the loaded program, so the loaded program can use them or make subclasses of them.

Accessing the Lua standard library

Currently there is no access to global variables, an if there was, you can't know what types they contain. One idea can be to have a statement that declares a variable name as having a certain type, without actually creating a local. For example:

extern tonumber: fn(string -> float);
let x = tonumber("123");

Evaluation of constants at compile time

If there is an expression like 1 + 2, turn it into 3. If such a constant value is assigned to an immutable variable, the compiler can remember it and expand it to the value at compile time.

Other possibilities could be to inline functions called from immutable variables (so the compiler knows for sure what function is being called).