假设我已经为CL-WHO定义了一个宏:
(defmacro test-html (&body body)
`(with-html-output-to-string (*standard-output* nil :PROLOGUE t :indent t)
(:html
(:body
,@body))))然后:
(test-html (:h1 "hallo"))给出(删除第一行):
"<html>
<body>
<h1>
hallo
</h1>
</body>
</html>"不出所料。现在,我已经定义了一个函数来生成供CL-WHO使用的s-expression:
(defun test-header (txt)
`(:h1 ,txt))当使用"hallo“调用时,返回
(:h1 "hallo")但现在当我打电话给
(test-html (test-header "hallo"))它返回:
"<html>
<body>
</body>
</html>"哪里出了问题,原因是什么?
发布于 2012-04-13 03:11:16
我倾向于通过定义一个快捷宏来解决这个问题,比如
(defmacro html-to-stout (&body body)
"Outputs HTML to standard out."
`(with-html-output (*standard-output* nil :indent t) ,@body))或字符串等效项。这里的关键是它不输出:prologue,所以它可以输出HTML chunklet而不是整个页面。一旦你得到了它,你就可以像这样做
(defun test-header (text)
(html-to-stout
(:h1 (str text))))
(test-html (test-header "Hello Hello"))发布于 2012-04-12 21:25:53
我也有同样的问题。我所能搜索到的是,这在cl的官方版本中是不可能的:http://lisp-univ-etc.blogspot.com/2009/03/cl-who-macros.html
我使用的是这个版本,它支持宏:https://github.com/vseloved/cl-who
https://stackoverflow.com/questions/10124227
复制相似问题