Fork me on GitHub
Matthew Twomey04:02:58

I want this same result:

(->> {:one "one" :two "two" :three "three"} vec flatten) 
;; => (:one "one" :two "two" :three "three")
I feel like I might be missing a single function that does this?

Matthew Twomey04:02:43

(mapcat seq {:one "one" :two "two" :three "three"}) also does it - but still seems like it should be more simple.


iterleave its keys and values. but be aware that you are going from an unordered structure to an ordered one. The way you "see" the map or think it should order might not be what you end up with.

Matthew Twomey04:02:43

well, what I do care about is that the pairs stay next to each other. I don’t care about the order of the pairs themselves.


good. then (defn as-seq [m] (interleave (keys m) (vals m))) should do it for you


although nothing really wrong with your mapcat seq solution

Matthew Twomey04:02:29

Oh yeah - ok, cool. I’m finding lots of ways to do this I see. I haven’t run into interleave yet - thanks for pointing it out!

👍 2

(into [] cat {:one "one" :two "two" :three "three"})

👀 2
Jakub Šťastný15:02:29

I'm getting [nRepl] Connection closed unexpectedly (connection broken by remote peer) when I do cider-eval-buffer. At that point bb --nrepl-server quits with exit status 1 and no message. I'm using babashka v1.1.172 from Homebrew on the latest macOS. What's up with that?


can't repro here. perhaps you have a (System/exit 1) in your code?

Jakub Šťastný15:02:30

Haha I'm a moron. You're right. It's doing arguments check 🙈


You can also do:

(throw (ex-info "Arguments not right" {:babashka/exit 1}))


This won't exit the REPL


but will exit with exit code 1 if the exception isn't caught, without printing an error report

Jakub Šťastný15:02:08

Nice, I like that.

Jakub Šťastný15:02:03

Are there no structs in Babashka? Can't see it mentined in BB book, but getting Could not resolve symbol: create-struct.


No. What is it with people and structs lately :) Clojure has defrecord which replaces structs in 99.9% of the cases


Please let me know why you are trying to use structs. There's been a flux of people lately and it's mystery where this is coming from

Jakub Šťastný15:02:20

No good reason: I'm rather new the Clojure and I'm still confused between vectors/iseqs, structs/records and the likes.

Jakub Šťastný15:02:30

So if you say use record, that's fair enough for me.


use a normal map, not even a record, unless you have a reason not to

☝️ 1

Where did you read about structs? I'm trying to detect the "beginner's source" that tries to teach this to people. It's not a co-incidence anymore that people are asking about this in various places

😂 2
Jakub Šťastný15:02:54

I think I want something more "formal" than a record. There's a lot of data and all the vectors and maps are getting way too complex, so I wanted like a custom type.

Jakub Šťastný15:02:45

Well coming from OOP languages you go like "OK, if there ain't no objects, then what would a custom type be?" and knowing structs from other languages, you go like oh yeah, that must be it.


ah, so it wasn't a book or blog, or something like this?


Hi. Where I can find bb builds with loom virtual threads? Any plans to build bb with loom in next releases?

Rupert (All Street)15:02:57

Out of interest what's your usecase with loom threads? You can have 10,000s of Java threads already and with core.async you can have millions of go blocks.


I'm working on library of SWIM implementation protocol in JVM and every UDP packet is processed in Virtual Thread. I want to make this library bb compatible and I need to test it with Loom threads. core.async has limits of using I/O in go blocks and limited by OS threads. Loom Virtual Threads is free of that limits. I can make 100K I/O parallel operations without any problems.

Rupert (All Street)16:02:10

Thanks, sounds good. I can see that loom threading model would help simplify the design of protocols like that.


we have this branch and tried out experimenting with it with some good results. but we are waiting on some more issues to resolve before moving to jdk 19+


i can try triggering the ci on that branch again to produce some binaries, but note that the branch isnt upto date


@U04V15CAJ should i get the loom branch upto date? have some newer CI builds?


You should be able to try the jdk19-loom branch and compile locally. For some reason there was a failing Windows test which I haven't dug into. There is GraalVM 19 22.3.1 (previous I tried was 22.3.0)


@U7ERLH6JX Feel free to make the branch up to date, preferably via a PR to the jdk-19 branch


If people want to speed up progress around getting this released into bb investigating the Windows issue should help too


I made bb build from branch using GraalVM 19 22.3.1. Now it works!

🎉 2

I made a build with spec flag export BABASHKA_FEATURE_SPEC_ALPHA=true. Why s/and is not supported? Is there workaround?


@U097654L8 You don't need this anymore. spec is included with bb in the latest version. before those you have to include this dependency:


This is from 1.0.167 (2022-11-30) and newer


I made a build with loom v1.0.165. Is there any bb branches with loom for newer versions of bb?


I need Loom and spec together


Like i mentioned before, that branch isn’t upto date. You can rebase master on it maybe


I'll try. Thanks.


PR welcome to that branch, as mentioned. Will help move things forward.


@U097654L8 if you’re already on it, might as well raise a PR if it works 😄 i can do it in a bit as well


Well I made rebase loom branch on 1.0.174-SNAPSHOT and Loom works. But I still struggle with spec. s/and still could not be resolved


you should not compile it with that spec flag you mentioned earlier


if you did, try: (require [clojure.spec.alpha :as s] :reload)


Ah, I will recompile without this flag. Thanks!


It works! Thank you!

👍 1
Jakub Šťastný20:02:40

I'm not sure whether this has to do with babashka or something else, but I'm running babashka, so I'll try here. I have a custom text representation of my type: (defmethod print-method QID [qid out] (.write out (str "m[QID: " (.toString qid) "]"))) When I put (println (QID. 4 0 0 1)) into my script and run it in the console, it prints out the correct custom representation. All good there. However in bb --nrepl-server this is not respected. That is, I evaluate the method definition, then I evaluate the println sexp, it returns nil as it should, but if I go to the cider buffer, where it shows standard output, it's not formatted by the custom formatter but rather by the default one. Anyway in the context of REPL, more important than the standard output is what I see as the inspect value when I evaluate a sexp in the code buffer. If I understand how things work, this requires to define print-dup in the same way as I defined the print-method. I did so, evaluated in REPL, but it's still out returning the expected formatting. What am I doing wrong?


Might be a bug


issue welcome


please use threads for remarks about the same topic / conversation :)

Jakub Šťastný20:02:00

Let me see what it does in normal Clojure.

Jakub Šťastný20:02:29

Oh wow it probably is a bug, it works in Clojure.

Jakub Šťastný20:02:47

Let me verify to make sure I'm not doing something stupid, but if I'm not, I'll report it.


I probably know what the bug is, issue welcome


Can you also paste the code there? It's easier to copy/paste as a test case

Jakub Šťastný21:02:46

I'm using Clojure in the REPL for now and it works there as expected. Really I just need it in the REPL, so it doesn't bother me that much, but of course it's more pleasant running Babashka REPL so I don't have to define all those constants that Clojure doesn't have defined, fs, str etc.


Thanks. I don't get why there are two snippets instead of just one?


A little bit more explanation in the issue might be good. There's just screenshots without any guiding text how to repro. I have this code, merged the snippet into one snippet:

(defprotocol Version (stringify [this] "Get string representation"))
(deftype QID [a b c d] Version (stringify [_] "test"))
(defmethod print-method QID [object out]
  (.write out (stringify object)))

(println "HERE")
(println (.stringify (QID. 4 0 0 1)))
(println (.toString (QID. 4 0 0 1)))
(println (QID. 4 0 0 1))
And here is the difference between bb and clj:
borkdude@m1 ~/dev/greglook-clj-multiformats (babashka) $ bb /tmp/dude.clj
borkdude@m1 ~/dev/greglook-clj-multiformats (babashka) $ clj -M /tmp/dude.clj
Is there anything more I need to know? I also see an NPE in the issue, how to repro that?

Jakub Šťastný21:02:02

The other one is probably not 100% related (it doesn't have print-method defined, but also behaves weird, so I thought it might be possibly somewhat related, I don't know, take a look and see.

Jakub Šťastný21:02:55

I think you don't need to know anything more.


in your screenshot I see a NullPointerException


so, this works:

(println (stringify (QID. 4 0 0 1)))


instead of calling (.stringify ...)


and instead of .toString, str works:

(println (str (QID. 4 0 0 1)))


Those are probably more idiomatic Clojure ways of doing the same and what bb is optimized for


nonetheless the difference is interesting and should be fixed

Jakub Šťastný21:02:02

OK, it does. That makes me even more perplexed. Isn't a method supposed to be called with a dot?

Jakub Šťastný21:02:15

Hahaha I'm sure about that 😄


a protocol method can just be called via the protocol var


user=> (defprotocol Foo (foo [_]))
user=> #'foo


So foo is a proper var. That there is a generated Java method under the hood is not something you should be concerned with I'd say


In ClojureScript (.stringify ...) won't even work

Jakub Šťastný21:02:01

Right. The way to access the generated Java method is via the dot notation? And I shouldn't be doing that then you say. Just leaving the dot out then?

Jakub Šťastný21:02:34

Really appreciate your help and your work on Babashka! Such an awesome project!

thanks 1

yes, just call the protocol method like you named it

👍 1