Live data from Hacker News

Why Lua?

blog.datamules.com

131–140 of 142 posts

Re: Why Lua?

#131
post #74

Earlier quoted context omitted.

Sorry, I would actually consider myself quite proficient in Python. What I was trying to [unsuccessfully] show was that the underlying mechanics of Python's import mechanism are different then, say, Python's dict or list implementations. Whereas in Lua everything really is just a table. I ran into this (in Python) when I was trying to dynamically import code based on command line arguments and access the functions in…

Hey, thanks for the reply, I do see your point now--I thought you were referring to the usual case of importing modules. It's true that Python modules aren't implemented in terms of dicts or lists and that Python is a larger language than Lua, so I think I completely agree with the point you were making. :) For future reference, I'd implement your dynamic module importer like this: def dynamic_import(name): import im…

Thanks for the pointer! I'll have to keep that in mind.

Re: Why Lua?

#132
post #6

Why isn't Lua more widely used? One reason is a consequence of it being an embedded language. Lua has had 5 major versions which are very incompatible with each other. You're just supposed to stick with the previous version until you upgrade your code. I read all the Lua papers, and they are quite fond of "getting it right" (which is refreshing). They will break things to get it right, whereas other languages stick w…

Not only does it lack a standard library, it lacks a standard metaobject protocol. The fact that a MOP can be implemented in Lua is very nifty, but not having a standard one makes an ecosystem of shared code very difficult.

Re: Why Lua?

#134
post #100

Earlier quoted context omitted.

More good points for both sides. This is not making it easier. I don't need speed as I'm doing offline processing and not worried about lambdas at this point. The unicode is important as I am looking to take Greek and Hebrew text and process it.

You may be better off with Tcl, then, if you don't want to use a library for Unicode.

It's not so much that I don't want to use a library, but more that I would be unable to use much of the core language for the processing and would have to do everything in/with the library and store my text in Unicode-aware holders rather than just strings.

If that's how it ends up, then so be it, but I'll try TCL first and know that I have Lua as a reasonable fall back plan.

Re: Why Lua?

#135
post #93

Earlier quoted context omitted.

Not sure if I'd agree that Guile's FFI bindings are better than LuaJIT's FFI. It's certainly easier to declare a function in LuaJIT - you can take the definition directly from the header file, rather than transcoding it into s-exps. Compare: (define memcpy (let ((this (dynamic-link))) (pointer->procedure '* (dynamic-func "memcpy" this) (list '* '* size_t)))) vs. ffi.cdef [[ void * memcpy ( void * destination, const v…

"As for the speed, there's no reason that a lot of dynamic languages couldn't be as fast as LuaJIT. But none of them are even close. I wish LuaJIT was still up in the computer language shootout. The LuaJIT interpreter (with JIT turned off) is 3x faster than V8 on the PC, and faster than Java on Android. And that's the interpreter - the JITed code is way faster." [Citation Needed] I know of old benchmarks (pre Cranksh…

You can compare v8 to vanilla lua on the computer language shootout benchmarks page, and then compare luajit to lua on the luajit page. V8 has definitely made up some ground, and the luajit interpreter isn't generally faster than v8, but the jit is still way faster on almost all tests. The one area where luajit isn't great is on tests that stress garbage collection, since luajit still uses vanilla lua's GC. I think that's luajit's next area of focus.

Re: Why Lua?

#136
I was first disappointed ... then amazed!

Disapointed because the author's link to the benchmark website lead me to the wrong impression that Lua would be almost 30 times slower than Java 7. Then I googled around and discovered the awesome LuaJit which seems to be able to compete even with C++ in performance.

What I really like is Lua's code density (see samples in the Shootout's benchmarks). Very impressive!

http://shootout.alioth.debian.org/u32/benchmark.php?test=all...

As an old LISPer and Schemer I would like to know if Lua Macros are really as expressive and powerful as Lisp macros. Some people claim this but I am not convinced (I would like to be convinced). The expressive power may be theoretically equivalent but this is also true for C and Assembler :-) The question is: Are Lua macros as easy to handle as Lisp and Scheme macros?

http://stackoverflow.com/questions/323346/what-can-lisp-do-t...

Re: Why Lua?

#137
post #127

Earlier quoted context omitted.

To nitpick your nitpick: in Lua tables are the only composite data structure. Everything you listed is either atomic or opaque (you can hide composite datatypes in userdata, but you can't introspect the values). If you think about it, this is very similar to C where the only composite datatype is a struct (arrays are just sugar on pointer arithmetic). In fact, I think if you wanted to make a scriptable dialect of C,…

Well, since we are nitpicking nitpicks, allow me to nitpick your nitpick of a nitpick: Lua closures are also composite data structures. You can get/set their upvalues via the debug API. Behold: function create() local a,b,c,d,e,f,g,h,i,j; return function() print(a,b,c,d,e,f,g,h,i,j); end end function array_get(f, index) local k,v = debug.getupvalue(f, index); return v; end function array_set(f, index, value) debug.se…

Very well played! If I were the nitpick-y type ;) I'd wonder whether use of the debug library is kosher (esp. in production code), but you are definitely correct. Though, actually, this again correlates very closely with C/Scheme -- You can use an offset from a stack frame pointer to access stack variables in a function scope in C; and upvalues are just closed-over variables a la Scheme closures.

Actually, that's another point in Lua's favor. The mechanism Lua uses for managing closed-over variables is WAY more elegant than, for example, Ruby's mechanism...

Re: Why Lua?

#138

Earlier quoted context omitted.

"We have a technique to reduce the complexity by four orders of magnitude, but unfortunately can't even give a summary of that technique here". I reserve judgment till I see an actual proof of that.

The proof is not far. See their last report here: http://www.vpri.org/pdf/tr2011004_steps11.pdf Also, a good deal of their code is accessible here: http://vpri.org/fonc_wiki/index.php/Installation_Guide As far as I can tell, several things can explain how they fit a whole library in a single book (assuming 50 lines per page, 400 page books, 10.000 books in a library). First, the use of dedicated languages instead of…

Looking at OMeta, it seems to use libcairo and X11. It's hardly fair to _not_ count those lines. Same goes for dedicated languages. If I don't have to count my toolchain, and I'm allowed specialized languages, I can do everything in one line...

   DoAwesomeStuffJustLikeILikeIt();
Don't get me wrong, there's some cool stuff there - but the claims of 4 orders of magnitude seem exaggerated to me.

Re: Why Lua?

#139
post #6

Why isn't Lua more widely used? One reason is a consequence of it being an embedded language. Lua has had 5 major versions which are very incompatible with each other. You're just supposed to stick with the previous version until you upgrade your code. I read all the Lua papers, and they are quite fond of "getting it right" (which is refreshing). They will break things to get it right, whereas other languages stick w…

Not only does it lack a standard library, it lacks a standard metaobject protocol. The fact that a MOP can be implemented in Lua is very nifty, but not having a standard one makes an ecosystem of shared code very difficult.

I don't know whether this is in fact true for the Lua community, but surely this is not necessarily true in general. MOP is not part of CLOS as defined by the standard, but that doesn't seem to create horrible problems (especially with Closer)

Re: Why Lua?

#140

Earlier quoted context omitted.

The proof is not far. See their last report here: http://www.vpri.org/pdf/tr2011004_steps11.pdf Also, a good deal of their code is accessible here: http://vpri.org/fonc_wiki/index.php/Installation_Guide As far as I can tell, several things can explain how they fit a whole library in a single book (assuming 50 lines per page, 400 page books, 10.000 books in a library). First, the use of dedicated languages instead of…

Looking at OMeta, it seems to use libcairo and X11. It's hardly fair to _not_ count those lines. Same goes for dedicated languages. If I don't have to count my toolchain, and I'm allowed specialized languages, I can do everything in one line... DoAwesomeStuffJustLikeILikeIt(); Don't get me wrong, there's some cool stuff there - but the claims of 4 orders of magnitude seem exaggerated to me.

Wait, what? OMeta uses libcairo and X11?! Where did you see that? The only thing I saw it use is a host programming language (Javascript or Python or Ruby…). You may want to count those lines instead. Anyway, remember that they also claim a full language stack in less than 2000 lines. Including a variant of OMeta. Even Lua is 5 times as big. Not counting GCC.

I know it's unbelievable. But other personal experiences make me think they're probably right. I have written equivalent OCaml and C++ code where the C++ version were 5 times larger (both where optimized for clarity). In my day job, I routinely divide substantial portions of C++ code by 2 through light refactoring.

VPRI's miracle doesn't only come from the awesomeness of their ideas. It also comes from the awfulness of current systems. A full desktop in 20.000 lines may not be so small, if you consider that current ones are way too big.

Addendum: I omitted a rather important detail: while the STEPS project aims to build a full desktop system, along with networking, publishing, messaging, and programming capabilities, it makes no attempt be compatible with anything (except the hardware on which it has to run). It doesn't do HTTP nor HTML, for instance.

Post reply on HN