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
1
vote
2 answers

Why does the y-combinator provide Turing equivalence?

This answer says Here is a basic y-combinator in lambda calculus: Y f = (\x -> f (x x)) (\x -> f (x x)) Ie Something like this in Clojure: (defn Y [f] ((fn [x] (x x)) (fn [x] (f (fn [& args] (apply (x x) args)))))) (def fac …
hawkeye
  • 31,052
  • 27
  • 133
  • 271
1
vote
2 answers

Why Scheme requires apply in Y-combinator implementation, but Racket doesn't?

Here is the Y-combinator in Racket: #lang lazy (define Y (λ(f)((λ(x)(f (x x)))(λ(x)(f (x x)))))) (define Fact (Y (λ(fact) (λ(n) (if (zero? n) 1 (* n (fact (- n 1)))))))) (define Fib (Y (λ(fib) (λ(n) (if (<= n 1) n (+ (fib (- n 1)) (fib (- n…
hawkeye
  • 31,052
  • 27
  • 133
  • 271
1
vote
2 answers

Scheme - fibonacci series with nested lambda

Inspired this post . I trying to implement a fibonacci series with nested lambda - (( (lambda (x) (x x)) ;; evaluate x on x ((lambda (fibo-gen)) ;; fibo-gen get another func as arg (lambda (N it second first) (cond ;; here the body…
URL87
  • 9,430
  • 29
  • 98
  • 161
1
vote
1 answer

Unable to get implementation of Y combinator working

Here's the code (also here): #lang racket (define poorY ((lambda length (lambda (ls) (cond [(null? ls) 0] [else (add1 ((length length) (cdr ls)))]))) (lambda length (lambda (ls) (cond [(null? ls) 0] …
Hanfei Sun
  • 39,245
  • 33
  • 107
  • 208
0
votes
0 answers

Implementing the Y-Combinator in Swift

I was watching this talk by Jim Weirich: https://www.youtube.com/watch?v=FITJMJjASUs about implementing the Y-Combinator in Ruby, and following along in Swift. I eventually got to this function, which works as a factorial for numbers up to 5: let…
Eduard Lev
  • 33
  • 5
0
votes
0 answers

Converting Python functions with multiple statements to lambdas

I'm completely new to Python and I was given a task to rewrite two Python functions using an Y combinator. To this end, I have to transform them into lambdas first, and here's the problem - they both have multiple statements and I'm having troubles…
Quentin
  • 1,040
  • 10
  • 22
0
votes
1 answer

Derivation of the Y-Combinator

While going through this article about Y-combinator (which I highly recommend), I stumbled over this transformation : (define Y (lambda (f) ((lambda (x) (x x)) (lambda (x) (f (x x)))))) Note that we can apply the inner lambda…
ecdhe
  • 403
  • 3
  • 16
0
votes
3 answers

Y-combinator does not seem to have any effect

I tried using the y-combinator (in both Lua and Clojure) as I thought that would allow me to exceed the size of default stack implementations when using recursion. It seems I was mistaken. Yes, it works, but in both of these systems, the stack…
0
votes
1 answer

y-combinator in javascript

I have built a y-combinator in js like this const y = f => { const g = self => x => f(self(self))(x); return g(g);} and I simplified this code like this const y = f => { const g = self => f(self(self)); return g(g);} this get an infinite…
-1
votes
1 answer

Disable Recursion in Ruby to Force Use of Y Combinator

How can Ruby's recursion be 'sabotaged' to disable the ability of ruby methods to engage in recursion? Needed for the creation of a program to teach lambda calculus, but using Ruby. Motivation from Crockford on JavaScript -…
Trajanson
  • 421
  • 3
  • 10
-1
votes
1 answer

Y-Combinator definiton

I am trying to understand the fixed-point combinator. I think it is used by some languages to implement recursion. The main problem is that I couldn't get the next definition: So please explain the image.
Charlie
  • 100
  • 7
1 2 3 4 5
6