lua-users home
lua-l archive

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


On Sat, Mar 17, 2018, at 08:21, Philipp Janda wrote:

> Fortunately, library interfaces can be fixed. I'd suggest passing some 
> form of schema/format into the serialization function (I don't like 
> mutating/annotating my data structures with information that you 
> basically only use for one function call).

That's basically what I've been doing in my own libraries and telling
people to do for years, like in my 5 year old comment on that post I
linked in the Twitter thread [1]. I am just tired of having to tell that to
people and seeing other languages not having that problem. It really
hurts advocacy for Lua.

For what it's worth, I have made two companies adopt Lua and I
have had issues with that both times. I have also written and
contributed to several libraries that use various approaches
around this...

> There's no need to water down Lua's data structures for the sake
> of communicating to the outside world.

Well, communicating with the outside world is a large part of what
some classes of software does, including Web and Mobile applications.

Thankfully there is no need to water down Lua in any way. This can
all be solved by having a default *standard* metatable for sequences
that lets you do this:

    local s = sequence.new(...)
    s[1] = "foo"
    s[2] = "bar"
    print(s:concat()) -- prints "foobar"
    print(sequence.is_sequence(s)) -- prints true

... and of course since they are sequences you could have dequeue
operations on them (push / pop / unshift / etc) which is a nice bonus.

Regarding creating holes, I would prefer if this:

    s[4] = "qux"

resulted in this sequence:

    {"foo", "bar", nil, "qux"}

and its length were 4 thanks to `__len`, but I would also be OK with
creating a hole in a sequence raising an error.

I could easily implement that as a library, but it wouldn't solve my
problem because I would have to tell people "just use sequences
from this library", which would work but I am not legitimate to make
everyone do this. If I could say "just use sequences from the standard
library" it would work.

[1] http://openmymind.net/Lua-JSON-turns-empty-arrays-into-empty-hashes/

-- 
Pierre Chapuis