learning-sicp

My embarrassing half assed SICP run.
git clone https://kaka.farm/~git/learning-sicp
Log | Files | Refs

exercise-5.scm (1046B)


      1 #!
      2 
      3 *Exercise 1.5:* Ben Bitdiddle has invented a test to determine
      4 whether the interpreter he is faced with is using
      5 applicative-order evaluation or normal-order evaluation.  He
      6 defines the following two procedures:
      7 
      8 (define (p) (p))
      9 
     10 (define (test x y)
     11   (if (= x 0)
     12       0
     13       y))
     14 
     15 Then he evaluates the expression
     16 
     17 (test 0 (p))
     18 
     19 What behavior will Ben observe with an interpreter that uses
     20 applicative-order evaluation?  What behavior will he observe with
     21 an interpreter that uses normal-order evaluation?  Explain your
     22 answer.  (Assume that the evaluation rule for the special form
     23                  `if' is the same whether the interpreter is using normal or
     24                  applicative order: The predicate expression is evaluated first,
     25                  and the result determines whether to evaluate the consequent or
     26                  the alternative expression.)
     27 
     28 Applicative-order evaluation:
     29 
     30 (test 0 (p))
     31 (test 0 (p))
     32 (test 0 and so on)
     33 
     34 Normal-order evaluation:
     35 
     36 (test 0 (p))
     37 (if (= 0 0)
     38     0
     39     (p))
     40 (if #t
     41     0
     42     (p))
     43 0
     44 
     45 !#