title: Error: contract violation in Scheme
body: <p>I'm practicing recursion in Scheme. My code below is used to take a pattern clause and a statement then return a list of bindings if statement match pattern, false if it isn't:</p>
  
  <pre><code>(define remove-question-mark
    (lambda (s1)
      (if (memq #\? (string-&gt;list (symbol-&gt;string s1)))
          (cdr (string-&gt;list (symbol-&gt;string s1)))
          '())))
  
  (define check-two-symbol
    (lambda (symbol1 symbol2)
      (if (and (regexp-match #rx#"\\?attrs" (symbol-&gt;string symbol1)) (list? symbol2))
          (cons symbol1 (list symbol2))
          (if (equal? symbol1 symbol2)
              '()
              (if (equal? (remove-question-mark symbol1) (string-&gt;list (symbol-&gt;string symbol2)))
                  (cons symbol1 symbol2)
                  #f)))))
  
  (define clause
    (lambda (state1 state2)
      (if (and (null? (car state1)) (null? (car state2)))
          '() 
          (list (check-two-symbol (car state1) (car state2)) (clause (cdr state1) (cdr state2))))))
  </code></pre>
  
  <p>This is my input: </p>
  
  <pre><code>(clause '(wasDerivedFrom ?der ?e1 ?e2 . ?attrs_derv) '(wasDerivedFrom der e1 e2 (prov:type "Revision")))
  </code></pre>
  
  <p>I got this error from my code:</p>
  
  <pre><code>car: contract violation
    expected: pair?
    given: '()
  </code></pre>
  
  <p>Expected output:</p>
  
  <pre><code>((?der . der)
  (?e1 . e1)
  (?e2 . e2)
  (?attrs_derv (prov:type "Revision")))
  </code></pre>
  
  <p>After debugging, i found that error happens when <code>(car state1)</code> is <code>?attrs_derv</code> </p>
  
  <p>If I run function <code>check-two-symbol</code> seperrately, like <code>(check-two-symbol '?attrs-derv '(prov:type "Revision"))</code>, it prints out nicely:</p>
  
  <pre><code>(?attrs_derv (prov:type "Revision"))
  </code></pre>
  
  <p>But with the main function, i get error. So can someone please help me show how to fix this error?? I'm not really familiar with recursion much ....</p>
  
  <p>Thank in advanced!</p>