math - 为什么 Clojure 返回 1N 而不是 1?

标签 math clojure return-value

;; ------------------------- DICE COEFFS ------------------------

(defn dice-set-coeff [a b]
  (* (/ (count (clojure.set/intersection a b))
        (+ (count a) (count b)))
     2))

(defn dice-lst-coeff [a b]
  (dice-set-coeff (set a) (set b)))

;; ------------------------- BIGRAMS ----------------------------

(defn now-nxt [xs]
  "im sure there is a better way to write this"
  (map #(list %1 %2) xs (rest xs)))

(defn bigram [xs]
  (list now-nxt xs))

(defn dice-string-bigram [a b]
  (dice-lst-coeff (bigram a) (bigram b)))

为什么我的结果是 1N?

tst.core> (dice-string-bigram "hello" "hello")
1N
tst.core> (dice-string-bigram "hello" "helap")
1/2
tst.core> (dice-string-bigram "hello" "howdy")
0
tst.core> (== (dice-string-bigram "hello" "hello") 1)
true

最佳答案

1N 是阅读器和 REPL 用于 BigInt 的语法。

其中一个调用返回一个 bigint。


回复:“我确信有更好的方法来写这个”

user> (now-nxt a)
((\h \e) (\e \l) (\l \l) (\l \o))
user> (partition 2 1 a)
((\h \e) (\e \l) (\l \l) (\l \o))

关于math - 为什么 Clojure 返回 1N 而不是 1?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11603804/

相关文章:

c# - 如何在 C# 中将 BigInteger 转换为 pow Double?

heroku - 处理托管在 Heroku 上的 Clojure 分类 Web 应用程序的子域

c# - 如何从函数返回值以在每一行用新结果顺序调用它

c++ - 控制台上的不同输出打印标准输出/重定向到文件

algorithm - 编程: Give the count of all such numbers which have 3 in their decimal representation

xml - 具有简单和嵌套标签的 xml 的 clj-xpath

带返回值的 Java 错误/异常处理

python - 可选的多个返回值

javascript - Mandelbrot 设置渲染速度太慢

python - 纬度/经度集中的最短总路径