Skip to content

Instantly share code, notes, and snippets.

@liquidz
Last active December 15, 2015 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liquidz/5285315 to your computer and use it in GitHub Desktop.
Save liquidz/5285315 to your computer and use it in GitHub Desktop.
(ns fuga.core
(:require
[evalive.core :refer [evil]]
[clojure.string :as str]))
(defn- to-sym [x]
(symbol (name x)))
(defn- key-map->sym-map [m]
(into {} (map (fn [[k v]] [(to-sym k) v]) m)))
(defn render [s data]
(let [m (key-map->sym-map data)]
(str/replace s #"\((\(.+?\))\)"
(fn [[_ form]]
(str (evil m (read-string form)))))))
(defn -main []
(println (render "hello ((str x))" {:x "world"}))
; => hello world
(println (render "1 + 2 + ((str n)) = ((+ 1 2 n))" {:n 3}))
; => 1 + 2 + 3 = 6
(println (render "((if flag 'foo 'bar))" {:flag true}))
; => foo
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment