[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Deep __newindex on assignment?
- From: Tom N Harris <telliamed@...>
- Date: Wed, 23 Dec 2009 19:59:39 -0500
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:
container.immutableObject.property = 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.