You can use `cljs.util/debug-prn` if you need to print during macro
expansion.
Whether or not this should be called a bug I don't know.
On Monday, August 13, 2018 at 8:41:05 AM UTC+2, Philos Kim wrote:
>
> I wrote a macro in ClojureScript and wanted to test the macro by using
> println function like this,
>
> ;; qna/macro.clj
> (ns qna.macro)
>
> (defmacro my-add [a b]
> (println "a =" a "b =" b) ; <-- Here
> `(+ ~a ~b))
>
>
> ;; qna/main.cljs
> (ns qna.main
> (:require-macros [qna.macro :refer [my-add]]))
>
> (defn ^:export main []
> (my-add 2 3))
>
>
> resources/public/index.html and project.clj are like the following.
>
> ;; resources/public/index.html
> <!doctype html>
> <html lang="en">
> <head>
> <meta charset='utf-8'>
> <title>QnA Demo</title>
> </head>
>
> <body>
> <h2>QnA Demo</h1>
> <div id="app"></div>
>
> <script src="js/main.js"></script>
> <script>qna.main.main();</script>
> </body>
> </html>
>
>
> ;; project.clj
> (defproject qna "0.1.0-SNAPSHOT"
> :dependencies [[org.clojure/clojure "1.9.0"]
> [org.clojure/clojurescript "1.10.339"]]
> :min-lein-version "2.6.0"
> :plugins [[lein-cljsbuild "1.1.7"]
> [lein-figwheel "0.5.16"]]
> :clean-targets ^{:protect false}
> ["target"
> "resources/public/js/out"
> "resources/public/js/main.js"]
> :cljsbuild
> {:builds
> [{:id "dev"
> :source-paths ["src"]
> :compiler {:main qna.main
> :output-to "resources/public/js/main.js"
> :output-dir "resources/public/js/out/"
> :asset-path "js/out/"
> :optimizations :none
> :source-map true
> :pretty-print true} }]})
>
> When I open the above .html file in the browser, I encounter the following
> error.
>
> Uncaught SyntaxError: Unexpected identifier in main.js:4
>
> And the compiled main.js file is like this.
>
> // Compiled by ClojureScript 1.10.339 {}
> goog.provide('qna.main');
> goog.require('cljs.core');
> a = 2 b = 3 // <-- embedded printed result
> qna.main.main = (function qna$main$main(){
> return ((2) + (3));
> });
> goog.exportSymbol('qna.main.main', qna.main.main);
>
> //# sourceMappingURL=main.js.map
>
>
> To sum up, whenever I evalute (println ...) within a macro, the printed
> result doesn't go to the REPL but is embedded into the compiled .js file.
>
> If this is a bug of ClojureScript, I will register this error in the
> ClojureScript JIRA.
>
>
>
>
>
>
--
Note that posts from new members are moderated - please be patient with your
first post.
---
You received this message because you are subscribed to the Google Groups
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/clojurescript.