Skip to content

Instantly share code, notes, and snippets.

@mavant
Created April 1, 2014 17:43
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 mavant/9919202 to your computer and use it in GitHub Desktop.
Save mavant/9919202 to your computer and use it in GitHub Desktop.
(defmacro list-pythonize "Convert a list of expressions in Clojure to semantic-whitespace form." ([l] (macroexpand-1 `(list-pythonize ~l 0))) ([l n] (map (fn [x] (if (list? x) (concat (list "\n") (repeat n "\t") (macroexpand-1 `(list-pythonize ~x ~(+ n 1))) ) x)) l)))
(print (macroexpand-1 '(list-pythonize (defn tabs->parens [c] (map add-parens (rest (split-on-newlines c)) (list-deltas (code->numtabs c)))))))
;=>
;(defn tabs->parens [c] (
; map add-parens (
; rest (
; split-on-newlines c)) (
; list-deltas (
; code->numtabs c))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment