1 ; Wildcard Pattern matching algorithm
2 ; * matches any substring (zero or more characters)
3 ; ? matches any character
6 (defun match (pattern list
)
7 (labels ((match1 (pattern suspect
)
8 (cond ((null pattern
) (null suspect
))
9 ((null suspect
) (equal pattern
'(:mult
)))
10 ((eq (first pattern
) :single
)
11 (match1 (cdr pattern
) (cdr suspect
)))
12 ((eq (first pattern
) :mult
)
13 (if (null (rest pattern
))
15 (do ((p (rest pattern
))
17 ((or (null l
) (match1 p l
))
19 ((eq (first pattern
) (first suspect
))
20 (match1 (rest pattern
) (rest suspect
)))
23 (cond ((null list
) nil
)
24 ((eq (first list
) #\
*)
25 (cons :mult
(explode (rest list
))))
26 ((eq (first list
) #\?)
27 (cons :single
(explode (rest list
))))
28 ((eq (first list
) #\~
)
30 (explode (rest (rest list
)))))
31 (t (cons (first list
) (explode (rest list
)))))))
32 (let ((pat (explode (coerce pattern
'cons
))))
33 (mapcan #'(lambda (x) (when (match1 pat
(coerce x
'cons
))
37 (setq l
(sort (apply #'nconc
(map 'cons
38 #'(lambda (x) (mapcar #'string x
))