Lisp cl格式谁做';我不能正常工作
我正试图通过hunchentoot和cl who建立一个个人网站,但我在以下代码中出现了语义错误:Lisp cl格式谁做';我不能正常工作,lisp,format,hunchentoot,Lisp,Format,Hunchentoot,我正试图通过hunchentoot和cl who建立一个个人网站,但我在以下代码中出现了语义错误: (defun index () (standart-page (:title "~apb") (dolist (article (articles)) (cl-who:htm (:ul (:li (format nil "~a: ~a" (a
(defun index ()
(standart-page (:title "~apb")
(dolist (article (articles))
(cl-who:htm
(:ul
(:li (format nil "~a: ~a" (article-date article) (article-title article))))))))
“标准页面”是一个宏:
(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)))))))
对“(索引)”的评估(在“(文章”中有一篇测试文章)返回:
~apb
~apb
-
通过查看
。
标记,我想知道为什么没有输出。我认为format函数有问题,但我不知道是什么原因。查看CL-WHO网站上的使用示例,我不认为您可以只使用返回字符串的格式。他们所有的示例都使用自定义输出在CL-WHO生成的代码示例中,您将其视为宏展开中的(格式化http输出流…)
行
这可以解释为什么您没有得到任何输出,您只需要使用他们的自定义输出编写器,而不是您正在使用的(格式为nil..)
(fmt“~a:~a”(文章日期文章)(文章标题文章))
一个明显的错误是您错误地拼写了“标准”。因此,将流绑定到*标准输出*
(sic)不会像您可能希望的那样重新绑定*标准输出*
。对于格式
具体来说,Andrew的答案是正确的。一般来说,您可以使用str
:
CL-USER> (with-html-output-to-string (*standard-output*)
(:p (str (format nil "~A" '<hello/>))))
"<p><HELLO/></p>"
类似地,使用htm
在退出HTML模式后返回HTML模式:
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>"
CL-USER>(html输出为字符串(*标准输出*)
(:ul(从1到3的x循环
do(htm(:li(str x‘‘‘‘‘‘)’))
“- 1
- 2
- 3
”
好的,谢谢,但它给了我一个错误“Undefined function FMT”。我不确定,但你能告诉我它在哪个软件包中吗。(我没有发现任何有用的东西)我想应该是在packagecl-who
中。在您自己的包定义中使用package,或者尝试使用cl-who:fmt
。我已经有一段时间没有和cl-who
打交道了,但是IIRCfmt
不是一个函数。它只是一个符号,并且只有在带有html输出的扩展中才有意义.
CL-USER> (with-html-output-to-string (*standard-output*)
(:p (esc (format nil "~A" '<hello/>))))
"<p><HELLO/></p>"
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>"