Created
February 19, 2014 04:52
-
-
Save noprompt/9086232 to your computer and use it in GitHub Desktop.
How to use slurp from ClojureScript
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 foo.core | |
(:refer-clojure :exclude [slurp])) | |
(defmacro slurp [file] | |
(clojure.core/slurp file)) | |
;; In CLJS | |
(ns bar.core | |
(:require [foo.core :include-macros true :refer [slurp]])) | |
;; This is possible because we can evaluate *Clojure* code at compile time. | |
(def project-clj | |
(slurp "project.clj")) |
@FrankApiyo ClojureScript uses Clojure to expand macros. This means the code inside the slurp
macro above is being invoked in the Clojure environment and, thus, all of the usual Clojure functions are available. In this case, slurp
will return the content of project.clj
as a string and "inline" it on line 14.
So if project.clj
looked like
(defproject foo)
then line 13 to 14 expands to
(def project-clj
"(defproject foo)")
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I haven't tried this but I'm skeptical because it does not make any sense to me 😞