Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 2.13 KB | None | 0 0
  1. (defun match (p s binds)
  2.     (let ( (temp nil) )
  3.         (cond ((atom p) (cond ((equal p s) (list t binds))
  4.                             (t (list nil nil))
  5.                         )
  6.                 )
  7.             ((equal (first p) '?) (setf temp (test-binds (second p) s binds))
  8.                 (cond (temp (list t temp))
  9.                     (t (list nil nil))
  10.                 )
  11.             )
  12.             ((atom s) (list nil nil))
  13.             (t
  14.             ; both p and s are lists
  15. ;upcoming modification to match5-
  16. ; 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.
  17. ; 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))
  18. ; 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
  19.  
  20.                 (if (not (atom (first s)))
  21.                     (cond ((atom (first p)) (or (first (match p (first s) binds)) (first (match p (rest s) binds))) )
  22.                         ((not (atom (first p))) (or (first (match (first p) s binds)) (first(match (rest p) s binds))))
  23.                         (t (nil))
  24.                     )
  25.                 )
  26.                 (if (not (atom (first p)))
  27.                     (if (atom (first s))
  28.                         (or (match (first p) s binds) (match (rest p) s binds))
  29.                     )
  30.                 )
  31.                 ; continuation of normal match5 here
  32.                 ((setf temp (match (first p) (first s) binds))
  33.                     ; temp = (flag binds)
  34.                     (cond ((first temp)
  35.                         ; (first p) and (first s) match
  36.                         (match (rest p) (rest s) (second temp)))
  37.                         (t (list nil nil))
  38.                     )
  39.                 )
  40.             )
  41.         )
  42.     )
  43. )
  44. (defun test-binds (x v binds)
  45. ;; returns nil or the binds updated by the addition of the pair (x v)
  46.     (let ( (y nil) )
  47.         (setf y  (assoc x binds))
  48.         (cond (y (cond ((equal (second y) v) binds)
  49.                 (t nil)))
  50.             (t (setf binds (append binds (list (list x v))))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement