Blue Crow Util

lua-users home
wiki

Y <- function (g){ local a = function (f) return f(f) return a(function (f):(g){
return g(function (x):(f) {
local c=f(f)
return c(x)
})
})
}

// factorial without recursion

F <- function (f){ return function (n):(f){

if (n == 0) return 1
else return n*f(n-1)
}
}

factorial <- Y(F) // factorial is the fixed point of F

// now test it

function test(x){

print(x+"! = "+factorial(x)+"\n")
}

test(3) test(4) test(5) test(6) test(7) Describe the new page here.


RecentChanges · preferences
edit · history
Last edited December 6, 2019 4:16 pm GMT (diff)