You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Lisp中无引号输出字符串且不返回任何值?求详细教程

Great question! Let's tackle your two main concerns one by one—first, getting that quote-free output without a visible return value, then pointing you to some solid Lisp resources.

Your Output Question

The Short Version

Strictly speaking, Common Lisp doesn’t have "no-return-value" operations—every expression must evaluate to at least one value (even nil). But you can make it look like there’s no return value in the REPL, while still printing your string without quotes.

Here’s how to do it:

(progn (format t "Hello world~%") (values))

Or using write-string (which outputs the string directly without formatting overhead):

(progn (write-string "Hello world" *standard-output*) (values))

In most Common Lisp REPLs (like SBCL, Clozure CL), this will print your string and show nothing as the return value—because (values) with no arguments returns zero values, which REPLs typically don’t display.

Why format t Returns nil

format is designed to return nil when you use t as the destination (which points to *standard-output*). This is part of the language specification—format only returns a string if you pass nil as the destination (to build a string instead of printing it).

If you just run (format t "Hello world~%"), the REPL will print your string and show nil as the return value. The progn + values trick suppresses that visible return value by replacing nil with zero values.

Looking for detailed, thorough resources? Here are some classics that cover everything from basics to advanced topics:

  • Common Lisp: A Gentle Introduction to Symbolic Computation: Perfect for total beginners. It walks you through Lisp’s core concepts step by step, with plenty of examples and exercises to reinforce what you learn.
  • Practical Common Lisp: A hands-on guide that focuses on building real things. It’s great if you want to move past theory and start writing useful code quickly, with chapters on topics like web development, databases, and more.
  • On Lisp: Once you’ve got the basics down, this book dives deep into macros, functional programming, and advanced Lisp techniques. It’s a must-read if you want to master Lisp’s unique power.
  • ANSI Common Lisp: The authoritative reference for the language standard. It’s dense, but it covers every detail of Common Lisp—keep it handy when you need to look up precise syntax or behavior.

内容的提问来源于stack exchange,提问作者jakHunter

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 03:34:04