[plt-scheme] ->d Performance

Doug Williams m.douglas.williams at gmail.com
Sat Apr 11 14:17:12 EDT 2009


I would like to use ->d to impose a precondition for a function.  For
example:

 (matrix-ref
  (->d ((matrix matrix?)
        (i (and/c exact-nonnegative-integer? (</c (matrix-rows matrix))))
        (j (and/c exact-nonnegative-integer? (</c (matrix-cols matrix)))))
       ()
       (result any/c)))

or

 (matrix-ref
  (->d ((matrix matrix?)
        (i exact-nonnegative-integer?)
        (j exact-nonnegative-integer?))
       ()
       #:pre-cond (and (< i (matrix-rows matrix))
                       (< j (matrix-cols matrix)))
       (result any/c)))

instead of just

 (matrix-ref
  (-> matrix? exact-nonnegative-integer? exact-nonnegative-integer? any/c))

The first two do work, but are really, really slow.

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?

Doug
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://list.cs.brown.edu/pipermail/plt-scheme/attachments/20090411/b5d13f6b/attachment.html


More information about the plt-scheme mailing list