Herly, I recommend that you buy Programming in Lua (Fourth Edition) by Roberto Ierusalimschy, if you do not yet have it. You won't regret it. Chapter 22 (The Environment) is what you need. All variables in Lua are either keys in a table or are local to a chunk. So-called global variables are...
Thanks. I thought it was something like that. My personal preference for the unsugared syntax is because the sugar seems to me to be unnecessarily apologetic. It is just because many Lua users come from a first-order background, rather than a higher-order one, that they should perhaps be...
The Y combinator as given above provides a means of doing this. Its crucial property is that Y(f) reduces to f(Y(f)) - the fixed-point property. Using it makes it possible to rewrite definitions without explicit recursion. Thus, in the remarks above, Y(F) does the same as fact. You get F from...
OK. The factorial function imay be given by
(function (g) return (
function (f) f = g ( function (x) return (f (x)) end)
return f end) end ) ( function (h) return function (n)
return (n<2) and n or n*h(n-1) end end)There are no named functions here. But naming is only a way of making...
It looks like my first suggestion does not work. I think what you are asking for is how to do a calculation likefunction fact (n)
return (n<2) and n or n*fact(n-1) end
print (fact(4)) --> 24without using a recursive function definition. What about this?local Y = function (g)
return (function...
You cannot. In Lua 5.2 loadstring is replaced by load which can take an environment as its fourth argument, but that will not help you with using a local variable.
Forgive me, but I find this very opaque. Finish what? To do the same as what? Please remember that us mortals are not telepathic. I use an operating system in which the window manager is the task-manager and user-applications have to co-operate with it if they want to use the graphical user...
What about this?
function (xmid, im)
local top_margin = 1
for y = 0, xhalf do
local c1 = im.get_pixel (xmid, y)
if c1.alpha < 20 then top_margin = y + 1 end -- if
end -- for
return top_margin
end -- function
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.