fork download
  1. ; your code goes here
  2. (defun match (pattern string)
  3. (let ((i 0)
  4. (len (length string))
  5. star)
  6. (loop
  7. for c across pattern
  8. do
  9. (when (= i len)
  10. (return-from match))
  11. (case c
  12. (#\* (setf star t))
  13. (#\? (incf i))
  14. (otherwise (if star
  15. (loop while (and (< i len) (not (eql c (elt string i))))
  16. do (incf i)
  17. finally (incf i) (setf star nil))
  18. (if (eql c (elt string i))
  19. (incf i)
  20. (return-from match))))))
  21. (= i len)))
  22.  
  23. (loop :for (s r) :on '("aababbcd" t
  24. "abcd" nil
  25. "aa?bxcxd" nil) :by #'cddr
  26. :for x := (match "a?*bb*cd" s) :do
  27. (format t "~:[FAIL~;OK~] ~:S: expected ~:[false~;true~]~%" (eql r x) s r))
  28.  
Runtime error #stdin #stdout #stderr 0.01s 10560KB
stdin
Standard input is empty
stdout
FAIL "aababbcd": expected true
stderr
*** - ELT: index 5 for "abcd" is out of range