lua-users home
lua-l archive

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


On Jan 13, 2010, at 9:53 PM, Ben Kelly wrote:

> When you're done, could you pretty please explain why in-do made it in
> to 5.2, but continue didn't and neither did an error handling mechanism
> (try/catch?) less ugly than pcall? :)

This seems kind of adversarial. Have the authors ever expressed that they think either of these things are critical to the language?

Lexical environments make a real change to the semantics of the language (usefulness of that change aside). "Continue" and exception handling, while both possibly convenient and obviously desired by multiple users, would both be sugar for existing constructs as far as I understand things.

Exception handling in particular is awkward, due to Lua's extremely limited selection of actual types. You could possibly use a construction like 

try errName do
  code
catch errExpr1 do
  handler
catch errExpr2 do
  handler
end

where the various errExpr clauses would be evaluated in order with errName in scope as the value supplied to the triggering use of error(). But if the try block follows the usual conventions for blocks, we would lose the ability to pass back values that we have with pcall.

I don't have a major issue with using pcall for explicit error-catching, especially since they're adding proper arguments to xpcall in this same patch. I don't really see how the above clause would be noticeably better than 

function catch(valid, ...)
	if valid then return ...
	elseif expr1((...)) then
		handler1
	elseif expr2((...)) then
		handler2
	end
end

other than being defined dynamically at the point of use (not an insignificant advantage, but possible to work around).