; gnome sort (define (gnome-sort lt? xs) (let loop ((behind (list)) (before xs)) (display behind) (display " ") (display before) (newline) (cond ((null? before) (reverse behind)) ((null? behind) (loop (list (car before)) (cdr before))) ((lt? (car behind) (car before)) (loop (cons (car before) behind) (cdr before))) (else (loop (cdr behind) (cons (car before) (cons (car behind) (cdr before)))))))) (display (gnome-sort < '(4 1 2 5 3))) (newline)