[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Noob question -- On error, exit function and terminate script
- From: Lorenzo Donati <lorenzodonatibz@...>
- Date: Sat, 25 Jun 2011 18:52:04 +0200
On 25/06/2011 18.18, Xavier Wang wrote:
[snip]
Sorry, but I mean, a new version of assert against the baselib one that
_don't_ evaluate the second expression if the first expression is true.
I don't think this is possible without altering deeply the semantics of
the language, since "assert" is a regular function (although implemented
in C), so all its arguments are evaluated before the call.
The possible solutions I see both involve change in the language:
1. turn "assert" into some sort of operator, which its kind of short
circuit evaluation (like "and" and "or").
2. introduce a way of telling Lua to delay the evaluation of an
expression (this has been proposed before IIRC).
I wouldn't want the first (too specific). Maybe the second could have
its applications if done well and it may be general enough to fit Lua's
spirit.
P.S.: note that you can achieve sort of "short circuited" assert writing:
local _ = condition or error( msg )
instead of
assert( condition, msg )
But I don't like that idiom too much. It doesn't save too much typing
compared to:
if not condition then error( msg ) end
and it is less explicit (i.e. unreadable ).
-- Lorenzo
- References:
- Noob question -- On error, exit function and terminate script, marbux
- Re: Noob question -- On error, exit function and terminate script, Rebel Neurofog
- Re: Noob question -- On error, exit function and terminate script, Xavier Wang
- Re: Noob question -- On error, exit function and terminate script, Timothy Hunter
- Re: Noob question -- On error, exit function and terminate script, Xavier Wang