Fork me on GitHub
#rewrite-clj
<
2021-10-08
>
javi12:10:13

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.

javi12:10:10

it works if i access the function directly like so

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

lread16:10:09

Hi @U9VP9VCE6, 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.

javi17:10:35

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

lread17:10:22

@U9VP9VCE6, 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.

javi17:10:36

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
javi18:10:58

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

lread18:10:53

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

javi18:10:30

👏 👏 🙌