Questions tagged [y-combinator]

The Y combinator is a higher-order function that allows a function that does not know its own name to call itself. It is the fundamental basis of recursion.

The Y combinator is a higher-order function that allows a function that does not know its own name to call itself. It is the fundamental basis of recursion.

In Scheme syntax:

  (define Y
    (lambda (f)
      (f (lambda (x) ((Y f) x)))))

To implement Fibonacci recursively with Y:

(define fibonacci 
  (Y
    (lambda (f)
      (lambda (n)
        (if (= n 0)
            1
            (* n (f (- n 1))))))) ))

A nice article on the topic is at: http://mvanier.livejournal.com/2897.html

86 questions
2
votes
3 answers

can i use y-combinator to get object reference for this closure?

this closure works: var o = { foo: 5 }; o.handler = function(obj){ return function() { alert(obj.foo); }; }(o); o.handler(); //alert('5') is it possible to define handler in-line, perhaps with something similar to a…
Dustin Getz
  • 19,902
  • 13
  • 77
  • 127
2
votes
2 answers

How would you implement a fixed-point operator (Y combinator) in F#?

I'm using F# to create a lambda calculus. I am currently stuck trying to figure out how I would implement the fixed-point operator (also called Y combinator). I think everything else is in order. Expressions are represented by the following…
klactose
  • 1,131
  • 2
  • 9
  • 26
2
votes
1 answer

When I use Y-Combinator and block in C, I meet a strange thing in parameter value

When I try to caculate sinh−1(x) using functions: double asinh_recursion(double buf, double increment, double input_var, unsigned long item_count) { if (fabs(increment) < 1E-5) { return buf; } return asinh_recursion(buf +…
slowcoach
  • 23
  • 5
2
votes
1 answer

Y-combinator implementation in javascript and elixir

I've been studying the Y Combinator, and I get how it works on paper, but I don't know yet understand how it can be implemented in a programming language. According to this page:…
CMCDragonkai
  • 5,369
  • 10
  • 47
  • 85
2
votes
1 answer

How to do this length≤1 more than once?

I've spent a day reading page 166's length≤1 in the book The Little Schemer; there's the following code: (((lambda (mk-length) (mk-length mk-length)) (lambda (mk-length) (lambda (l) (cond ((null? l) 0) (else (add1 …
2
votes
1 answer

convert one big quote to string/list in scheme

i have this assignment to do, where i need to parse a wrong written recursive procedure, and fix it. for example: This: (let ((fib (lambda (n) (cond ((= n 0) 1) ((= n 1) 1) (else (+…
matmiz
  • 50
  • 8
1
vote
1 answer

Is the Y Combinator a left fold or a right fold?

The Y combinator (from the wikipedia article) is defined as: Y = \f.(\x.f(x x)) (\x.f(x x)) so when we call Y on g: Y g = (\f.(\x.f(x x)) (\x.f(x x))) g = (\x.g(x x)) (\x.g(x x)) = g((\x.g(x x)) (\x.g(x x))) = g (Y g) The repetition results in…
1
vote
1 answer

Why does wrapping a function with a lambda fix stack overflow?

If expression evaluates to a function of one argument, I would have thought that lambda x: (expression)(x) is identical to expression - but this is not actually the case. Consider the two following definitions of the Y combinator: def Y1(F): …
1
vote
2 answers

(self self) call inside the let statement, in strict language

I am currently, going through this article on Y-combinator by Mike Vanier. Along the way of Y-combinator derivation, this code: (define (part-factorial self) (lambda (n) (if (= n 0) 1 (* n ((self self) (- n…
user8554766
1
vote
1 answer

Understanding extra arguments in the Y Combinator in Scheme

According to RosettaCode, the Y Combinator in Scheme is implemented as (define Y (λ (h) ((λ (x) (x x)) (λ (g) (h (λ args (apply (g g) args))))))) Of course, the traditional Y Combinator is λf.(λx. f(x x))(λx. f(x x)) My question,…
Ben I.
  • 963
  • 1
  • 11
  • 27
1
vote
2 answers

How to implement iteration of lambda calculus using scheme lisp?

I'm trying to learn lambda calculus and Scheme Lisp. The tutorial on lambda calculus can be found here http://www.inf.fu-berlin.de/lehre/WS03/alpi/lambda.pdf. The problem I'm facing is I don't know how to properly implement iteration. (define (Y y)…
1
vote
2 answers

Issue passing a closure that takes an escaping closure to a function that accepts a closure of that type

In the old swift world (2.0 I believe) I had the following Y-combinator implementation func Y( f: (T -> R) -> (T -> R) ) -> (T -> R) { return { (t: T) -> R in return f(self.Y(f))(t) } } I would call the Y-comb elsewhere to…
agreendev
  • 169
  • 2
  • 8
1
vote
2 answers

Recursive lambda calculus function

I would like to create a lambda calculus function P such that (P x y z) gives ((x y)(x P)(P z)). I have tried using variants of the Y-combinator/Turing combinator, i.e. functions of the form λg.(g g), since I need to reproduce the function itself,…
1
vote
1 answer

How to call a function with multiple arguments using the Y combinator in ocaml?

I'm trying to understand the Y combinator in OCaml. I took some code from here, and I'm trying to use it to write the Ackermann function. In the examples in the link, the functions only require one argument. The Ackermann function requires two…
user3047641
  • 149
  • 1
  • 1
  • 10
1
vote
1 answer

Y-Combinator factorial in javascript works for numbers not for the Church numerals.

I managed to implement Church encoding and Y-Combinator using ES6 arrow function in javascript. But when I tried to evaluate the factorial function, FALSE = a => b => b TRUE = a => b => a ZERO = f => z => z ONE = f => z => f(z) SIX = f => z =>…