I encountered the following error — imagine a function that returns 3.0
instead of just 3.0 as shown example below:

> (split-at-right (range 8) 3.0)
split-at-right: contract violation
  expected: exact-nonnegative-integer?
  given: 3.0
  context...:
   /Applications/Racket/collects/racket/list.rkt:191:0: split-at-right
   /Applications/Racket/collects/racket/private/misc.rkt:87:7

The obvious  fixes didn't work ...

> (split-at-right (range 8) (round 3.0))
split-at-right: contract violation
  expected: exact-nonnegative-integer?
  given: 3.0
  context...:
   /Applications/Racket/collects/racket/list.rkt:191:0: split-at-right
   /Applications/Racket/collects/racket/private/misc.rkt:87:7
>

... and I couldn't find something like real->integer, but inexact->exact
came to the rescue:

> (split-at-right (range 8) (inexact->exact 3.0))
(split-at-right (range 8) (inexact->exact 3.0))
'(0 1 2 3 4)
'(5 6 7)
> (split-at-right (range 8) 3.0)
split-at-right: contract violation
  expected: exact-nonnegative-integer?
  given: 3.0
  context...:
   /Applications/Racket/collects/racket/list.rkt:191:0: split-at-right
   /Applications/Racket/collects/racket/private/misc.rkt:87:7
>

Still, it doesn't seem particularly elegant.
____________________
  Racket Users list:
  http://lists.racket-lang.org/users

Reply via email to