Skip to content

Instantly share code, notes, and snippets.

@metacritical
Forked from noprompt/slurp.clj
Created October 30, 2017 01:37
Show Gist options
  • Save metacritical/4f69cd0a29861b63563f43ff65b0e83a to your computer and use it in GitHub Desktop.
Save metacritical/4f69cd0a29861b63563f43ff65b0e83a to your computer and use it in GitHub Desktop.
How to use slurp from ClojureScript
(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"))
@kenfehling
Copy link

kenfehling commented Nov 10, 2017

I don't understand how this works though, doesn't clojure.core/slurp use java.io stuff? But that's not available in Node.js or the web browser.

@chr15m
Copy link

chr15m commented Jan 5, 2023

@kenfehling because it is a macro it happens at compile time not run time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment