基于 Python 的函数式编程语言——Coconut

Coconut 的代码最终将翻译为 Python 源代码并执行,看起来挺有意思的:

range(100) |> parallel_map$((**)$(2)) |> list

尾递归优化:

@recursive
def factorial(n, acc=1):
    case n:
        match 0:
            return acc
        match _ is int if n > 0:
            return factorial(n-1, acc*n)
    else:
        raise TypeError("the argument to factorial must be an integer >= 0")
0 comments