The following function, when evaluated with “(reduced 10 1)”, should return “3”, but it enters an infinite recursion instead.
(define (reduced rest multiple)
; rest: cardinal
; multiple: cardinal
; multiple > 0
(print "multiple: " multiple " rest: " rest)
((> multiple rest) rest)
(define multiple' (+ multiple multiple))
(define rest' (- rest multiple))
(print "multiple': " multiple' " rest': " rest')
(reduced rest' multiple')
(reduced 10 1 1)
Seems there is a bug involving nested “define” and recursion. If the recursion point contain an expression, the recursion disappear. See attached Scheme sample source file for more details.
Log in to post a comment.