Skip to content

Instantly share code, notes, and snippets.

@alandipert
Last active August 29, 2015 14:09
Show Gist options
  • Select an option

  • Save alandipert/64a598b9e26eb0a0ac96 to your computer and use it in GitHub Desktop.

Select an option

Save alandipert/64a598b9e26eb0a0ac96 to your computer and use it in GitHub Desktop.

Revisions

  1. alandipert renamed this gist Nov 11, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. alandipert renamed this gist Nov 11, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. alandipert revised this gist Nov 11, 2014. 1 changed file with 7 additions and 3 deletions.
    10 changes: 7 additions & 3 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -5,11 +5,15 @@
    (if (seq tokens)
    (let [token (first tokens)]
    (cond (string? token)
    (recur (rest tokens) (doto out-str (.append token)) out-args)
    (or (vector? token) (list? token) (seq? token))
    (recur (rest tokens)
    (doto out-str (.append token))
    out-args)
    (vector? token)
    (recur (rest tokens)
    (doto out-str (.append (str/join "," (map (constantly "?") token))))
    (into out-args token))
    :else
    (recur (rest tokens) (doto out-str (.append "?")) (conj out-args token))))
    (recur (rest tokens)
    (doto out-str (.append "?"))
    (conj out-args token))))
    (into [(str out-str)] out-args))))
  4. alandipert created this gist Nov 11, 2014.
    15 changes: 15 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    (defn deterpolate [s]
    (loop [tokens (interpolate s)
    out-str (StringBuffer.)
    out-args []]
    (if (seq tokens)
    (let [token (first tokens)]
    (cond (string? token)
    (recur (rest tokens) (doto out-str (.append token)) out-args)
    (or (vector? token) (list? token) (seq? token))
    (recur (rest tokens)
    (doto out-str (.append (str/join "," (map (constantly "?") token))))
    (into out-args token))
    :else
    (recur (rest tokens) (doto out-str (.append "?")) (conj out-args token))))
    (into [(str out-str)] out-args))))