memory
添加了LRU缓存淘汰。
rec模块为了缓存每次递归的结果牺牲了尾递归优化,所以移除了它。
gleam add memory
import memory
pub fn factorial(i: Int) -> Int {
factorial_loop(i, i)
}
fn factorial_loop(i: Int, acc: Int) -> Int {
case i {
0 | 1 -> acc
_ -> factorial_loop(i - 1, acc * { i - 1 })
}
}
pub fn main() -> Nil {
let assert Ok(factorial) = memory.new(factorial, 10)
}
Development
gleam run # Run the project
gleam test # Run the tests