[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Need for help
- From: "Peter Hill" <corwin@...>
- Date: Mon, 24 Feb 2003 13:31:00 +0800
mnicolet:
> It´s not very orthogonal to use relational operators
> directly, but resort to a method for assignment.
Rici Lake:
> In Lua, assignment is not an operator. I don't find this odd. Maybe
> I'm odd. :)
Not odd :-). It is commonly in the nature of polymorphic languages to make
assignment merely a labelling to some object reference (eg, Smalltalk has
nothing but object references).
However...
Once you allow the "index / newindex" metamethods on a global table the
situation changes. Now assignment IS an operator (some of the time).
> When you say:
> a = 3
> The previous value of "a" is not consulted. Why should it be? That is
> not what assignment means.
You say that the previous value of "a" is not consulted but, with "index /
newindex" metamethods active it MIGHT be! =:-O
> "=" is not sending a message to the previous value of a; it is, if you
> like, sending a message to the global table.
> (Or stashing the value in a local variable.)
True... but that is just a question of one implementation for trapping
variable accesses.
Don't automatically rule out the idea of a "previous value trap". It
certainly _would_ be possible to have a special type which, when assigned to
(or read from), would instead call some metamethod. And it would not be that
inefficient, either. To perform an assignment (regardless of what kind) the
VM must have already located the variable's memory address. It would take
little extra time (and not much code) to check the variable's previous value
for a special 'container' type. And this would work with local variables
too!
Of course the current method works fine for globals & table variables. If
locals were handled too then things would be complete. :-) So would it be
worth adding a special type that traps assignments...? I don't know.
But I don't think we should assume the answer is automatically no.
*cheers*
Peter Hill.
Ki: Contractors... high-paid leeches stealing our work.
Fooker: If you think of them as disposable employees, you'll feel much
better...