Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defun match (p s binds)
- (let ( (temp nil) )
- (cond ((atom p) (cond ((equal p s) (list t binds))
- (t (list nil nil))
- )
- )
- ((equal (first p) '?) (setf temp (test-binds (second p) s binds))
- (cond (temp (list t temp))
- (t (list nil nil))
- )
- )
- ((atom s) (list nil nil))
- (t
- ; both p and s are lists
- ;upcoming modification to match5-
- ; if s is a list of lists, and p is a single list, then call match on the first list in s and the rest of s.
- ; if s is a list of lists, and p is a list of lists, call match on ((first p) (first s)) ((first p) (rest s)) ((rest p) (rest s)) and ((rest p) (first s))
- ; If p is a list of lists, and s is a single list, then call match on the first list in p and the rest of p
- (if (not (atom (first s)))
- (cond ((atom (first p)) (or (first (match p (first s) binds)) (first (match p (rest s) binds))) )
- ((not (atom (first p))) (or (first (match (first p) s binds)) (first(match (rest p) s binds))))
- (t (nil))
- )
- )
- (if (not (atom (first p)))
- (if (atom (first s))
- (or (match (first p) s binds) (match (rest p) s binds))
- )
- )
- ; continuation of normal match5 here
- ((setf temp (match (first p) (first s) binds))
- ; temp = (flag binds)
- (cond ((first temp)
- ; (first p) and (first s) match
- (match (rest p) (rest s) (second temp)))
- (t (list nil nil))
- )
- )
- )
- )
- )
- )
- (defun test-binds (x v binds)
- ;; returns nil or the binds updated by the addition of the pair (x v)
- (let ( (y nil) )
- (setf y (assoc x binds))
- (cond (y (cond ((equal (second y) v) binds)
- (t nil)))
- (t (setf binds (append binds (list (list x v))))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement