I would like to use ->d to impose a precondition for a function. For example:<br><br> (matrix-ref<br> (->d ((matrix matrix?)<br> (i (and/c exact-nonnegative-integer? (</c (matrix-rows matrix))))<br> (j (and/c exact-nonnegative-integer? (</c (matrix-cols matrix)))))<br>
()<br> (result any/c)))<br><br>or<br><br> (matrix-ref<br> (->d ((matrix matrix?)<br> (i exact-nonnegative-integer?)<br> (j exact-nonnegative-integer?))<br> ()<br> #:pre-cond (and (< i (matrix-rows matrix))<br>
(< j (matrix-cols matrix)))<br> (result any/c)))<br><br>instead of just<br><br> (matrix-ref<br> (-> matrix? exact-nonnegative-integer? exact-nonnegative-integer? any/c))<br><br>The first two do work, but are really, really slow.<br>
<br>I like having the bounds check in the contract (as opposed to bounds check in the matrix-ref code, but can't accept the performance hit. Any ideas?<br><br>Doug<br><br>