How macros can be evaluated using clojurescript repl

Once the browser is connected to replo clojurescript, I previously had no way to call macros from repl. This is a problem that clojurescript has disabled me in the past, preferring to use javascript directly. Basically, I felt that cljs-repl was a bit lame, and I was returning to the compilation / debugging cycle, which was supposed to free us from clojure code.

Are there any good workarounds / workflows for pushing and testing code in clojurescript? Especially if macros can be evaluated?

An example of my problem:

  • create a new cljs project

    lein new cljs-template blah

  • start the server

    cd blah

    lein run

  • run web-repl

    lein trampoline cljsbuild repl-listen

  • there is a src/blah/client/main.cljs with a header

  (ns blad.client.main
       (: require [noir.cljs.client.watcher: as watcher]
                 [clojure.browser.repl: as repl]
                 [crate.core: as crate])
       (: use [jayq.core: only [$ append]])
       (: use-macros [crate.macros: only [defpartial]]))

note the line (:use-macros [crate.macros :only [defpartial]])

I cannot use defpartial in a replica of a browser because it is a macro. The error I am getting is:

  >> (crate.macros / defpartial [])
 "Error evaluating:" (crate.macros / defpartial []): as "crate.macros.defpartial.call (null, cljs.core.Vector.fromArray ([])); \ n"
 #
 TypeError: Cannot read property 'defpartial' of undefined

Now defpartial is a pretty useful macro, and without it, it was a problem.

My problem got worse when I wanted to define another macro in the project with :use-macros . I could not debug what I wrote at all in the repl or browser, and after about half a day I realized that it was faster to use clj repl, check the macro there using macroexpand, and copy the results back to the browser. I have one cljs macro working in about a day, it wasn’t very fun. That was about 6 months ago. I hope there is a faster way to do it now.

+4
source share
2 answers

For macros to load during the w / bREPL interactive session, you need to explicitly evaluate the ns form in bREPL.

However, this is a little annoying - some work has landed in the wizard to support interactive macro exposure, but it needs a lot of work. W also has a few ideas floating around to make bREPL more useful by analyzing the source files at startup.

+6
source

Today I checked that with cemerick / austin : clojureScript browser-REPL, you can use and evaluate your macros in brepl without restriction, to say without explicitly evaluating the ns form in bREPL. I use core.async macros and custom domain macros in this demo-project without any problems.

+3
source

Source: https://habr.com/ru/post/1433201/


All Articles