Created
June 10, 2019 16:56
-
-
Save weissjeffm/05ae315f6d34c13d1e645efea599f3e0 to your computer and use it in GitHub Desktop.
match fn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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