Question

I am playing around with compiling clojurescript to nodejs and I just really want to use the println function:

(println "hello world")

However, it gives me an error

 No *print-fn* fn set for evaluation environment

I've looked around the net but it wasn't clear what was supposed to be done. I really just want to set *print-fn* to js/console.log but I'm not sure how to do that

Was it helpful?

Solution

Since this commit the canonical way of redirecting println to the console seems to be:

(enable-console-print!)

OTHER TIPS

If you can't use println in clojurescript browser environment, why don't you (re)define this function inside your code?. I mean something like:

(def println[ & more]
  (.log js/console more))

on the beginning of your application code

EDIT: as @edbond says, in clojurescript/node environment you can use println without more configuration. You can find an example on the clojurescript documentation https://github.com/clojure/clojurescript/wiki/Quick-Start#running-clojurescript-on-nodejs

(ns nodehello)

(defn -main [& args]
  (println (apply str (map [\ "world" "hello"] [2 0 1]))))

(set! *main-cli-fn* -main)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top