lua-users home
lua-l archive

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

On 14/02/2012 9:15 PM, Josh Simmons wrote:
Not quite sure what you were saying before about standard container
classes? This is Lua after all, and we have the wondrous table which
manages quite well to subsume the common data structures.

I know the argument is getting old, just to clarify what I mean by standard containers (maybe I mean "collections" if there's a difference): I agree that table handles the mechanism, but it says nothing about the intended use, nor does it's interface limit its use to valid semantics of a specific container type. When I need a LIFO stack, I want to write something that encodes the intent:

s = Stack();
s:push( 1 );
s:push( 2 );

print( s:pop() );
-- 2
print( s:pop() );
-- 1

Other useful container/collection abstractions with reasonably universal semantics in different languages: Queue, Set, Deque, Bag

I won't bore you with a defense of "say what you mean, and make it hard to do what you don't mean." I program in assembly language sometimes too, but when I'm using a scripting language I want abstraction and clarity, not to have to consult my decoder ring "what's the most efficient way to make a table behave like an X".

I'm not so accross the functional side of things so much but map() and filter() might be common examples there.

Anyway as has previously been mentioned if you're serious about this
kinda stuff the best bet would probably be to contribute to penlight
(or that other one). Those of us who don't prefer to add dependencies
are not likely to change our minds and join the cause any time soon
however if penlight continues to become more compelling it may become
something of a de facto standard, which is about the best you could
hope for as far as I can see.

Thanks for the advice. Sounds like I better invest some time learning about these.

Maybe there could be a new entry in the uFAQ, something like:


Q: Where's the library of basic primitives (object system, collections, functional programming primitives, etc)?

A: Lua comes "without batteries". You're expected to roll your own or concoct something from the many and diverse sources out there. If you're looking for something approaching a base library that you can include in your project out of the box you might be interested in checking out penlight [] or stdlib [,]. These are not yet de fecto standards but if you start using them they may become so one day.