Created
September 6, 2017 19:30
-
-
Save hiredman/5b98146e4f1fd37c3d1b8c2db9810bd4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function map(func, array) | |
local new_array = {} | |
for i,v in ipairs(array) do | |
new_array[i] = func(v) | |
end | |
return new_array | |
end | |
function fix(u) | |
return u(u) | |
end | |
function y_star(...) | |
local l={...} | |
return fix( | |
function (p) | |
return map( | |
function (li) | |
return (function (...) | |
return li(unpack(p(p)))(unpack({...})) | |
end) | |
end, | |
l) | |
end) | |
end | |
function odd_maker(odd, even) | |
return function (n) | |
return not(even(n)) | |
end | |
end | |
function even_maker(odd, even) | |
return function (n) | |
if n == 0 then | |
return true | |
else | |
return odd(n-1) | |
end | |
end | |
end | |
x = y_star(odd_maker, even_maker) | |
oddp = x[1] | |
evenp = x[2] | |
print(512, evenp(512), oddp(512)) | |
print(513, evenp(513), oddp(513)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment