teal-language / tl

The compiler for Teal, a typed dialect of Lua
MIT License
2.04k stars 101 forks source link

[Feature Request] Addition of a type stdarray #588

Closed qEagleStrikerp closed 1 year ago

qEagleStrikerp commented 1 year ago

I think something that would really enhance the Teal experience would be to have an extra type "stdarray" that finally starts indexing at 0 like every other language out there. Normal arrays would stay the way they always have been while one would be able to use specifically declared stdarrays the way they are used to it from other languages. A stdarray would be stored as an array, but an indexing call on a stdarray is always modified to be +1. Example:

local fooarray: {number} = {3, 4, 5, 6}
local bararray: stdarray{number} = {7, 8, 9, 10}

print(fooarray[1]) -- prints "3", just as one would expect
print(bararray[1]) -- internally converts the call to print(bararray[2]) and thus outputs "8"

When transpiling .tl->.lua, the stdarrays themselves stay the same, only their indexing calls have to be increased by 1.

hishamhm commented 1 year ago

like every other language out there

This is not true. No plans to add or change this in Teal.