lisp - 学习口语。为什么 NIL 在函数结束后使用 if 语句打印出来

标签 lisp common-lisp clisp

嗨新手在这里尝试学习 lisp,我对为什么 lisp 在我的输出末尾打印 NIL 感到困惑?有没有办法让它不打印 NIL 或者我的 if 语句设置不正确。

(defun greater (x) 
  (if (> x 4) 
    (message "number is greater than 4")))

得到结果:

    [2]> (square 10)
    number greater than 4
    NIL

最佳答案

所有顶级表单都由 Read-Eval-Print-Loop 打印。以下是如何避免它:

;;; make a main function
(defun main () 
  ;; all your program top level forms here!
  (values)) ; empty values return no value and the REPL will not print anything when your program terminates

;; call main
(main)

当然,在交互式 session 中,您希望打印出结果,这样您就可以输入 (+ 2 3) 并返回 5 而不必将其包装在打印语句。

关于lisp - 学习口语。为什么 NIL 在函数结束后使用 if 语句打印出来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46517001/

相关文章:

lisp - 如何在 lisp 中解决赋值问题

lisp - 如何使用 lisp (clisp) 创建和使用库?

macros - Lisp:在宏中扩展属性名称

lisp - Common Lisp 中的 '() 与 ()

lisp - Lisp 中的 OpenDocument 操作

带有 usocket 库的 Common Lisp 中的 WebSocket 客户端

lisp - 如何从 Lisp 类导出槽和访问器?

lisp - 关闭普通 lisp 中的结果打印

documentation - Common Lisp 的 Man 或 javadoc 风格的文档

coding-style - 此 Clojure 代码缩进正确吗?