lua-users home
lua-l archive

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


This is a kind of language comparison.
I am working with some strange so-called "post-relational" DMBS as Cache, with uses a script language, the first version of which originated back in '70s. It was called MUMPS then, an abbrieviation where one M stands for Massachusets, and the other - for Medicine (U, P, S - I don't remember ;-). in '80s (or early '90s) the name was shortened to M.
From the beginning it was a script for hierarchical (is this a correct term?) data bases, that is the bases, that store their data organized in trees. In M implementation this mean that you can store data in persistent multidimensional sparse assocative arrays.
Well, this all is somewhat similar to Lua tables in the way that Lua tables are assocative arrays and can be multidimensional (nested).
But, several techniques for using globals (that's how persistent arrays are called in M) rely on the fact that the indices are always sorted, that is traversing goes in some predictable and documented manner: first all numbers in natural order, then all strings in alphabetical order (there are no other type in M beside string, which can be in certain situations interpreted as number (also similar to Lua)). This allows to implement fast searching techinques using inverted tables (values as indices).
If you invert a Lua table you can find any specific value fast, but only if you know the FULL value. If indices were automatically sorted that would also allow partial key searching as well as the easy (and fast) implementation of dictionary structure discussed recently.
Don't consider it a proposal to change the official implementation of Lua tables - it relies on different principal and sorting cannot be easily added to table indices. Besides, there are other issues: how to compare non-string or number values, or maybe even how to compare strings is a question without immediate answer either.
Other thing that would make Lua a real DBMS is making tables persistent somehow.
These thoughts are inspired by some people that are already using Lua as some kind of database (some guy from japan wrote to the list last year that he holds biological data in Lua and the authors of Lua themselves maintain a database of projects in Lua), they still remain thoughts.
 
More on the comparison - this concerns recent discussions of Piton whitespace scoping and continue statement absence :). This is a sample code in M:
 
 ; this one traverses ^G global, prints and counts all indices except "%"
 set CNT=0
 set X="" for I=1:1 set X=$order(^G(X)) quit:X=""  do
 . if X="%" quit 
 . write X,!
 . set CNT=CNT+1
 quit CNT
 
 
well, here the body of for loop consists of the rest of line after the command (set, quit, do) and the dotted lines afterwars. The last quit is already outside the loop. The dots are somethig like piton scoping, aren't they? :)
 
Now, there are three quit commands. The first one breaks the loop, the second acts as a continue, and the last one returns from the routine that containes the code.
No break, no continue, no return - only quit. In fact you cannot immediately break from the dotted line, you have to set flag and quit on the flag when you return to the for-line. So implementing break with continue is IMO easier than vica versa. The M code above is very similar to the variant with local function for the loop body - it really CALLS (with do) the dotted lines, and the second quit _returns_ form that code, being in effect a continue for the loop.