pike.ida.liu.se
Search for
Home > Docs > Pike reference

[Top]
Function

Function.Y()


Method Y

function Y(function 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; })

Module reference for Pike v7.8 release 116, 2008-12-31