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"))))))