[racket] integers, exact and inexact in working with split-at-right
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140315/03ef8158/attachment.html>