From f968bc59afafba1ee96ff67faed1ca847b65806b Mon Sep 17 00:00:00 2001 From: Juthatip McDevitt Date: Sun, 27 Jul 2025 11:15:45 -0500 Subject: [PATCH] add ch1 ex5 --- chapter_1/ex_5.rkt | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/chapter_1/ex_5.rkt b/chapter_1/ex_5.rkt index 3531468..7f5c9dc 100644 --- a/chapter_1/ex_5.rkt +++ b/chapter_1/ex_5.rkt @@ -1,3 +1,23 @@ #lang sicp -(+ 5 5) \ No newline at end of file +;Ben Bitdiddle has invented a test to determine whether the interpreter he is faced with is using applicative-order evaluation or normal-order evaluation. He defines the following two procedures: +;(define (p) (p)) +;(define (test x y) +;(if (= x 0) 0 y)) +;Then he evaluates the expression (test 0 (p)) +;What behavior will Ben observe with an interpreter that uses applicative-order evaluation? What behavior will he observe with an interpreter that uses normal-order evaluation? Explain your answer. +;(Assume that the evaluation rule for the special form if is the same whether the interpreter is using normal or applicative order: The predicate expression is evaluated first, and the result determines whether to evaluate the consequent or the alternative expression.) + +;-------------------------------------------------------------------------------------------------------------------------- +;Applicative-order evaluation --> evaluates the arguments of a function before applying the function itself. +;Normal-order evaluation --> evaluates arguments only when they are needed (delay evaluation agrument until they are needed) + + +(define (p) (p)) +(define (test x y) + (if (= x 0) 0 y) +) + +(test 0 3) ;if x = 0 then return x but if it is not then return y. So that, it is doing what you are asking for --> return x which is 0 +(test 1 3) ;if x != 0 then return y --> return 3 +(test 0 (p)) ;nothing happened// not evaluated yet \ No newline at end of file