【问题标题】:cl-who: using a variable in with-html-output-to-stringcl-who:在 with-html-output-to-string 中使用变量
【发布时间】:2013-06-10 19:59:21
【问题描述】:

到目前为止我看到的所有cl-who 的例子都是这样工作的:

(with-html-output-to-string (s)
   (:HTML (:HEAD (:TITLE "hello")) (:BODY (:DIV "world"))))

效果很好。 但是,我想将 with-html-output-to-string 与变量一起使用,而不是硬编码的 html 树;如果*p*(:HTML (:HEAD (:TITLE "hello")) (:BODY (:DIV "world"))) 我这样做

(with-html-output-to-string (s)
   *p*)

我得到"" 结果。 我猜想with-html-output-to-string 是一个宏,它的最后一个参数永远不会被评估。 有什么办法可以解决这个问题吗?

【问题讨论】:

  • 我无法添加标签cl-who(不存在,没有足够的代表)。
  • 我唯一能想到的就是(eval `(with-html-output-to-string (s) ,*p*))。似乎没有 with-html-output-to-string 作为函数的实现。
  • 有一个特殊的结构:str - 见weitz.de/cl-who/#example
  • @VsevolodDyomkin 对我有用;如果你想把它放在答案中,我很乐意接受。

标签: macros common-lisp cl-who


【解决方案1】:

使用cl-who:str;查看http://weitz.de/cl-who/#example 的示例。

如果你这样做:

(with-html-output-to-string (s)
   (str *p*))

你会得到预期的输出。

【讨论】:

    【解决方案2】:

    将部分 html 树作为 lisp 形式传递不是 cl-who 中的预期方式,但您可以使用一些 cl-who 内部(申请 tree-to-commands)来编写一个小包装器。

    【讨论】:

    • 我发现使用cl-who:str 适合我的需要。还是谢谢。
    猜你喜欢
    • 2023-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-18
    • 2011-04-17
    • 2018-06-03
    • 1970-01-01
    • 2010-10-14
    相关资源
    最近更新 更多