[英]How to output a string in lisp without quotes and without returning anything?
REPL打印它執行的每個表達式的值
如果您使用READ EVAL PRINT LOOP,則REPL將打印結果。 這就是為什么它被稱為讀取評估打印循環。
但是輸出函數本身不會打印其結果。
CL-USER 1 > (format t "hello")
hello ; <- printed by FORMAT
NIL ; <- printed by the REPL
CL-USER 2 > (format t "world")
world ; <- printed by FORMAT
NIL ; <- printed by the REPL
現在結合以上內容:
CL-USER 3 > (defun foo ()
(format t "hello")
(format t "world"))
FOO
CL-USER 4 > (foo)
helloworld ; <- printed by two FORMAT statements
; as you can see the FORMAT statement did not print a value
NIL ; <- the return value of (foo) printed by the REPL
如果不返回任何值,則REPL將不打印任何值。
CL-USER 5 > (defun foo ()
(format t "hello")
(format t "world")
(values))
FOO
CL-USER 6 > (foo)
helloworld ; <- printed by two FORMAT statements
; <- no return value -> nothing printed by the REPL
您可以在沒有REPL的情況下執行Lisp代碼
如果您使用沒有REPL的Lisp,則無論如何都不會打印任何值:
$ sbcl --noinform --eval '(format t "hello world~%")' --eval '(quit)'
hello world
$
另外,您可以讓Lisp執行Lisp文件:
$ cat foo.lisp
(format t "helloworld~%")
$ sbcl --script foo.lisp
helloworld
$
實際的命令行是特定於實現的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.