我正在尝试使用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中使用格式?我应该用什么呢?
我正在学习Common Lisp,想要玩lisp和web开发.我目前的问题来自一个简单的想法,迭代我想要包括的所有JavaScript文件.我使用SBCL和Quicklisp进行快速启动.问题可能与cl-who我正在使用的包有关.
所以我宣布了我的包,并开始这样:
(defpackage :0xcb0
(:use :cl :cl-who :hunchentoot :parenscript))
(in-package :0xcb0)
Run Code Online (Sandbox Code Playgroud)
为了简单起见,我减少了我的问题功能.所以我有这个page功能:
(defun page (test)
(with-html-output-to-string
(*standard-output* nil :prologue nil :indent t)
(:script
(:script :type "text/javascript" :href test))))
Run Code Online (Sandbox Code Playgroud)
这将产生所需的输出
*(0xcb0::page "foo")
<script>
<script type='text/javascript' href='foo'></script>
</script>
Run Code Online (Sandbox Code Playgroud)
现在我已经创建了一个生成:script标签的宏.
(defmacro js-source-file (filename)
`(:script :type "text/javascript" :href ,filename)))
Run Code Online (Sandbox Code Playgroud)
这按预期工作:
*(macroexpand-1 '(0XCB0::js-source-file "foo"))
(:SCRIPT :TYPE "text/javascript" :HREF "foo")
Run Code Online (Sandbox Code Playgroud)
但是,如果我将此包含在我的page函数中:
(defun page (test)
(with-html-output-to-string
(*standard-output* nil :prologue nil :indent t)
(:script
(js-source-file "foo"))))
Run Code Online (Sandbox Code Playgroud)
... undefined function: …
我正在使用 cl-who (通过 hunchentoot),到目前为止完全成功,但有一件事我无法弄清楚,而且我的解决方法很丑陋,所以我希望有一个简单的解决方案。我的 hunchentoot 简单处理程序调用的函数如下所示:
(defun foo ()
(with-html-output-to-string
(*standard-output* nil :prologue t)
(:html
(:body (htm :br :hr "foo" :hr ...etc...))))
Run Code Online (Sandbox Code Playgroud)
一切都很好。
然而,当我想从 foo 中调用辅助函数来执行...无论我想要执行什么子工作时,我不知道如何使 CL-WHO 的 HTM 上下文执行该调用。例如,这工作正常:
(defun foo ()
(with-html-output-to-string
(*standard-output* nil :prologue t)
(:html
(:body (htm :br :hr "foo" :hr (bar)))))
(defun bar ()
(format t "This will show up in the html stream"))
Run Code Online (Sandbox Code Playgroud)
但这不起作用:
(defun bar ()
(with-html-output-to-string
(*standard-output* nil :prologue t)
(htm "This will NOT show up in the html stream")))
Run Code Online (Sandbox Code Playgroud)
(我已经尝试过各种操作,但无济于事。)
我确信我正在做一些简单的错误;必须在任何 …