clojure - 在 Clojure 中实现整数?计划中

标签 clojure scheme

我是 Clojure 新手,找不到整数的等效项?在Chez方案8.4中,主要针对以下测试用例:

(integer? 39.0) => #t

到目前为止我提出的功能是:

(defn actual-integer? [x] (or (= 0.0 (- x (int x))) (integer? x))) 

当x是任意数字类型时它是否有效或者有更好的解决方案吗?

谢谢。

最佳答案

严格来说,39.0 不是一个整数文字,因为它末尾有 .0 部分。该过程的一个简单实现是:

(defn actual-integer? [x] (== (int x) x))

请注意 == operator :

Returns non-nil if nums all have the equivalent value (type-independent), otherwise false

关于clojure - 在 Clojure 中实现整数?计划中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19061255/

相关文章:

list - 在 Scheme/Racket 中向左旋转列表

concurrency - 在 Clojure 中是否有可能使用代理导致死锁(或其他坏情况)?

clojure - 创建 HashMap Clojure

optimization - SICP做出改变

scheme - .vimrc 中 Scheme 的条件选项

方案二叉搜索树错误 (R5RS)

constructor - Clojure:从Map分配defrecord字段

clojure - 减少像 Clojure 中带有条件的循环这样的惰性序列

git - 有没有提供 Git 信息的 Leiningen 插件?

scheme - SICP 练习 1.3 征求意见