Fork me on GitHub
#babashka
<
2024-02-07
>
Patrick Brown14:02:05

Any ideas why I get this error in a babashka nrepl-server? clojure.lang.ExceptionInfo: Could not resolve symbol: sci.impl.records/equals. https://github.com/babashka/sci/blob/ca675599773ade82d83ff3a1aa476c25dc644f86/src/sci/impl/records.cljc#L59 What I’d like to do is be able to call equality on two different atom refs defined by a custom Type. Any ideas are welcome. My offending code is in thread.

1
borkdude14:02:16

thread upcoming?

Patrick Brown14:02:33

(deftype Link [atom-ref meta validate-with watches read-with write-with deref-with check-with id] 5 references Object (equals [this other] (and (instance? Link other) (= atom-ref (.-atom-ref other)))) clojure.lang.IDeref (deref [this] (let [derefer (or deref-with (fn [_ a getf] (getf (deref a))))] (derefer this atom-ref read-with))) clojure.lang.IAtom (swap [this f] (reset! this (f (deref this)))) (swap [this f x] (reset! this (f (deref this) x))) (swap [this f x y] (reset! this (f (deref this) x y))) (swap [this f x y z] (reset! this (apply f (deref this) x y z))) (compareAndSet [_ old-value new-value] (let [_ (compare-and-set! atom-ref old-value new-value) commit? (= old-value new-value)] (when commit? (swap! atom-ref new-value)))) (reset [this new-value] (if write-with (let [validate (.-validate-with this)] (when-not (nil? validate) (assert (validate new-value) "Invalid Value")) (do (swap! atom-ref write-with new-value) new-value)) (throw (Exception. "READ ONLY ATOM: Reset unavailable.")))))

Patrick Brown14:02:39

My copy and paste game is poor, there is some kondo emacs gibberish at the top of that function…

Patrick Brown14:02:00

(deftype Link [atom-ref meta validate-with watches read-with write-with deref-with check-with id] Object (equals [this other] (and (instance? Link other) (= atom-ref (.-atom-ref other)))) clojure.lang.IDeref (deref [this] (let [derefer (or deref-with (fn [_ a getf] (getf (deref a))))] (derefer this atom-ref read-with))) clojure.lang.IAtom (swap [this f] (reset! this (f (deref this)))) (swap [this f x] (reset! this (f (deref this) x))) (swap [this f x y] (reset! this (f (deref this) x y))) (swap [this f x y z] (reset! this (apply f (deref this) x y z))) (compareAndSet [_ old-value new-value] (let [_ (compare-and-set! atom-ref old-value new-value) commit? (= old-value new-value)] (when commit? (swap! atom-ref new-value)))) (reset [this new-value] (if write-with (let [validate (.-validate-with this)] (when-not (nil? validate) (assert (validate new-value) "Invalid Value")) (do (swap! atom-ref write-with new-value) new-value)) (throw (Exception. "READ ONLY ATOM: Reset unavailable.")))))

borkdude14:02:05

If I run that code locally with bb dude.clj it works, is this only occurring in the nREPL server?

borkdude14:02:20

also, which version of bb are you using

borkdude14:02:01

if this isn't the full repro, e.g. if you also instantiate Link etc to see the error, please also provide that. I'll be back later today

Patrick Brown14:02:22

Oh, dear, I think you just touched it. I’ve got this in my emacs. I’ve got babashka.nrepl 0.0.6-SNAPSHOT with BB 0.8.157

borkdude14:02:22

maybe try upgrading bb to 1.3.188

Patrick Brown14:02:06

By chance, how does babashka get updated on nix package manager?

borkdude14:02:47

I don't know, I don't maintain the nix side of things myself, but @U0303ET1R2T perhaps knows

Patrick Brown14:02:49

I reckon I switched to an old bb when I went from putting bb in my bin myself to using nix home manager for it. Either way. Thanks for your help. I know where I went wrong… Good news! Not my app code!

🎉 1
sohalt14:02:21

babashka on nixpkgs is updated by a group of maintainers (and automatically with a bot, if the update is seamless) https://github.com/NixOS/nixpkgs/commits/a3ed4692b7bb68563541f9886a055b07e8675c3b/pkgs/development/interpreters/babashka/default.nix

❤️ 1
sohalt14:02:38

Though you'd need to use nixpkgs-unstable to get the latest babashka. The latest stable release (nixpkgs-23.11) has babashka 1.3.186 https://github.com/NixOS/nixpkgs/blob/release-23.11/pkgs/development/interpreters/babashka/default.nix#L12

Patrick Brown14:02:56

Babashka is 1.3.188 on nix-unstable. There is a link in the README https://github.com/babashka/babashka?tab=readme-ov-file#installation And more info https://github.com/babashka/babashka/blob/master/doc/nix.md Everything was up to date. I wasn’t following the correct instructions and using a bad nix channel for BB. Thanks to everybody who helps me have great tooling that is so easy to use if you actually RTFM. Sorry for the confusion.

❤️ 1
Felix Dorner16:02:22

What’s the babashka/fs for something like find my/dir -name toto.yaml ? I can’t get it to work neither with glob nor match 😞

1
borkdude16:02:02

(fs/glob "my/dir" "**/toto.yaml") 
I think

Felix Dorner16:02:06

Lifesaver, thanks!

borkdude16:02:23

or maybe **toto.yaml if you also want to find in the top level directory

Felix Dorner16:02:17

Ok, yes both work for me.

Ingy döt Net18:02:09

Can I add org.babashka/fs to my project.clj ? I added org.babashka/http-client fine but fs errors with:

Retrieving org/babashka/fs/0.5.20/fs-0.5.20.pom from public-github
Retrieving org/babashka/fs/0.5.20/fs-0.5.20.jar from public-github
Could not find artifact org.babashka:fs:jar:0.5.20 in central ()
Could not find artifact org.babashka:fs:jar:0.5.20 in clojars ()
Could not transfer artifact org.babashka:fs:jar:0.5.20 from/to public-github (): : Authentication is required but no CredentialsProvider has been registered
Failed to read artifact descriptor for org.babashka:fs:jar:0.5.20
This could be due to a typo in :dependencies, file system permissions, or network issues.
If you are behind a proxy, try setting the 'http_proxy' environment variable.

1
seancorfield18:02:54

How are you specifying the dependency? Sounds like you need to specify https:// not git:?

Ingy döt Net19:02:56

hmmm. then I get

Could not find artifact org.babashka:fs:jar:0.5.20 in central ()
Could not find artifact org.babashka:fs:jar:0.5.20 in clojars ()
Could not find artifact org.babashka:fs:jar:0.5.20 in public-github ()

Ingy döt Net19:02:06

it has its own repo and releases: https://github.com/babashka/fs so I assumed you can use it as a dep

Ingy döt Net19:02:26

$ git diff core/project.clj
diff --git a/core/project.clj b/core/project.clj
index cc99fb8..9f230af 100644
--- a/core/project.clj
+++ b/core/project.clj
@@ -21,6 +21,8 @@
    [org.clojure/data.json "2.4.0"]
    [clj-commons/clj-yaml "1.0.27"]
    [org.snakeyaml/snakeyaml-engine "2.7"]
+   [org.babashka/fs "0.5.20"]
+   [org.babashka/http-client "0.3.11"]
    [org.babashka/sci "0.8.41"]]
 
   :plugins
@@ -31,7 +33,7 @@
 
   :prep-tasks [["lein2deps" "--write-file" "deps.edn" "--print" "false"]]
 
-  :repositories [["public-github" {:url ""}]]
+  :repositories [["public-github" {:url ""}]]
 
   :global-vars {*warn-on-reflection* true}

Ingy döt Net19:02:30

but the docs don't say anything about using it in deps.edn like they do for http-client

Ingy döt Net19:02:54

https://clojars.org/babashka/fs looks like I need to use babashka/fs not org.babshka/fs

Ingy döt Net19:02:10

yep. problem solved...

borkdude19:02:55

Yes that is it. This is a consequence of Clojars changing their rules about org name verification

1