From: Ramakrishnan Muthukrishnan Date: Sun, 27 May 2012 16:25:57 +0000 (+0530) Subject: Better explanation of the unless procesure if it is not defined X-Git-Url: https://git.rkrishnan.org/Site/Content/Exhibitors/vdrive/global?a=commitdiff_plain;h=d8388032e6e749f7cab7a18d840bc6462826dccc;p=sicp.git Better explanation of the unless procesure if it is not defined in a lazy way. --- 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