From 5fbe78a34ea6e34627c2696b108d4695d04a0862 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Tue, 4 Mar 2025 19:52:28 +0100 Subject: [PATCH] wip --- notebooks/macro_auto_gensym.clj | 6 ++++++ notebooks/macro_with_auto_gensym.clj | 5 +++++ src/nextjournal/clerk/analyzer.clj | 4 ++++ src/nextjournal/clerk/eval.clj | 1 + test/nextjournal/clerk/analyzer_test.clj | 2 ++ 5 files changed, 18 insertions(+) create mode 100644 notebooks/macro_auto_gensym.clj create mode 100644 notebooks/macro_with_auto_gensym.clj diff --git a/notebooks/macro_auto_gensym.clj b/notebooks/macro_auto_gensym.clj new file mode 100644 index 000000000..4a3341bd9 --- /dev/null +++ b/notebooks/macro_auto_gensym.clj @@ -0,0 +1,6 @@ +(ns macro-auto-gensym + (:require [macro-with-auto-gensym :as m])) + +;; Q: when I change my/macro and re-eval the notebook, should it render the change? + +(inc (m/my-macro 1)) diff --git a/notebooks/macro_with_auto_gensym.clj b/notebooks/macro_with_auto_gensym.clj new file mode 100644 index 000000000..2753a8ca7 --- /dev/null +++ b/notebooks/macro_with_auto_gensym.clj @@ -0,0 +1,5 @@ +(ns macro-with-auto-gensym) + +(defmacro my-macro [x] + `(let [x# ~x] + (inc x#))) diff --git a/src/nextjournal/clerk/analyzer.clj b/src/nextjournal/clerk/analyzer.clj index fe6bc7620..17623c79b 100644 --- a/src/nextjournal/clerk/analyzer.clj +++ b/src/nextjournal/clerk/analyzer.clj @@ -445,6 +445,10 @@ ([state file] (analyze-doc state (parser/parse-file {} file)))) +(comment + (analyze-file *file*) + ) + (defn unhashed-deps [->analysis-info] (remove deref? (set/difference (into #{} (mapcat :deps) diff --git a/src/nextjournal/clerk/eval.clj b/src/nextjournal/clerk/eval.clj index e7ed465d5..4099a87c0 100644 --- a/src/nextjournal/clerk/eval.clj +++ b/src/nextjournal/clerk/eval.clj @@ -122,6 +122,7 @@ ([store ns name val] (record-interned-symbol store ns name) (core-intern ns name val))) (defn ^:private eval+cache! [{:keys [form var ns-effect? no-cache? freezable?] :as form-info} hash digest-file] + (prn :form form) (try (let [!interned-vars (atom #{}) {:keys [result]} (time-ms (binding [config/*in-clerk* true] diff --git a/test/nextjournal/clerk/analyzer_test.clj b/test/nextjournal/clerk/analyzer_test.clj index 4646bebdb..0f2ce761b 100644 --- a/test/nextjournal/clerk/analyzer_test.clj +++ b/test/nextjournal/clerk/analyzer_test.clj @@ -101,6 +101,8 @@ (ana/analyze '(do inc)))) (is (empty? (:deps (ana/analyze '(do 'inc)))))) + (ana/analyze `(let [a# 1])) + (testing "locals that shadow existing vars shouldn't show up in the deps" (is (= #{'clojure.core/let} (:deps (ana/analyze '(let [+ 2] +))))))