lua-users home
lua-l archive

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

Asko Kauppi <asko.kauppi <at>> writes:

> It really seems like you're missing something, here.. The whole 
> ideology -should we say 'world'- of Lua is a bit different. Linked 
> lists. I don't see much use for them so just to save your time, the 
> example might be extremely C biased.. Like, you can demo how good an 
> assembler replacement C is by doing 'ax=10; ax++' code. But it never 
> makes sense..

Well, since I've never written a single lua program (yet), perhaps
I am missing something.

On the other hand, my bias is in favor of functional languages like
scheme and ml rather than c, and I find linked lists and other
recursive data types highly useful.  Tables as in lua don't have any
intrinsic idea of order, so if you need to print sorted results, a
list or balanced binary tree is a good alternative -- just as fast
as a hash table to maintain the data, but the sort before the final
output is free.  It's easy to apply higher-order functions to lists,
via map, filter, fold, and zip, and the result can be an easy-to-read
program that is also very fast, if done well.  And something I want
to explore is the use of coroutines to provide haskell-style lazy
lists, but I don't think my lua skills are yet up to that level.

Perhaps you are suggesting that I should implement linked lists in
lua natively rather than in c, and indeed I have seen libraries for
that, but that seems expensive to me compared to the c implementation.
In c, getting the next item in the list is just a pointer reference.
In lua, getting the next item in a list means computing a hash using
arithmetic, indexing into the array that holds the hash table, then
chasing pointers down a linked list, comparing keys until you find
the one you want.  I'll compare timings on the c list library to a
lua list library when I'm finished, but if the lua library beats the
c library, I will have to seriously question my c programming skills
-- and greatly praise Roberto's!

As I said in an earlier post, I am evaluating lua for a specific
project, and lua's combination of easy interface to c, built-in
garbage collection, first-class functions, and procedural-language
syntax are all attractive to me.  My target audience doesn't want to
program in lisp, no matter how much I like it, because they don't
like the parentheses.  They aren't attuned to typeful languages like
sml.  On the other hand, a "simple scripting language" like lua is
familiar, and gives a sophisticated programmer a lot of power in a
small package.  And yes, I realize that lua is far more than a simple
scripting language.

By the way, I am reading code, as fast as I can.  But there are never
enough hours ....  Do you have pointers to any code similar to mine?