Re: Readability question.

"'Martin Eden' via lua-l" <[email protected]> Fri, 5 Jun 2026 19:06:39 +0200
Newsgroups gmane.comp.lang.lua.general
Message-ID <[email protected]>
On 2026-06-05 16:11, Francisco Olarte wrote:
> local function guard(f, a, b)
>     return function(a,b)
>        if a == nil then
>           return b
>        end
>        if b == nil then
>           return a
>        end
>        return f(a,b)
>     end
> end


Hello Francisco,

It still bad for me:

   if a == nil then
      return b
   end
   if b == nil then
      return a
   end

We're testing for one thing and returning other.

I think I would settle at

local function safe_calc(f, a, b)
   return
     function(a, b)
       if not (a and b) then return (a or b) end

       return f(a, b)
     end
end

-- Martin

-- 
You received this message because you are subscribed to the Google Groups "lua-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/lua-l/d3ff81da-fc50-4fc2-9d83-7d4dfaba1d6f%40disroot.org.