[plt-scheme] How to make the following code more clear?

From: SamuelXiao (foolsmart2005 at gmail.com)
Date: Sat Oct 11 05:15:06 EDT 2008

Here is my program:
--------------------------------------------------------------
(define (selectionsort lst)

  (define(largest lst)
    (define larger(lambda (x y)
                    (if (> x y) x y)))
    (if(null? (cdr lst))
       (car lst)
       (larger(car lst)(largest(cdr lst)))))

  (define(remove lst val)
    (if(eq? val (car lst))
       (cdr lst)
       (cons (car lst)(remove(cdr lst)val))))

  (define selectionhelper (lambda(largestval lst)
                            (cons largestval (selectionsort(remove lst
largestval)))))

  (if (null? lst) '()
      (selectionhelper (largest lst) lst)))
 
-------------------------------------------------------------------------------------------------------

As you can see, it's a bit hard to read, could anyone tell me how to
combine the defines into only one define and make it more clear?

My program is selection sort. it's now in descending order, i want to
make it in ascending order, how could i do it?  i don't want to change
to larger into smaller although it's work.  I tried use reverse but it
gives me uncorrect order.



Posted on the users mailing list.