Using foldr when the base case is an error
<p>I am wondering how you would convert this function to foldr. Particularly the base case, which is an error. The parameters are a list and an element of the list. The function just counts the number of elements to the element in the parameter (x).</p>

<pre><code>; [List-of X] X -&gt; number or error
; Count number of elements to X
(define (cnt l x)
  (cond
    [(empty? l) (error x "not found")]
    [(symbol=? (first l) x) 0]
    [else (add1 (cnt (rest l) x))]))
</code></pre>