[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: "with" statement in Lua?
- From: Dave Bollinger <DBollinger@...>
- Date: Tue, 13 Jul 1999 01:23:38 -0400
Food for thought:
Back in the list archives there are several threads about pointer
aliasing, caching pointers to objects, and such - essentially describing
the functionality of Pascal's "with" statement. I'd like to mention one
additional benefit of such a statement that I haven't yet seen mentioned:
you could sweeten up the var:func() format calls so that they behave more
like the object/method model, giving them direct access to private
"properties". Basically, var:func() would be sugar for:
v.f = function(self, params)
with self do
-- you could now directly access v's contents without prefacing with
"self."
end
end
I haven't delved into the source code, so perhaps I'm a bit naive, but it
seems like it would just involve an additional first pass through the
"with" frame when checking for symbolic names. (in other words, it could
be just syntax for setting up a symbol frame - it needn't literally create
a pointer alias, although I'm sure someone out there would probably be
interested to have that as well)
It could break code, though, if there were naming conflicts between the
table's members and a global variable or parameter. :-( OTOH, it
shouldn't preclude the use of "self.var", that syntax should still be valid
without conflict, even within the with frame for self (where "self" would
not exist, so it should fall back to the next frame and find the formal
parameter (psuedo-parameter)).
Well, I don't know how feasible/desirable it really is, but I thought
I'd toss it out for comments?
Cheers,
Dave