title: Scheme: merge and sort functions
body: <p>I'm trying to write a function that merges and then sorts a list, but now I have two different functions; one that merges it and one that sorts it. So I'm trying to write another function, that calls either functions, so it can merge and sort a list at once in that function.</p>
  
  <p>This is what I have:</p>
  
  <pre><code>;; this merges the list
  (define (merge l1 l2)
    (cond ((null? l1) l2)
          ((null? l2) l1)
          ((&lt; (car l1) (car l2)) (cons (car l1) (merge (cdr l1) l2)))
          (else (cons (car l2) (merge l1 (cdr l2))))))
  
  ;; this sorts the list
  (define sort
    (lambda (lst)
      (if (null? lst)
          '()
          (insert (car lst)
                  (sort (cdr lst))))))
  
  (define insert
    (lambda (elt sorted-lst)
      (if (null? sorted-lst)
          (list elt)
          (if (&lt;= elt (car sorted-lst))
              (cons elt sorted-lst)
              (cons (car sorted-lst)
                    (insert elt (cdr sorted-lst)))))))
  </code></pre>