From 4ca6fb5ab65c41902f0204714c113dce9e657683 Mon Sep 17 00:00:00 2001 From: Felipe Fernandes Date: Mon, 3 Aug 2026 19:29:45 -0300 Subject: [PATCH] fix: collect expression symbols with symbol? Filter tree leaves with symbol? instead of (complement seqable?) so non-symbol atoms are never treated as ?-inputs. Fixes #59 Signed-off-by: Felipe Fernandes --- src/nodely/syntax.clj | 6 +++++- test/nodely/syntax_test.clj | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/nodely/syntax.clj b/src/nodely/syntax.clj index 08ebacf..f3d0e9c 100644 --- a/src/nodely/syntax.clj +++ b/src/nodely/syntax.clj @@ -6,8 +6,12 @@ [nodely.data :as data])) (defn- expression-symbols + "Collect symbols that appear as leaves in `expr`. + + Uses `symbol?` (not `(complement seqable?)`) so non-symbol atoms such as + numbers, keywords, and strings are excluded before later `?`-prefix filtering." [expr] - (set (filter (complement seqable?) (tree-seq seqable? seq expr)))) + (set (filter symbol? (tree-seq seqable? seq expr)))) (defn- question-mark->keyword [s] diff --git a/test/nodely/syntax_test.clj b/test/nodely/syntax_test.clj index 2107fc5..dfdfa00 100644 --- a/test/nodely/syntax_test.clj +++ b/test/nodely/syntax_test.clj @@ -218,3 +218,13 @@ :process-node #::data{:type :value :value ifn?}} (>sequence inc ?foo/bar))))) + +(deftest expression-symbols-collects-only-symbols + ;; #59: leaves must be filtered with `symbol?`, not `(complement seqable?)`, + ;; so non-symbol atoms are never treated as `?`-inputs. + (testing "numbers and keywords in an expression do not become inputs" + (is (match? #::data{:type :leaf :inputs #{:x} :fn ifn?} + (>leaf (+ ?x 1 :not-an-input))))) + (testing "only `?`-prefixed symbols become inputs" + (is (match? #::data{:type :leaf :inputs #{:y} :fn ifn?} + (>leaf (str ?y "suffix"))))))