Last active
December 11, 2015 19:08
-
-
Save dabd/4646206 to your computer and use it in GitHub Desktop.
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
(ns test.core | |
(:require [clojure.string :as s])) | |
(defn expand-interval-test | |
[interval v] | |
(map (fn [s] | |
(cond (re-seq #"^\d+\.?\d*$" s) | |
`(<= ~v ~(Float/parseFloat s)) | |
(re-seq #"^(\d+\.?\d*)-(\d+\.?\d*)$" s) | |
(let [[_ x y] (first (re-seq #"^(\d+\.?\d*)-(\d+\.?\d*)$" s))] | |
`(and (>= ~v ~(Float/parseFloat x)) (<= ~v ~(Float/parseFloat y)))) | |
(re-seq #"^(\d+\.?\d*)\+$" s) | |
(let [[_ x] (first (re-seq #"^(\d+\.?\d*)\+$" s))] | |
`(>= ~v ~(Float/parseFloat x))) | |
(= "-" s) | |
`true | |
:else (throw (Exception. (str "Don't know how to parse this: " s))))) | |
(s/split interval #","))) | |
(defmacro interval-test-fn | |
[interval] | |
(let [v (gensym "v")] | |
`(fn [~v] | |
(or ~@(expand-interval-test interval v))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment