Clojure:有没有人创建了一个可视化代码树结构的工具?

时间:2018-05-04 23:03:19

标签: clojure lisp visualization

我正在学习Clojure(我的第一个LISP)并且在学习LISP固有的“代码作为数据”的想法时,我很好奇是否有人曾经构建过一个可以读取程序并构建抽象的工具可视化器中的语法树 - 可能是前后宏扩展?

通过这个,我的意思是像SVG这样的树的图形描述。

1 个答案:

答案 0 :(得分:2)

真的,你所要做的只是' (quote)一个表格来获得它的AST。这就是lisps的美丽。假设您有标准// Check Collision if (this.collision(nx, ny) == true) { this.props.actions.myCustomAction(this.props.auth, snake.stage.score return; } 功能:

every?

只需引用它即可获得嵌套的符号列表:

(defn every?
  "Returns true if (pred x) is logical true for every x in coll, else
   false."
  {:tag Boolean
   :added "1.0"
   :static true}
  [pred coll]
  (cond
     (nil? (seq coll)) true
     (pred (first coll)) (recur pred (next coll))
     :else false))

通过使用标准; Notice the quote at the start! '(defn every? "Returns true if (pred x) is logical true for every x in coll, else false." {:tag Boolean :added "1.0" :static true} [pred coll] (cond (nil? (seq coll)) true (pred (first coll)) (recur pred (next coll)) :else false)) => (defn every? "Returns true if (pred x) is logical true for every x in coll, else\nfalse." {:tag Boolean, :added "1.0", :static true} [pred coll] (cond (nil? (seq coll)) true (pred (first coll)) (recur pred (next coll)) :else false)) 函数(缩进表示嵌套)可以对其进行可视化以进行可视化:

clojure.pprint/pprint

你可以通过在(clojure.pprint/pprint '(defn every? "Returns true if (pred x) is logical true for every x in coll, else false." {:tag Boolean :added "1.0" :static true} [pred coll] (cond (nil? (seq coll)) true (pred (first coll)) (recur pred (next coll)) :else false))) (defn every? "Returns true if (pred x) is logical true for every x in coll, else\n false." {:tag Boolean, :added "1.0", :static true} [pred coll] (cond (nil? (seq coll)) true (pred (first coll)) (recur pred (next coll)) :else false)) 打电话来获得后宏观扩展表示:

macroexpand

如果你正在寻找超过这个的东西,引用一些代码然后以递归方式对它进行搜索是微不足道的。您可以将其更改为您想要的任何格式。

相关问题