Skip to content

Instantly share code, notes, and snippets.

@weissjeffm
Created June 10, 2019 16:56
Show Gist options
  • Save weissjeffm/05ae315f6d34c13d1e645efea599f3e0 to your computer and use it in GitHub Desktop.
Save weissjeffm/05ae315f6d34c13d1e645efea599f3e0 to your computer and use it in GitHub Desktop.
match fn
(defn match [pattern input-string]
(loop [[[op op-arg alt] :as pattern] pattern [chr :as input-string] input-string]
(if op
(let [res (case op
:req (= op-arg chr)
:opt (if (= op-arg chr)
true
:next)
:alt (or (= op-arg chr)
(= alt chr)))]
(and res (recur (rest pattern) (if (= res :next)
input-string
(rest input-string)))))
(not chr))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment