Shimomura Ikkei |
|
I am thinking to write FunctionalTutorial? :) Here is for a scrap, before make new pages. I did not research exists informations, yet.
Functional programming in Lua, Iterator, Generator, Combinator. and Lazy evaluation by coroutine.
Lua's VM and bytecodes stuff. for example, as implementation of bind2, inject the binding value on the function's code(maybe bytecode, and constants field) instead of changing argument orders by wrapped anonymous function.
-- Lua sais: attempt to call global `fact' (a nil value)
local fact = function(num) if (num > 1) return n*fact(n-1) else return 1 end end
-- this is ok. calls global 'fact'
fact = function(num) if (num > 1) return n*fact(n-1) else return 1 end end
-- but since the closure depend to global, see code below
temp = fact
fact = function (num) return num end
print(temp(10)) -- temp(10) returns 90