lua-users home
lua-l archive

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


Hi,

On 02/06/10 07:46, Mark Hamburg wrote:
This seems problematic from the standpoint that it won't let you append a table-based object into the target.

this could be done the following way:

    t1 = { "a", "b", "c"}
    t2 = { "x", "y" }

    t1 << { "d", "e" } << "f" << { t2 } << "z"

would result in t1 pointing to { "a", "b", "c", "d", "e", "f", { "x", "y" }, "z" }


But turning to the core request, what you could do instead is something like:

	Stream( "a", "b", "c" ):append( "d", "e" ):append( "f" ):appendElements( t2 ):append( "z" ):extractTable()

This is, of course, much more wordy. So, how about:

	Stream( "a", "b", "c" )( "d", "e" )( "f" ):elements( t2 )( "z" ):extractTable()
there a way
The stream object here implements the __call metamethod as a shorthand for append.

Nice idea. With a construction like this the user has to write something like in the configuration file:

    t1 = List { "a", "b", "c"}
    t2 = List { "x", "y" }

    t1("d", "e")("f")(t2)("z")

or (more wordy, but probably more easily understandable):

    t1:append("d", "e"):append("f"):append(t2):append("z")
to get a list with append functionality
or (I like this one the most so far):

    t1:append{"d", "e"}:append{"f"}:append{t2}:append{"z"}

Is it possible to set a default meta-table for new constructed tables? So that the user can write x = {"a", "b" } in the configuration file and doesn't need to invoke a constrcutor function like "List" to get a list with "append"-functionality?

However I still have the wish that the standard builtin lists (tables) would provide an easy writable standard way for appending, ideally with a new operator like <<.

Best regards,
Oliver