fork(1) download
  1. (defn tails [s]
  2. (take (count s) (reductions (fn [s _] (rest s)) s s)))
  3.  
  4. (defn match[p s]
  5. (cond
  6. (empty? p) true
  7. (empty? s) false
  8. :else
  9. (case (first p)
  10. \* (some (partial match (rest p)) (tails s))
  11. \? (recur (rest p) (rest s))
  12. \\ (and (= (ffirst p) (first s))
  13. (recur (drop 2 p) (rest s)))
  14. (and (= (first p) (first s))
  15. (recur (rest p) (rest s))))))
  16.  
  17. (print (time (match "as*d*?qwe*qwe" "as123dssqwe12345678qwe")))
  18. (print (time (match "as*d*?qwe*qw" "as123dssqwe12345678qwe")))
Success #stdin #stdout 2.05s 335552KB
stdin
Standard input is empty
stdout
"Elapsed time: 2.61513 msecs"
true"Elapsed time: 0.268433 msecs"
true