[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: stack level parameter
- From: David Manura <dm.lua@...>
- Date: Mon, 18 Jan 2010 23:37:41 -0500
On Sat, Jan 9, 2010 at 4:34 PM, Cosmin Apreutesei wrote: 
> I always felt that the stack level parameter in
> setfenv() and error() is just a hack, and I'm happy to see it go away.
I agree with the sentiment: Whenever I add a level parameter to an
error to setfenv/getfenv, it usually feels fragile or potentially
wrong. How does code know the appropriate level parameter of its
caller? For example, the setfenv in package.clean  makes an
implementation assumption of stack levels inside the module function.
It gets more complicated if a function can be called from multiple
levels (e.g. directly or from a wrapper function). There's also a
theoretical dilemma: given a function f, you can't necessary define a
function g that wraps f and behaves identically , though you may if
f exposes a level parameter as an optional argument. Idioms like "f =
assert(io.open(.....))" don't attempt to provide a level parameter,
but you can localize a redefinition of assert to do so.
There are mechanisms, not out-of-the-box, one can devise to deal with
it, and early on I had some experiments with LuaCarp a la Perl Carp
and then , but unfortunately I don't have a solution in mind that I
can with certainty say works really well in practice in all use cases,
tail calls, and code by different authors and that I might suggest for