lua-users home
lua-l archive

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


More on the forthcoming "in env do ... end" construct...

Three somewhat conflicting thoughts:

1. I wonder whether there's a way to make it friendly toward Ruby-style class construction where basically the class gets modified by functions executed inside a block. Something like the following:

	local c = makeClass()

	in c do
		addField "foo"
		addField "bar"
		function baz( self, yada, yada2 ) end
	end

Except that one would want to fold together the class creation and the environment swap via something like:

	local c

	in c = makeClass() do
		addField "foo"
		addField "bar"
		function baz( self, yada, yada2 ) end
	end

Or "cleaner" (but less Lua-like) still:

	local c = in makeClass() do
		addField "foo"
		addField "bar"
		function baz( self, yada, yada2 ) end
	end

I could also see a case for a metamethod on the value supplied as an environment to be checked as part of the in construct so that the class would not be an environment but could supply one when we needed to use it as such.

2. The above mucks with being able to lint the code since we are actually fine with the global reads of addField and the global set of baz.

3. How much code will get confused by losing the other globals? Will we see a rise in use of package.seeall like constructs? Is something like the PostScript dictionary stack actually more appropriate for non-lexical references?

Mark