Live data from Hacker News

Why Lua?

blog.datamules.com

81–90 of 142 posts

Re: Why Lua?

#81

Earlier quoted context omitted.

This sounds very much like Python's __getattribute__ [0] method. Is there a difference I'm not understanding? [0] http://docs.python.org/reference/datamodel.html#object.__get...

I'm not that familiar with Python, but can you use __getattribute__ to provide methods as well? Using __index is the way you typically implement inheritance in Lua.

yes.

    >>> class A(object):
    ...   def __getattribute__(self, key):
    ...     try: return object.__getattribute__(self, key)
    ...     except AttributeError: return lambda: 12
    ...
    >>> a = A()
    >>> a.asdf
     at 0x7fbb8fb6f848>
    >>> a.asdf()
    12

Re: Why Lua?

#82
post #79

Earlier quoted context omitted.

Shows how long it's been since I last used Tcl! Still, Tcl's anonymous functions aren't quite what many people consider to be lambdas: % set inc {x {expr $x + 1}} % apply $inc 1 2 % apply $inc 1 2 % $inc 1 invalid command name "x {expr $x + 1}" % inc 1 1 This works fine with `apply`, but if you treat it like a normal function, it does some strange things. Conversely, functions that are defined with `proc` aren't comp…

I can't speak to what most people expect from lambdas; I force myself use Tcl's [apply] occasionally just to try slightly different paradigms, so I appreciate your commentary. One thing to note though, your final [inc 1] has nothing to do w/ $inc. In the interactive REPL (which I'm assuming you used), Tcl will (by default) essentially autocomplete commands if it can, and [inc] completed to [incr], which is "increment…

I didn't know that tclsh autocompletes commands; that's pretty neat. In this case, it looks like [incr 1] is incrementing a variable called 1, and appears to start from zero if the variable isn't initialized.

I find Tcl's command model interesting because it leads to a very tiny semantics. A few years ago I spent a lot of time thinking about how it could be extended to have lambdas, and I couldn't come up with a way that wouldn't break the command model in some way or another. They aren't something Tcl needs to have, I just thought it'd be convenient. (Tcl's evaluation model allows you to simulate higher-order procs, which, along with `apply`, covers many use cases of lambda).

Re: Why Lua?

#83

Earlier quoted context omitted.

When my main language was C, I used to feel that dynamically mutating or self-modifying data structures were somewhere between black magic and heresy. I have found that being able to place arbitrary constraints on the way my programs store things in (seemingly simple) data structures has been very, very powerful.

metatables don't involve dynamically mutating / self-modifying data structures. They're more equivalent to javascript's prototype, except slightly more general-purpose. You can easily use them to build an OO system, among other things.

Yes, I agree that Lua metatables / metamethods look and work a lot like JavaScript's prototype property.

I should have been more specific when mentioning self-modifying data structures and Lua metatables in the same post.

Consider: it is possible for a table to be its own metatable, and for that table to contain (pointers to) some functions that govern storing data in the table. For the non-Lua reader, these tied-to-an-event-on-a-table functions are called table-access metamethods [0], and they allow for some dangerous shenanigans.

If these particular metamethods knew how to add to, rearrange, or delete from the set of callable functions already stored in the table, the subsequent layout and contents of the table could change in a non-deterministic way.

Something that looks like a simple assignment/update (__newindex/__index, insert/update, or your favorite pair of terms)

  t[0] = "command phrase"
     x = t[0]
could trigger wholesale reorganization of the table, including deletion or addition of new metamethods.

[0] "Programming in Lua 1ed (Chapter 13. Metatables and Metamethods, 13.4 – Table-Access Metamethods)" http://www.lua.org/pil/13.4.html

edit: incomplete example

Re: Why Lua?

#84
post #79

Earlier quoted context omitted.

Shows how long it's been since I last used Tcl! Still, Tcl's anonymous functions aren't quite what many people consider to be lambdas: % set inc {x {expr $x + 1}} % apply $inc 1 2 % apply $inc 1 2 % $inc 1 invalid command name "x {expr $x + 1}" % inc 1 1 This works fine with `apply`, but if you treat it like a normal function, it does some strange things. Conversely, functions that are defined with `proc` aren't comp…

I can't speak to what most people expect from lambdas; I force myself use Tcl's [apply] occasionally just to try slightly different paradigms, so I appreciate your commentary. One thing to note though, your final [inc 1] has nothing to do w/ $inc. In the interactive REPL (which I'm assuming you used), Tcl will (by default) essentially autocomplete commands if it can, and [inc] completed to [incr], which is "increment…

To my point of no keywords, and touching on the interesting model @groovy2shoes is talking about here[1]:

  $ tclsh

  % set a set
  set
  % puts $a
  set
  % $a b 9
  9
  % set b
  9
  % set set set
  set
  % $set set
  set
  % rename set foo
  % foo set
  set
  % foo a
  set
  % foo a 9
  9
  % puts $a
  9
  %
[1] http://news.ycombinator.com/item?id=3536419

[edit: formatting]

Re: Why Lua?

#85
post #30

To echo chubot: Why isn't Lua more widely used? * It lacks an easy-to-use symbolic debugger. * It lacks a first-rate IDE. * It lacks a standard way for people coming from OO/Java to define objects and interfaces. * It lacks a GUI toolkit. * It has a great set of manuals. It lacks an O'Reilly book with a woodcut animal on the cover. * Arrays indexes start at 1. Except for the last item, these are all relatively small…

> * It lacks an easy-to-use symbolic debugger. > * It lacks a first-rate IDE. This is changing http://eclipse.org/koneki/ldt/ ; > * Array indexes start at 1. This sounds dangerously similar to "I can't use Python because it has significant whitespaces". Developers might like or dislike it, but if you can't get over _that_, you either lack important cognitive abilities, or you're suffering from a very serious case of…

> > * Array indexes start at 1.

> [...]

> However, I'll admit it's a bit irritating when you're frantically switching between C and Lua.

I would imagine it can be confusing when swapping between C and Lua, but when working in a Lua-only environment (e.g. writing addons for World of Warcraft) it very quickly becomes a non-issue.

Re: Why Lua?

#86

Earlier quoted context omitted.

There are several server side Lua options with coroutines.

Could you name a few, alls I see are kepler based ones..

I work at Zipline Games and we're building out a server side hosted lua system. We're targeting it at game developers, but there is nothing game specific about the lua handlers you can write. You can find out more about it at http://getmoai.com

If you don't want a hosted solution you can look into mongrel2 and tir http://tir.mongrel2.org/

Re: Why Lua?

#88
post #79

Earlier quoted context omitted.

I can't speak to what most people expect from lambdas; I force myself use Tcl's [apply] occasionally just to try slightly different paradigms, so I appreciate your commentary. One thing to note though, your final [inc 1] has nothing to do w/ $inc. In the interactive REPL (which I'm assuming you used), Tcl will (by default) essentially autocomplete commands if it can, and [inc] completed to [incr], which is "increment…

I didn't know that tclsh autocompletes commands; that's pretty neat. In this case, it looks like [incr 1] is incrementing a variable called 1, and appears to start from zero if the variable isn't initialized. I find Tcl's command model interesting because it leads to a very tiny semantics. A few years ago I spent a lot of time thinking about how it could be extended to have lambdas, and I couldn't come up with a way…

Ya -- interactive tclsh has a few creature-features. The autocomplete we're discussing, automatic fall-through to exec as if via sh(1), command history, history editing, and perhaps more I'm forgetting.

  kamloops$ tclsh8.6
  % info commands up*
  update uplevel upvar
  % uptime
   7:17PM  up 1 hr, 7 users, load averages: 0.06, 0.12, 0.17
  % ls fu
  ls: fu: No such file or directory
  child process exited abnormally
  % ls -ld fu 
  ls: fu: No such file or directory
  child process exited abnormally
  % ^fu^foo
  ls -ld foo
  -rwxr-xr-x  1 joe  users  7300 Mar 23  2011 foo
  % history 
     1  info commands up*
     2  uptime
     3  ls fu
     4  ls -ld fu
     5  ls -ld foo
     6  history
  % !2
  uptime
   7:20PM  up  1:03, 7 users, load averages: 0.13, 0.12, 0.16

Re: Why Lua?

#89
post #88

Earlier quoted context omitted.

I didn't know that tclsh autocompletes commands; that's pretty neat. In this case, it looks like [incr 1] is incrementing a variable called 1, and appears to start from zero if the variable isn't initialized. I find Tcl's command model interesting because it leads to a very tiny semantics. A few years ago I spent a lot of time thinking about how it could be extended to have lambdas, and I couldn't come up with a way…

Ya -- interactive tclsh has a few creature-features. The autocomplete we're discussing, automatic fall-through to exec as if via sh(1), command history, history editing, and perhaps more I'm forgetting. kamloops$ tclsh8.6 % info commands up* update uplevel upvar % uptime 7:17PM up 1 hr, 7 users, load averages: 0.06, 0.12, 0.17 % ls fu ls: fu: No such file or directory child process exited abnormally % ls -ld fu ls: f…

> automatic fall-through to exec as if via sh(1)

That explains why X11.app launched that one time I forgot a `$` before my `x`...

Re: Why Lua?

#90

Not criicizing lua, but worth comparing to guile. > Integration with C (and C++ for that matter) Guile does it better. You can use shared memory threads in guile without any penalty. Atmost you have to allow for the garbage collector to run when inside FFI functions. But that is a small price to pay in case you need to use multiple parallel-concurrent threads with a single heap. Guile was built with FFI in mind and h…

With a small patch to add coroutine.clone[1], you can have continuations in Lua[2].

[1] http://lua-users.org/lists/lua-l/2006-01/msg00652.html

[2] https://github.com/torus/lua-call-cc

Post reply on HN