cl-who和format

mgs*_*mgs 2 lisp sbcl common-lisp hunchentoot cl-who

我正在尝试使用cl-who生成以下html代码:

<html>
<body>
<div id="cnt_1"></div>
<div id="cnt_2"></div>
<div id="cnt_3"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

这是我认为可行的代码:

(with-html-output-to-string (*standard-output* nil)
 (:html
  (:body
   (do ((cnt 1 (+ cnt 1)))
       ((> cnt 3))
     (htm (:div :id (format t "cnt_~A" cnt)))))))
Run Code Online (Sandbox Code Playgroud)

但我得到以下输出:

<html><body><divcnt_1></div><divcnt_2></div><divcnt_3></div></body></html>
Run Code Online (Sandbox Code Playgroud)

似乎:id不能与函数调用一起使用.这是否意味着我不能在cl-who中使用格式?我应该用什么呢?

Dai*_*rod 5

那是因为你不想直接在流中写.

CL-USER> (with-html-output-to-string (s) (:div :id "test"))
"<div id='test'></div>"

CL-USER> (with-html-output-to-string (s)
           (:html
            (:body
             (do ((cnt 1 (+ cnt 1)))
                 ((> cnt 3))
               (htm (:div :id (format nil "cnt_~A" cnt)))))))

"<html><body><div id='cnt_1'></div><div id='cnt_2'></div><div id='cnt_3'></div></body></html>"
Run Code Online (Sandbox Code Playgroud)

顺便说一句,如果你想直接在流中写,请使用CL-WHO:FMT.