小编use*_*853的帖子

为什么我的字符串函数返回clojure.lang.LazySeq@xxxxxx?

我使用leiningen REPL定义了以下3个函数:

(defn rand-int-range [floor ceiling] (+ floor (rand-int (- ceiling floor))))

(defn mutate-index
  "mutates one index in an array of char and returns the new mutated array"
  [source idx]
  (map
    #(if (= %1 idx)
       (char (+ (int %2) (rand-int-range -3 3)))
       %2)
    (iterate inc 0)
    source))

(defn mutate-string
  [source]
  (str
    (mutate-index
      (.toCharArray source)
      (rand-int (alength (.toCharArray source))))))
Run Code Online (Sandbox Code Playgroud)

当我运行时(mutate-string "hello"),而不是REPL打印出变异的字符串,它打印出clojure.lang.LazySeq@xxxxxx,其中'xxxxx'是一个随机的数字和字母序列.我希望它能打印出像"hellm"这样的东西吗?这真的像我想的那样给了我一个字符串吗?如果是,我如何让REPL向我显示该字符串?

clojure

14
推荐指数
2
解决办法
5457
查看次数

标签 统计

clojure ×1