[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
**Subject**: **Re: Lua 5.3: functional version of // operator?**
**From**: Miles Bader <miles@...>
**Date**: Mon, 08 Jul 2013 17:19:17 +0900

I wrote in a previous message:
> Then I could just write my own version adaptable local function like:
>
> -- Returns math.floor (a / b)
> --
> local function idiv (a, b)
> if math.idiv then
> return math.idiv (a, b)
> else
> return ifloor (a / b) -- ifloor from above
> end
> end
Of course this is better written as:
local idiv = math.idiv or function(a,b) return ifloor (a / b) end
[In general that's a pattern I tend to like to follow when writing
version-adaptable code using some new function NEW_FUN: define a local
version of NEW_FUN whose value is "NEW_FUN or function (...) ... end".]
-miles
--
Barometer, n. An ingenious instrument which indicates what kind of weather we
are having.