【问题标题】:Error when entering decimal number in clojure repl在 clojure repl 中输入十进制数时出错
【发布时间】:2013-04-12 17:48:34
【问题描述】:

当我在 clojure repl 中输入 user> (* 10 .5) 时,我会收到以下消息:

CompilerException java.lang.RuntimeException: Unable to resolve symbol: .5 in this context, compiling:(NO_SOURCE_PATH:1:1)

我知道我可以做到这一点 (/ 10 2)(* 10 (/ 1 2))

谁能告诉我这里发生了什么?

我正在使用 clojure 1.5、emacs 和 nrepl

【问题讨论】:

    标签: clojure read-eval-print-loop


    【解决方案1】:

    clojure reader 使用 NNNN.NNNN 的形式表示双打。 .5 应该写成

    (* 10 0.5)
    

    作为旁注,它读作双精度,如果你想要一个浮点数,你必须强制它。

    . 开头的 var 名称非常好

    user> (def .im-a-normal-var 42)
    #'user/.im-a-normal-var
    user> .im-a-normal-var
    42
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-16
      相关资源
      最近更新 更多