嗨新手在这里尝试学习 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/