Pike v8.1 release 6

Method Function.Y()


Method Y

function(:void) Y(function(:void) f)

Description

The dreaded fixpoint combinator "Y".

The Y combinator is useful when writing recursive lambdas. It converts a lambda that expects a self-reference as its first argument into one which can be called without this argument.

Example

This example creates a lambda that computes the faculty function.

Function.Y(lambda(function f, int n) { return n>1? n*f(n-1) : 1; })