Fork me on GitHub
#babashka
<
2022-02-15
>
Martynas Maciulevičius10:02:39

How does one install sci as an external dependency? I try to run tests of malli and they fail with this error: :malli.core/sci-not-available

borkdude10:02:09

Include org.babashka/sci {:mvn/version "0.3.0"}

Martynas Maciulevičius10:02:40

What should be the file? ~/.clojure/deps.edn?

borkdude10:02:16

The deps.edn in your project. But if you are running malli's tests from the malli repo, it's likely that you'll have to include some alias. Ask in #malli

1
borkdude10:02:58

If you are working on malli, maybe you can also upgrade SCI, it has some performance boosts in 0.3.0.

Martynas Maciulevičius10:02:21

Unfortunately I only want to fix one bug 🙂

Benjamin13:02:57

Can I add core.halt-when in user space?

borkdude13:02:17

@benjamin.schwerdtner halt-when is added on master, available in the next release. you can download a master snapshot from https://github.com/babashka/babashka-dev-builds or install using

bash <(curl ) --version 0.7.5-SNAPSHOT --dir .

catjam 2
borkdude13:02:51

but you could also add it in user space using (intern 'clojure.core (fn ...))

Benjamin14:02:39

nice thanks

Martynas Maciulevičius15:02:08

Hey. Is there a way to use muuntaja in babashka? It says that it can't find java.util.concurrent.ConcurrentHashMap.

borkdude15:02:13

Can you explain what you are doing?

borkdude15:02:24

muuntaja is unlikely to work with babashka since babashka doesn't support deftype .

Martynas Maciulevičius16:02:01

I want to parse JSON input. But it crashes for some reason.

bash scripts/test-permissions-babashka.sh 
----- Error --------------------------------------------------------------------
Type:     java.lang.Exception
Message:  Unable to resolve classname: java.util.concurrent.ConcurrentHashMap
Location: muuntaja/parse.clj:3:3

----- Context ------------------------------------------------------------------
1: (ns muuntaja.parse
2:   (:require [clojure.string :as str])
3:   (:import (java.util.concurrent ConcurrentHashMap)))
     ^--- Unable to resolve classname: java.util.concurrent.ConcurrentHashMap
4: 
5: ;;
6: ;; Cache
7: ;;
8: 

----- Stack trace --------------------------------------------------------------
muuntaja.parse                   - muuntaja/parse.clj:3:3
muuntaja.core                    - muuntaja/core.clj:3:3
<omitted>
user                             - <expr>:1:10

Martynas Maciulevičius16:02:33

Also this: [metosin/muuntaja "0.6.8"] Maybe it's an old version?

borkdude16:02:40

Why do you need muuntaja for parsing json?

borkdude16:02:12

Also, again: even if we added that class, muuntaja wouldn't work because of deftype

Martynas Maciulevičius16:02:04

Well the project's original author was parsing JSON this way. So I thought that I don't want to add cheshire as I should reuse the same lib. But well... it doesn't work.

borkdude16:02:31

but muuntaja also uses cheshire.

borkdude16:02:43

you can use cheshire directly in babashka

borkdude16:02:56

don't use a complex library for something which should be simple

Martynas Maciulevičius16:02:22

I know. And I used it this way. But JAR build failed because I didn't include cheshire into the project's lein dependencies. Which meant that I have to not use cheshire for that namespace (import failed).

Martynas Maciulevičius16:02:53

I think you're right. And that means that the library wasn't used properly in the first place.

Martynas Maciulevičius16:02:51

Yep. I didn't even know that muuntaja uses cheshire. Thanks.

Martynas Maciulevičius08:02:20

This says that muuntaja uses jsonista by default and cheshire is one possible adapter that could be used: https://github.com/metosin/muuntaja#modules

borkdude08:02:18

Ok, makes sense. But if you want to parse JSON in bb, you don't need this library. Just use Cheshire

Martynas Maciulevičius08:02:12

Yes but that means that I would need to include the cheshire into the project's dependencies even if I would use jsonista . Because if I import cheshire then JAR doesn't want to build. I may use profiles for that but it's more cumbersome. Or then I'd need to move out the babashka-main namespace. I don't yet know what would be the best pattern for that.

borkdude08:02:26

You could also use reader conditionals for this or a .bb file which is prioritized over .clj

borkdude08:02:48

Or even a macro that checks if you are in bb or not

Martynas Maciulevičius08:02:47

Does bb have a reader conditional? Also I can't return from namespace evaluation once I detect that I can't run it. It's probably my best bet if I'd include both libraries into the project.

borkdude08:02:48

Yes, see the book and search for reader conditionals

borkdude08:02:50

You don't have to include Cheshire for bb, it's built in

borkdude08:02:12

If your code is public then I could have a look

Martynas Maciulevičius11:02:54

Nah, my code is not public. But it's fine. I figured it out. I'll use the conditionals in multiple places and I'll have cljc file. 🙂

borkdude11:02:37

That works. You can also isolate the change in one place in a function and then call that json function throughout the rest of your code.

Martynas Maciulevičius11:02:52

Yes. This is what I ended up with.

👍 1
Martynas Maciulevičius11:02:29

I have a conditional in imports and then I have a conditional in encode/decode functions. I don't yet know what I'll do if I'll need a InputStream or OutputStream as output but that's fine for now.

borkdude11:02:47

is that a built-in java class?

Martynas Maciulevičius11:02:27

No, I think IOStream is something that I made up in my mind. I think it could come from C++... Java has InputStream and OutputStream.

borkdude11:02:44

those are available in bb

Martynas Maciulevičius11:02:24

No, that's fine. I was thinking about JSON parsing into a Java stream. But cheshire should do it just fine. I'll only need to add a function that does this.

Benjamin17:02:43

how should I remove babashka options from command-line-args. E.g. "--parallel" will be an arg I was misspelling the arg that's why 🙈 all good

Benjamin17:02:13

naively I just (remove #{"--paralles"} args)

borkdude18:02:41

hmm, --parallel should not end up in *command-line-args* , might be a bug.

Benjamin14:02:27

you are right. It was because I misspelled it so the misspelled one showed up :thumbsup:

borkdude14:02:23

great, thanks :)