(方案)从数字中去掉小数(即 42.0 -> 42)

(Scheme) Take away decimal from a number (i.e 42.0 -> 42)

我有一个大小为 700000 的向量,其中全为零。我正在尝试将索引中的值更改为 1。我通过计算获得索引。这是代码:

#lang racket

; Make bitvector
(define bitvector (make-vector 700000 0))

; Fill indices
(define fillvector
  (lambda (hashlist dict)
    (cond [(null? hashlist) (cdr dict)]
          [(null? dict) '()]
          [else (vector-set! bitvector ((car hashlist) (car dict)) 1) (fillvector (cdr hashlist) dict)]
    )
))

我这样称呼fillvector(fillvector hashfl-1 dictionary)dictionary是一堆字:

(define dictionary '( (h e l l o)
                      (w a y)
                      (r a i n b o w) ))

我在 运行 命令后收到此错误:

vector-set!: contract violation
  expected: exact-nonnegative-integer?
  given: 415458.0
  argument position: 2nd
  other arguments...:
   '#(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
   1

我认为错误是因为乘法可以 return 一个十进制值(尽管我确定它总是 .0)。还有什么我可以做的吗?任何帮助将不胜感激,谢谢!

将浮点数("inexact")数转换为非浮点数("exact")数的过程是inexact->exact(或exact R6RS 和 R7RS)。

> (inexact->exact 415458.0)
415458