lua-users home
lua-l archive

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

Javier Guerra wrote:
> * complex immutable: (mismatch) use a table, copy at specific points
> (either at creation or at any modification)

Which what strings are. And other objects can be implemented with
memoizing and copy-on-write.

But there's no way to do: = foo

Just as there's no subscript operator for strings.
    myString[string.find(myString,' ')] = '-'

Or, for that matter,
    num += 5

So the rule in Lua is that immutable objects just don't work that way.
And if you want to modify such a value, you do it by creating a new object.

    num = num + 5
    myString = string.gsub(myString,' ','-')
    container.immutableObject = mutateObject(container.immutableObject)

Should it be changed so programs are simpler? Maybe. But this way the
parser is simpler.

-- tom