[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: More about packaging (hopefully not too long)
- From: RLake@...
- Date: Tue, 8 Jun 2004 13:12:06 -0400
> (BTW, why do you need to return `module', if
it came from the outside?)
Convenience, mostly. It makes the code a little shorter.
My feeling is that
OO-like methods should always return self if they
can't think up anything
better to return, because then you can reuse the value
which you often want
Question of style, I suppose. But it reduces the need
to think up names for
local variables you are only going to use once.
On this subject: setmetatable(tab, meta) returns tab
But: setfenv(func, env) does not return func.
It could be argued that setfenv() does not necessarily
a function as its first argument (although I personally
numeric argument to setfenv should be deprecated),
but it still
would be nice to be able to say, eg.
local flag, foo = pcall(setfenv(assert(loadfile(script)),
local flag, foo
local chunk = assert(loadstring(input))
flag, foo = pcall(chunk, bar)
Of course, not everyone will like the style of the
first line, I guess.
But I do :)
PD: No chance of a "let" statement I don't
let chunk = assert(loadstring(input)) in
local flag, foo = pcall(chunk, bar)
Some people probably wouldn't like the odd scoping
of the internal local.