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)
(cond
((> multiple rest) rest)
(else
(define multiple' (+ multiple multiple))
(define rest' (- rest multiple))
(print "multiple': " multiple' " rest': " rest')
(reduced rest' multiple')
); else
); cond
); reduced
(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.
More analysis and examples for the bug
I also see this error. Luckily there is method space waves to fix it.
It has been fixed slope
Last edit: Sam Will 2025-10-13
Hey @tunnel rush, this behavior is expected in Scheme and not a recursion bug.
Last edit: Johnny Payne 2026-01-24
Seems there is a bug involving nested “define” and recursion. If the recursion point contain an expression, the recursion disappear. See attached Scheme geometry dash sample source file for more details.
Last edit: Lois Tanner 2026-03-16
It’s interesting to see how even niche projects like Common Music still have unresolved bugs—really shows how maintaining open-source software can be an ongoing challenge 99 nights in the forest
Last edit: Cavanaugh Brett 2026-04-17
Interesting bug! It seems like the issue might be related to how the nested define is being evaluated within the recursion. Have you tried moving the heardle define statements outside the cond or using let instead? It could help clarify the scope and prevent unexpected behavior.
Interesting bug report. It really does look like the nested define statements are interfering with the recursive call scope or evaluation order. I’d be curious to know which Scheme interpreter/version you’re using, since standard Scheme implementations usually handle basketball stars this pattern correctly without infinite recursion.