점점점과 빈 리스트는 맞음
This commit is contained in:
1 parent
2ae6f1b3e5
commit
5fb7442dd6
2 files changed
+93
-20
No files matched your search
@@ -68,6 +68,18 @@
|
||||
(or (= '... x)
|
||||
(and (scm/syntax? x) (-> x scm/syntax-e ellipsis?))))
|
||||
|
||||
(defn pattern-vars [pattern]
|
||||
;; 안 예쁘는데ㅠㅠ
|
||||
(let [vs (atom #{})]
|
||||
(walk/prewalk (fn [x]
|
||||
(when (and (scm/identifier? x)
|
||||
(not (wildcard? x))
|
||||
(not (ellipsis? x)))
|
||||
(swap! vs #(conj % x)))
|
||||
x)
|
||||
pattern)
|
||||
@vs))
|
||||
|
||||
(defn unify [pattern datum]
|
||||
(match [(scm/syntax-e pattern) (scm/syntax-e datum)]
|
||||
[(_ :guard wildcard?) _] {}
|
||||
@@ -79,13 +91,22 @@
|
||||
|
||||
[([p (_ :guard ellipsis?) & ps] :seq)
|
||||
(ds :guard seq?)]
|
||||
(let [ds-end (take-last (count ps) ds)
|
||||
ds-start (drop-last (count ps) ds)]
|
||||
(let [ds-end (or (take-last (count ps) ds)
|
||||
(list))
|
||||
ds-start (or (drop-last (count ps) ds)
|
||||
(list))]
|
||||
(merge-unify
|
||||
(some->> ds
|
||||
(map #(some-> (unify p %)
|
||||
(update-vals list)))
|
||||
(apply merge-unify-with concat)
|
||||
(apply merge-unify-with concat
|
||||
;; 여기에 이 map이 없으면 ds 빌 때 `unify`는
|
||||
;; {}을 생성할 잘못되게 것이다. 그때
|
||||
;; variable들은 bound을 안 될 것이다. 대신에
|
||||
;; empty ellipsis로 bind해야 한다.
|
||||
(into {}
|
||||
(for [v (pattern-vars p)]
|
||||
[(scm/syntax-e v) (list)])))
|
||||
(map (fn [[k v]]
|
||||
[k [:ellipsis v]]))
|
||||
(into {}))))
|
||||
|
||||
Reference in new issue
Block a user