How Can Lisp be defined in terms of y combinator?

119 views Asked by At

I'm watching a lecture SICP 7A and struggling to understand "Define Lisp as Y combinator (time 1:16:15 )"

I think I understood that expt ( calculating exponential of a number like x^n ) can be expressed in terms of Y combinator and lambda.

If I am right, I can think of this equation as a recursive expression.

x = 2x - 4

Because x is defined using itself.

So I can express above expression as

f(x) = 2x - 4 .

So x is the fixed point of f: x = f(x).

And Using this strategy, ( And all code is expressed as Scheme )

First express expt as,

(define expt
  (lambda (x n)
    (if (= n 0)
        1
        (* x (expt x (- n 1))))))

and like above F is

F = (lambda (g)
      (lambda (x n)
        (if (= n 0)
            1
            (* x (g x (- n 1))))))

So expt is ( Y is Y combinator, (Y F) = (F (Y F)) )

expt = F expt = fixed point of F = (F(F(F(F... (F ?) ...)))) = (Y F) .

So my question is here,

Like Sussman ( the lecturer of the video (link above) ) said,

What Lisp is is the fixed point of the process which says,
if I know what lisp was and substituted it in for 
eval and apply and so on, 
on the right hand sides of all those recursion equations,
then if it was a real good lisp, is a real one then
the left hand side would also be lisp.

Can I express Lisp as

L = (lambda (lisp)
      (lambda (eval apply)
         (lisp eval apply))))

So as a result, Can this code (below) said to be right?

Lisp = L Lisp = fixed point of L = (L(L(L(L ... (L ?) ... )))) = (Y L)
1

There are 1 answers

0
Sylwester On

The y combinator uses lexical closures to perform recursion. Thus you can implement a Scheme interpreter with global variables and letrec in a host scheme that doesn't have them as long as it has lexical closures. Basically you can rewrite them to use Y combinator.

This is the same as cond vs if where you can implement both as long as the host has one of them.

You can implement Scheme using only lexical closures and basically you turn the code into lambda calculus. It's a very inefficient scheme and not very useful, but it's turing complete. I think all developers should try to implement a lisp language in both a lisp language like Scheme or CL and try the same in a non lisp language. It gives you some Insight you'll never have about programming languages. Good luck