Y Combinator in Scheme using Define
Asked Answered
K

2

5

In order to learn what a fixed-point combinator is and is used for, I wrote my own. But instead of writing it with strictly anonymous functions, like Wikipedia's example, I just used define:

(define combine (lambda (functional)
                  (functional (lambda args (apply (combine functional) args))))

I've tested this with functionals for factorial and fibonacci, and it seems to work. Does this meet the formal definition of a fixed-point combinator?

Klemm answered 14/1, 2011 at 1:28 Comment(1)
Exercise 2: Y combinator without using define or letrec :)Behavior
I
3

The answer is no, because according to the blog referred to in the previous answer, it doesn't even meet the definition of combinator, since 'combine' is a free variable.

Iceboat answered 17/5, 2011 at 18:34 Comment(1)
Thanks for pointing that out. Just to be sure that the blog's definition is correct, do you consider it equivalent to Wikipedia's definition: "A combinator is a higher-order function that uses only function application and earlier defined combinators to define a result from its arguments."? See en.wikipedia.org/wiki/Combinatory_logicKlemm
K
5

EDIT: While chessweb or anyone else corroborates his answer, temporarily consider his answer correct and this one wrong.


It seems the answer is yes. Apparently the exact same combinator appears here, midway down the page:

(define Y
    (lambda (f)
      (f (lambda (x) ((Y f) x)))))
Klemm answered 14/1, 2011 at 1:41 Comment(2)
You shouldn't. You're encouraged to answer you own questions. IIRC you can accept your own answer in 2 days after you gave it.Lamia
The main point of teaching the Y combinator is to see how you can implement recursion with just functions. By writing a recursive definition, you fail to do that -- so you end up with something that works, but it's only useful in understanding what Y is supposed to do. Mike's text would be a good place to read about it in depth and see how the define-less version is derived.Misguide
I
3

The answer is no, because according to the blog referred to in the previous answer, it doesn't even meet the definition of combinator, since 'combine' is a free variable.

Iceboat answered 17/5, 2011 at 18:34 Comment(1)
Thanks for pointing that out. Just to be sure that the blog's definition is correct, do you consider it equivalent to Wikipedia's definition: "A combinator is a higher-order function that uses only function application and earlier defined combinators to define a result from its arguments."? See en.wikipedia.org/wiki/Combinatory_logicKlemm

© 2022 - 2024 — McMap. All rights reserved.