我试图通过hunchentoot和cl-who建立一个个人网站,但我在以下代码中出现了一个语义错误:
(defun index ()
(standart-page (:title "~apb")
(dolist (article (articles))
(cl-who:htm
(:ul
(:li (format nil "~a: ~a" (article-date article) (article-title article))))))))"standart-page“是一个宏:
(defmacro standart-page ((&key title) &body body) `(cl-who:with-html-output-to-string (*standart-output* nil :prologue t :indent t)
(:html :xmlns "http://www.w3.org/1999/xhtml"
:xml\:lang "de"
:lang "de"
(:head
(:title ,title)
(:body
(:div :id "wrapper"
(:div :id "header"
(:h1 "~apb"))
(:div :id "content"
,@body)))))))对"(index)“的评估(在”(文章)“中有一篇测试文章返回:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='de' lang='de'>
<head>
<title>
~apb
</title>
<body>
<div id='wrapper'>
<div id='header'>
<h1>
~apb
</h1>
</div>
<div id='content'>
<ul>
<li>
</li>
</ul>
</div>
</div>
</body>
</head>
</html>通过查看<li>..</li>标记,我想知道为什么没有输出。我认为格式功能有问题,但我不知道是什么原因。
发布于 2010-12-16 20:43:32
看看CL-WHO网站上的用法示例,我认为你不能只做一个返回字符串的格式。他们的所有示例都使用自定义输出函数(例如fmt),这些函数看起来像是在幕后写入动态变量。在CL-WHO生成的代码示例中,您可以看到这是宏展开中的(format http-output-stream ....)行。
这就解释了为什么你没有得到任何输出,你只需要使用他们的自定义输出编写器,而不是你正在使用的(format nil ..)。你可能想要像这样的东西
(fmt "~a: ~a" (article-date article) (article-title article))
发布于 2010-12-17 19:25:37
特别是对于format,安德鲁的答案是正确的。通常,您可以使用str
CL-USER> (with-html-output-to-string (*standard-output*)
(:p (str (format nil "~A" '<hello/>))))
"<p><HELLO/></p>"请注意,在本例中,字符串不是HTML转义的(这也适用于fmt )。如果您希望它是这样的,请改用esc:
CL-USER> (with-html-output-to-string (*standard-output*)
(:p (esc (format nil "~A" '<hello/>))))
"<p><HELLO/></p>"同样,在退出HTML模式后,使用htm返回模式:
CL-USER> (with-html-output-to-string (*standard-output*)
(:ul (loop for x from 1 to 3
do (htm (:li (str x))))))
"<ul><li>1</li><li>2</li><li>3</li></ul>"发布于 2010-12-16 23:22:47
一个明显的错误是你拼写错了"standard“。因此,将流绑定到*standart-output* (sic)并不会像您希望的那样重新绑定*standard-output*。
https://stackoverflow.com/questions/4460772
复制相似问题