使用CL-WHO生成超文本标记语言的常用方法是使用宏with-html-output和with-html-output-to-string。这使用特殊的语法。例如:
(let ((id "greeting")
(message "Hello!"))
(cl-who:with-html-output-to-string (*standard-output*)
((:p :id id) message)))是否可以将数据((:p :id id) message)编写为列表,而不是使用上面所示的宏语法?例如,我想将HTML定义为如下列表:
(let* ((id "greeting")
(message "Hello!")
(the-html `((:p :id ,id) ,message)))
;; What should I do here to generate HTML using CL-WHO?
)CL-WHO能从一个普通的Lisp列表中产生HTML吗?
发布于 2021-11-15 09:06:55
您希望将代码插入到表达式中。
实际上,你需要eval:
(let* ((id "greeting")
(message "Hello!")
(the-html `((:p :id ,id) ,message)))
(eval `(cl-who:with-html-output-to-string (*standard-output*)
,the-html)))但这并不适合使用eval。但是宏包含一个隐含的eval。我会为此定义一个宏,并调用该宏:
(defun html (&body body)
`(cl-who:with-html-output-to-string (*standard-output*)
,@body))
;; but still one doesn't get rid of the `eval` ...
;; one has to call:
(let* ((id "greeting")
(message "Hello!")
(the-html `((:p :id ,id) ,message)))
(eval `(html ,the-html)))https://stackoverflow.com/questions/69969577
复制相似问题