Welcome to the CHICKEN Scheme pasting service

Merge sort added by vktec on Sat Sep 24 18:32:48 2016

(use srfi-1)

(define (merge a b)
  (cond
    ((null? a) b)
    ((null? b) a)
    (else
     (if (< (car a)
            (car b))
         (cons (car a)
               (merge (cdr a)
                      b))
         (cons (car b)
               (merge a
                      (cdr b)))))))

(define (merge-sort l)
  (let ((len (length l)))
    (cond
      ((>= 1 len) l)

      ((= 2 len)
       (if (> (car l)
              (cadr l))
           (list (cadr l)
                 (car l))
           l))

      (else
       (let ((half-len (quotient len 2)))
         (merge
          (merge-sort (take l half-len))
          (merge-sort (drop l half-len))))))))

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
Which egg provides `take-right'?
Visually impaired? Let me spell it for you (wav file) download WAV