From d8388032e6e749f7cab7a18d840bc6462826dccc Mon Sep 17 00:00:00 2001 From: Ramakrishnan Muthukrishnan Date: Sun, 27 May 2012 21:55:57 +0530 Subject: [PATCH] Better explanation of the unless procesure if it is not defined in a lazy way. --- src/sicp/ex4_25.rkt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/sicp/ex4_25.rkt b/src/sicp/ex4_25.rkt index 20c4136..7a01051 100644 --- a/src/sicp/ex4_25.rkt +++ b/src/sicp/ex4_25.rkt @@ -2,9 +2,21 @@ #| -The call (factorial 5) will never call 'unless' and will be recursively call 'factorial' for ever. +The call (factorial 5) will never call 'unless' and will be recursively call 'factorial' for ever. 'n' goes +negative and the factorial won't notice it, as it will never get to evaluate the function body of `unless'. It will work in a normal order language because none of the arguments of 'unless' are evaluated until they are used inside. +#lang lazy +(define (unless predicate if-exp else-exp) + (if (not predicate) + if-exp + else-exp)) + +(define (factorial n) + (unless (= n 1) + (* n (factorial (- n 1))) + 1)) + |# \ No newline at end of file -- 2.37.2