设置,让,宏,螺母 [英] set, let, macros, nuts
问题描述
我正在尝试从html内容构建快速目录. (简而言之)
I am trying to build a quick toc from an html content. (to make it short)
代码简直太简单了:
(defn toc [content]
(doseq [i (take 5 (iterate inc 1))]
(let [h (str "h" i)]
(println ($ content h)))))
其中 content 是html内容, $ 是 clojure-soup
where content is the html content, and $ is a macro required from clojure-soup
而
($ content "h1")
起作用,并返回所有标签的列表.
works, and returns a list of all the tags.
简单:
($ content (str "h" 1))
我不会做任何事情.
我如何强制
(str "h" 1)
要在之前正确评估 宏被称为?
奖励原因:)
推荐答案
如果您暗示$
是宏,则这是不可能的:这根本不是宏的工作方式.宏需要在编译时扩展为某种东西,并且只能扩展一次.您具有运行时数据,例如h
的各种值,但是无法在编译时使用它.对我来说,听起来$
应该是一个函数.
This is not possible if, as you imply, $
is a macro: it's simply not how macros work. The macro needs to expand into something, at compile time, and it can only do so once. You have run-time data, like the various values of h
, but there is no way to use that at compile-time. To me it sounds like $
should have been a function.
这篇关于设置,让,宏,螺母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!