Last active
August 29, 2015 14:12
-
-
Save devrimbaris/a140e416ff3efb23b5fe to your computer and use it in GitHub Desktop.
How to define functions out of string...
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 run-rule-one-argument | |
"Assumes rule is defined in string like "zero? b." | |
[rule-string & args] | |
(let [parsed (stri/split rule-string #" ") | |
rulefn (resolve (symbol (first parsed)))] | |
(apply rulefn args))) | |
(run-rule-one-argument "zero?" 7) | |
(run-rule-one-argument "-" 9) | |
(defn run-rule-two-arguments | |
"Assumes rule is defined in string like "a > b." | |
[rule-string & args] | |
(let [parsed (stri/split rule-string #" ") | |
rulefn (resolve (symbol (second parsed)))] | |
(apply rulefn args))) | |
(run-rule-two-arguments "a > b" 5 7) | |
(run-rule-two-arguments "a > b" 75 7) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment