Here's a program I wrote to sort a list of numbers in increasing order (without using inbuilt sort function).
(define (sort-list l)
(define first-element (if (not (null? l)) (car l) 0))
(cond ((null? l) (quote ()))
(else (cons (find-shortest l first-element) (sort-list (remove-member l (find-shortest l first-element)))))))
(define find-shortest
(lambda (tl b)
(cond ((null? tl) b)
((< (car tl) b) (set! b (car tl)) (find-shortest (cdr tl) b))
(else (find-shortest (cdr tl) b)))))
(define remove-member
(lambda (tl2 a)
(cond ((null? tl2) (quote ()))
((= a (car tl2)) (cdr tl2))
(else (cons (car tl2) (remove-member (cdr tl2) a))))))
It works, but I know it's very badly written. It has way too many recursions than what's necessary. Can someone suggest ways to make this code better?
find-shortest
should be namedfind-smallest
. \$\endgroup\$