Terra: A low-level counterpart to Lua
terralang.org
terralang.org
https://www.hnsearch.com/search#request/submissions&q=terra+...
Still, it's interesting and relevant, and I hadn't seen it before, so thanks for posting.
for i = 0, < 10 do --[[ ... ]] end
...and throwing a compile error if you omit the <, though arguably ugly and weird, would still have been preferable I think.
Terra also includes for loop. This example counts from 0 up to but not including 10:
for i = 0,10 do
C.printf("%d\n",i)
end
This is different from Lua’s behavior (which is inclusive of 10) since Terra uses 0-based indexing and pointer arithmetic in contrast with Lua’s 1-based indexing. Ideally, Lua and Terra would use the same indexing rules. However, Terra code needs to frequently do pointer arithmetic and interface with C code both of which are cumbersome with 1-based indexing. Alternatively, patching Lua to make it 0-based would make the flavor of Lua bundled with Terra incompatible with existing Lua code.
Lua also has a for loop that operates using iterators. This is not yet implemented (NYI) in Terra, but a version will be added eventually.
The loop may also specify an option step parameter:
for i = 0,10,2 do
c.printf("%d\n",i) --0, 2, 4, ...
endI think this is a good example of what the llvm code generation libraries enable (as opposed to gcc).
(In addition to being a pretty cool project on it's own!)
In the meantime, I'm watching Terra.
Personally, through, Lua is sugary enough for me, particularly if I use Penlight.
But what I have in mind is just a little different. I want explicit type declaration, and I don't want to type "->".
So, something more of this character:
void chant( string thing, int times ):
for int i in range( times ):
print( "$thing $i" )
Also, I'd like to write the compiler in Terra.I'm pretty fond of Lua just the way it is as well, but I'm picky and stubborn and idealistic. I keep telling myself not to think about it, but I can't help but daydream about writing a language. I think Terra presents a fair opportunity to get it out of my system.