rewrite-clj

javi 2021-10-08T12:01:13.061300Z

are the z/right* , z/left* etc.. functions available in cljs? they work great in the clojure repl, but when i switch to a cljs repl ( browser) i get an error saying they are undefined.

javi 2021-10-08T12:44:10.062800Z

it works if i access the function directly like so

(-> zloc
	  rewrite-clj.custom-zipper.core/right
    z/string)

lread 2021-10-08T16:14:09.063Z

Hi @fj.abanses, thanks for reaching out with your question. I’ll try to reproduce your issue. I’m running on macOS, so any shell commands will be in bash. I’ll start with creating, then switching to an empty new directory from bash:

mkdir testing123 
cd testing123
Now I’ll create a minimal deps.edn file in the testing123 directory that references the current versions of ClojureScript and rewrite-clj. It has the following content:
{:deps {org.clojure/clojurescript {:mvn/version "1.10.866"}
        rewrite-clj/rewrite-clj {:mvn/version "1.0.682-alpha"}}}
From bash, I’ll launch a ClojureScript REPL like so:
clj -M --main cljs.main --repl
This launches a web browser and gives me a REPL to that browser at the terminal:
ClojureScript 1.10.866
cljs.user=>
Now I’ll poke around in the REPL. First I’ll start with requiring the rewrite-clj.zip API:
cljs.user=> (require '[rewrite-clj.zip :as z])
nil
That looks good. Now I’ll do a little sanity test with down*:
cljs.user=> (-> "[1 2 3]" z/of-string z/down* z/string)
"1"
That seems good. Ok, let’s navigate to the space node after 1:
cljs.user=> (-> "[1 2 3]" z/of-string z/down* z/right* z/string)
" "
That also seems good to me. You also mentioned left* so I’ll try that too by navigating to 3 and then back to 2:
cljs.user=> (-> "[1 2 3]" z/of-string z/down* z/rightmost* z/left* z/left* z/string)
"2"
Looks good over here. So I think there must be something different on your side. I look forward to learning more. Just a wild guess, but are you maybe still including rewrite-cljs as one of your dependencies? If so, remove it; rewrite-clj v1 replaces rewrite-cljs and rewrite-clj v0.

javi 2021-10-08T17:08:35.066900Z

thanks for the very detailed reply. yeah, i removed rewrite-cljs but i still the same issue. i ll keep looking into it, i must be doing something very silly somewhere… :) btw, thanks for the work on the library!!1

lread 2021-10-08T17:37:22.067100Z

@fj.abanses, if you find yourself still stuck, come back and share more of your setup/environment and we’ll figure it out. Sometimes some other library will bring in an unexpected dependency. If you are using leiningen, you could try lein deps :tree, if you are using tools cli, you could try clj -Stree.

javi 2021-10-08T17:58:36.070500Z

thanks, that’s actually what i am exploring now. cleared .m2 of rewrite-clj and rewrite-cljs but on recompiling ( i am using shadow ) rewrite-cljs gets pulled back in. i have to go now, but i will look at it in detail when i am back and report

👍 1
javi 2021-10-08T18:37:58.074200Z

back now. cleared ./shadow-cljs , removed a zprint dependency i am not using and re-installed the library. all working now :) many thanks @lee ! apologies for the noise.

lread 2021-10-08T18:39:53.074400Z

Sweet! No need to apologize, I’m sure this discussion will help others who stumble into a similar situation.

javi 2021-10-08T18:56:30.074800Z

👏 👏 🙌