 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; filter functions
 (defn add-filter 
-  [filter-str]
-  (swap! filters conj filter-str))
+  [profile filter-str]
+  (let [transformed-filter (replace-current-user-symbols profile filter-str)]
+    (if transformed-filter
+      (do
+        (swap! filters conj transformed-filter)
+        transformed-filter)
+      nil)))
 
 (defn vec-remove
   "remove elem in coll"

                    [:a {:on-click #(remove-filter idx)} [:i.material-icons "delete"]]
                    ]]) @filters)])

(defn Examples [filter-examples]
  [:ul.collection
   (map-indexed (fn [idx filter]
                  ^{:key filter}
                  [:li.collection-item filter [:a.secondary-content {:on-click #(add-filter filter)} [:i.material-icons "playlist_add"]]]) filter-examples)])

(defn Filters []
  (let [inputatm (atom "")]
    (fn []
      [:div
       [:h3 "Filters"]
       [Current-Filters inputatm]
       [New-Filter-Field inputatm]
       [:hr]
       [:h3 "Examples"]
       [:p "Here are some example filters to get you started!"]
       [Examples [
                  "(startsWith? :FirstName \"M\")" 
                  "(= :LaborRoleID \"APPLDEVL\")"
                  "(substring? :Title \"Quality\")"
                  "(= :KeyscanStatus \"In 4th Flr N\")"
                  "(or (startsWith? :FirstName \"M\") (substring? :Title \"Edit\"))"
                  ]]
       [:hr]
       [:h3 "References"]
       [Instructions]])))

(defn current-page []
  [:div [(session/get :current-page)]])

      (println "Error while evaluating string")
      (prn e))))

(defn replace-current-user-symbols
  "replaces keywords that are given in the form $keyword to the value of lookups to the given profile, e.g.
  the string \"(= :UserID $UserID)\" with the profile including {:UserID 123} will result in the string \"(= :UserID 123)\" "
  [profile expr]
  (let [$->kw (fn [kw] (->> kw str rest (apply str) keyword ))
        $? (fn [kw] (= \$ (first (str kw))))
        transform$ (fn [a] (if ($? a)
                            (get profile ($->kw a))
                            a))]
    (try
      (some->> expr
               (read-string)
               (walk/postwalk transform$)
               str)
      (catch :default e
        (prn 'replace-current-user-symbols e)))))

(defn create-filter-fn 
  "Creates a filter function of the form:
  (fn [user] expr-as-fn)
