Please don't convert the result of __lt to a boolean?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Please don't convert the result of __lt to a boolean?

Soni "They/Them" L.
This would be cool:

v = f(x) <- g(y) <- h(z)
v = v() -- v = result of f(x, g(y, h(z)))

(I guess Lua 5.3 can do <<- and stuff but has anyone made a lib for it yet?)

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.


Reply | Threaded
Open this post in threaded view
|

Re: Please don't convert the result of __lt to a boolean?

Luiz Henrique de Figueiredo
> This would be cool:
>
> v = f(x) <- g(y) <- h(z)
> v = v() -- v = result of f(x, g(y, h(z)))

Without the currying, one can this in Lua:

--  Mathematica style

debug.setmetatable(function () end,
        { __idiv = function (a,b) return b(a) end})

_ = 2 // math.sqrt // print

-- Unix pipe style

debug.setmetatable(function () end,
        { __bor = function (a,b) return b(a) end})

_ = 2 | math.sqrt | print


Reply | Threaded
Open this post in threaded view
|

Re: Please don't convert the result of __lt to a boolean?

Dirk Laurie-2
In reply to this post by Soni "They/Them" L.
You can already do this:

debug.setmetatable(1.0, {__lt = function(num,tbl)
  if type(tbl)=='table' then return tbl[1] < num and num < tbl[2]
  else error("attempt to compare number with "..type(tbl))
end end })

if math.pi-3 < {10/71,10/70} then print "Archimedes was right" end




2017-10-15 0:51 GMT+02:00 Soni L. <[hidden email]>:
This would be cool:

v = f(x) <- g(y) <- h(z)
v = v() -- v = result of f(x, g(y, h(z)))

(I guess Lua 5.3 can do <<- and stuff but has anyone made a lib for it yet?)

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.