Log In  
Log In  

(Hoping to catch you before you finalize 0.1.12)

Similar to how I felt ceil() was missing from the fundamental math toolset in PICO-8, I feel like there are a couple of fundamentals missing from the table toolset.

Would it be reasonable to add these to the built-in table operators?

function ins(table, index, elem)
  local temp = elem
  while temp ~= nil do
    table[index],temp = temp,table[index]
    index = index + 1
  end
  return elem
end

function pop(table)
  local elem = table[#table]
  table[#table] = nil
  return elem
end

-- (and possibly this alias, just for the sake of being symmetrical with pop)
push = add

(Note that I was tempted to suggest an extension to add() where we simply append an optional index, but I've looked at the underlying code you have for add(), and I think the additional code to check for that optional index could slow down existing games too much, so it's probably better to have a new, bespoke ins() function instead.)

With just these two (and a half) additions, it becomes much more intuitive and simple to use tables as stacks, queues, and sets. I think that would be a real boon to both budding and established programmers without really taking the API to a higher level of abstraction.

P#53035 2018-05-26 11:44 ( Edited 2018-05-26 16:33)


[Please log in to post a comment]

X
About | Contact | Updates | Terms of Use
Follow Lexaloffle:        
Generated 2019-03-20 15:06 | 0.131s | 2097k | Q:9