Allow rest-patterns in pattern2 and prevent unification with nil
This commit is contained in:
parent
ff302d078a
commit
06a7bc3c60
@ -54,10 +54,16 @@
|
|||||||
;; If the patterns are already equal, the frame already
|
;; If the patterns are already equal, the frame already
|
||||||
;; has the correct bindings
|
;; has the correct bindings
|
||||||
(= pattern1 pattern2) frame
|
(= pattern1 pattern2) frame
|
||||||
|
;; Nothing should unify with nil
|
||||||
|
(or (nil? pattern1) (nil? pattern2)) :failed
|
||||||
;; If pattern1 is a rest-pattern (e.g. [& ?rest]), unify its rest
|
;; If pattern1 is a rest-pattern (e.g. [& ?rest]), unify its rest
|
||||||
;; part with pattern2 in the current frame
|
;; part with pattern2 in the current frame
|
||||||
(and (sequential? pattern1) (= (first pattern1) '&))
|
(and (sequential? pattern1) (= (first pattern1) '&))
|
||||||
(unify-match (second pattern1) pattern2 frame)
|
(unify-match (second pattern1) pattern2 frame)
|
||||||
|
;; If pattern2 is a rest-pattern, unify its rest part with pattern1
|
||||||
|
;; in the current frame
|
||||||
|
(and (sequential? pattern2) (= (first pattern2) '&))
|
||||||
|
(unify-match (second pattern2) pattern1 frame)
|
||||||
;; If pattern1 is a variable, try to bind it to pattern2
|
;; If pattern1 is a variable, try to bind it to pattern2
|
||||||
(var? pattern1) (extend-if-possible pattern1 pattern2 frame)
|
(var? pattern1) (extend-if-possible pattern1 pattern2 frame)
|
||||||
;; If pattern1 is not a variable but pattern2 is, try to bind
|
;; If pattern1 is not a variable but pattern2 is, try to bind
|
||||||
|
Loading…
Reference in New Issue
Block a user