From d05d055ec3d3053263e0d35a46c24c225b3182ce Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Sat, 20 Jul 2019 14:38:21 -0400 Subject: [PATCH] Support the destructuring `&` syntax in queries --- src/sicp_logic/match.clj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/sicp_logic/match.clj b/src/sicp_logic/match.clj index ab66c8b..604d59b 100644 --- a/src/sicp_logic/match.clj +++ b/src/sicp_logic/match.clj @@ -54,6 +54,10 @@ ;; If the patterns are already equal, the frame already ;; has the correct bindings (= pattern1 pattern2) frame + ;; If pattern1 is a rest-pattern (e.g. [& ?rest]), unify its rest + ;; part with pattern2 in the current frame + (and (sequential? pattern1) (= (first pattern1) '&)) + (unify-match (second pattern1) pattern2 frame) ;; If pattern1 is a variable, try to bind it to pattern2 (var? pattern1) (extend-if-possible pattern1 pattern2 frame) ;; If pattern1 is not a variable but pattern2 is, try to bind