[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
**Subject**: **Re: The problem with or and false**
**From**: "Alexander Gladysh" <agladysh@...>
**Date**: Thu, 30 Mar 2006 00:08:55 +0400

> > local r = A[k] if r == nil then
> > r = B[k] if r == nil then
> > r = C[k] if r == nil then
> > error("Not found")
> > end
> > end
> > end
> > return r
>
> Is that code so ugly ?
Well, not *so*, but imperfect enough to ask a 'self-educational' question. :)
> You also can try :
> for _,r in pairs{ A[k], B[k], C[k]} do
> return r
> end
> return error("Not found")
It probably can be written even shorter as
local _,r = asser_valid(next { A[k], B[k], C[k] }, "Not found")
return r
(where assert_valid is described in my first letter).
But it involves table creation anyway. Is there a solution without
table creation?
Thanks,
Alexander.