Outputting a sorted list of pairs in scheme recursively (issue with base case)
<p>I want to sort and print out a list somewhat like this:</p>

<p>Apple : 1
Banana : 2
...etc (each pair is on a new line, but stackoverflow shows it like this)</p>

<p>I find that I can get it mostly done, but I get an error that it expects a pair, while it is given an empty list. I understand that the error is because I reached the end of my list, and that I need a base case here, but I'm not sure what is required. If I check to see if the list is null, and then return the list as my base case, it doesn't output anything.</p>

<p>Getting the following error:</p>

<blockquote>
  <p>car: contract violation   expected: pair?   given: ()</p>
</blockquote>

<p>Thanks for checking out my problem.</p>

<pre><code>(define lst '( ("Apple" 1) ("Orange" 4)  ("Pear"3) ("Banana" 2)) )

(define name (lambda (m)
               (car m)
               ))

(define priority (lambda (m)
                   (car (cdr m))
                   ))

(define sortList
  (lambda (lst)
    (sort lst
       (lambda (x y)
        (&lt;(priority x)(priority y))
       )
      )
    )
 )

(define printItem (lambda (m)

                      (display (name m))
                      (display " : ")
                      (display (priority m))
                      (display "\n")
                      )
  )

(define printQueue
  (lambda (lst)
    (printItem (car(sortList lst)))
    (printQueue (cdr (sortList lst)))
    )
  )

(printQueue lst)
</code></pre>