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 hidden or 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")) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@FrankApiyo ClojureScript uses Clojure to expand macros. This means the code inside the
slurpmacro above is being invoked in the Clojure environment and, thus, all of the usual Clojure functions are available. In this case,slurpwill return the content ofproject.cljas a string and "inline" it on line 14.So if
project.cljlooked likethen line 13 to 14 expands to