【问题标题】:suppress output in REPL抑制 REPL 中的输出
【发布时间】:2017-03-18 16:32:21
【问题描述】:

当调用返回某些内容的函数时,REPL 会打印输出。如何在不求助于临时添加nil 作为函数的最后一行的情况下抑制这种打印?

【问题讨论】:

  • 为什么需要这样的功能?是输出太大还是其他原因?

标签: clojure read-eval-print-loop


【解决方案1】:

这很容易做到。例如,如果您有一个名为 f 的函数,那么如您所知,您可以这样调用它:

(f)
;; hello yes this is f
;;=> :huge

但如果你想忽略输出,你可以这样做:

(do (f) nil)
;; hello yes this is f
;;=> nil

如果您愿意,也可以定义一个 ignore 函数来为您执行此操作:

(def ignore (constantly nil))

(ignore (f))
;; hello yes this is f
;;=> nil

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2016-03-07
  • 1970-01-01
  • 2012-03-09
  • 2011-10-28
  • 2013-11-19
  • 1970-01-01
相关资源
最近更新 更多