Menu

#1 Scheme interpreter recursion bug

open
nobody
cm (2)
5
2026-06-21
2012-07-25
Hibou57
No

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.

Discussion

  • Hibou57

    Hibou57 - 2012-07-25

    More analysis and examples for the bug

     
  • Glen Everett

    Glen Everett - 2025-10-02

    I also see this error. Luckily there is method space waves to fix it.

     
    👎
    1
  • Sam Will

    Sam Will - 2025-10-13
    Post awaiting moderation.
  • Sam Will

    Sam Will - 2025-10-13

    It has been fixed slope

     
    👎
    1

    Last edit: Sam Will 2025-10-13
  • Mark Sweeney

    Mark Sweeney - 2025-11-27
    Post awaiting moderation.
  • Johnny Payne

    Johnny Payne - 2026-01-24

    Hey @tunnel rush, this behavior is expected in Scheme and not a recursion bug.

     
    👎
    1

    Last edit: Johnny Payne 2026-01-24
  • Evan Whitehead

    Evan Whitehead - 2026-02-02
    Post awaiting moderation.
  • Lois Tanner

    Lois Tanner - 2026-03-16

    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.

     
    👎
    1

    Last edit: Lois Tanner 2026-03-16
  • mohaselena

    mohaselena - 2026-04-17
    Post awaiting moderation.
  • Cavanaugh Brett

    Cavanaugh Brett - 2026-04-17

    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

     
    👎
    1

    Last edit: Cavanaugh Brett 2026-04-17
  • Felix Andrea

    Felix Andrea - 2026-04-21

    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.

     
    👎
    1
  • kenvin roll

    kenvin roll - 2026-05-12
    Post awaiting moderation.
  • Forrest Armstrong

    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.

     
  • Harry Cole

    Harry Cole - 2026-05-25
    Post awaiting moderation.
  • williams

    williams - 2026-06-21
    Post awaiting moderation.

Log in to post a comment.

Monday.com Logo