tags:

views:

95

answers:

2

Hi,

I am new to Scheme, by looking at the Exercise 1.5 of SICP, what is the meaning/usage of this expression?

(define (p) (p))

Thanks!

+7  A: 
(define (p) (p))

The above defines a function p that takes no arguments and calls itself recursively (infinitely).

The exercise 1.5 is about applicative-order vs normal-order evaluation.

(define (test x y)
  (if (= x 0)
       0
       y))

(test 0 (p))

In applicative-order all arguments are evaluated and then they are applied to the test, so the program will freeze if the interpreter uses that kind of evaluation in this specific case.

Nick D
+2  A: 

'define' is defined in the very beginning, in chapter 1:

The general form of a procedure definition is

(define (< name> < formal parameters>) < body>)

After you evaluate the definition you see that your procedure is simply calling itself. The trick lies in the evaluation order of the arguments of the 'test' procedure, as you could figure out from the question of the exercise.

bandi