lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Thu, May 7, 2015 at 2:57 PM, Brigham Toskin <> wrote:
>>  As long as you can avoid nil, then table.insert() and table.remove()
>> implement a LIFO stack (since both default to the last position).  That
>> is:
>>         push = table.insert
>>         pop  = table.remove
>>   How much more compilicated is your ADT?
> This is actually exactly what I was doing, originally. But I have to check
> for underflow for most operations. And nil is a valid value. [...]

Can't you replace nil with another sentinel value when you're about to
push it into the stack?



Luciano Ramalho
|  Author of Fluent Python (O'Reilly, 2015)
|  Professor em:
|  Twitter: @ramalhoorg