3 ms·
It bugs me that the numerical for-loop in Terra has identical syntax to Lua's, but different semantics. Especially since you are encouraged to mix Lua and Terra
by denzquix 13y ago
It bugs me that the numerical for-loop in Terra has identical syntax to Lua's, but different semantics. Especially since you are encouraged to mix Lua and Terra code in the same file. Even something like:
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.
- omaranto 13y agoI couldn't find a description of the Terra for loop in a few minutes of poking through the website and the paper. How is it different from the numeric Lua for loop?
- tekacs 13y agoFrom http://terralang.org/getting-started.html#control_flow http://terralang.org/getting-started.html#control_flow 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, ... end