Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/nodely/syntax.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
10 changes: 10 additions & 0 deletions test/nodely/syntax_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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"))))))
Comment on lines +225 to +230