lua-users home
lua-l archive

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


On 01/07/2011 8.42, steve donovan wrote:
On Fri, Jul 1, 2011 at 8:28 AM, Lorenzo Donati
<lorenzodonatibz@interfree.it>  wrote:
it being cheap enough. Reading the objections that occasionally come up to
that idiom, I got the feeling that people don't think it is so cheap
(relatively speaking).

If you have a lot of assertions, then it's true that every such
assertion will generate a new closure. It ain't pretty - whether it is
a problem for a particular application is something that only
profiling can tell.

Here's one little extension which could make life easier in a natural
way, borrowed from Perl:

do_something() or fail "something failed!"

That is, to allow expressions as statements[1].  Because of boolean
operator short-circuiting, anything after 'or' will only be evaluated
when something bad happens.


Yes, I knew that, thanks, and I use some of those idioms from time to time.

On that page it is said that expressions aren't allowed to be statements to avoid ambiguities. Are there elegant way to avoid those ambiguities? Now that 5.2 is about to come out, maybe it may be worth addressing this issue. Or would it be too big a language change?

It would be very elegant to be able to write something like:

do_something() or error "aaargggghhh!"

I once heard something about a "let" statement. Would that solve the problem in a general and elegant way? Maybe something on the lines:


let
  do_something() or error "aaargggghhh!"
end

Am I missing something?


steve d.
[1] http://lua-users.org/wiki/ExpressionsAsStatements