Skip to content

I want to add table.isarray, but is my understanding of how it works correct? #457

Answered by zeux
EtiTheSpirit asked this question in Q&A
Discussion options

You must be logged in to vote

While we often call some types of tables "arrays", I am not sure there's a reasonable formal distinction you can draw and if it is, what it would be, between arrays and non-arrays.

For example, assuming you implemented isarray as "hash part is dummynode", you'd get:

local t = { [1] = 1 } -- true
local t = { [2] = 1 } -- false
local t = { [2] = 1 } t[1] = 1 -- currently false I think, will be true in the future
local t = { [math.abs(1)] = 1 } -- currently false, will be true in the future
local t = { [1] = 1, n = 2 } -- false
local t = { [1] = 1, n = 2 } t.n = nil -- also false!

I don't think it's reasonable to specify queries in terms of internal behavior, but what would the meaningful e…

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by EtiTheSpirit
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants