Fork me on GitHub
#beginners
<
2021-04-24
>
raspasov04:04:19

Also, if-let, if-some , depending on what you need.

sova-soars-the-sora05:04:26

if-some looks neat. https://clojuredocs.org/clojure.core/if-some when would one use it instead of if-let ?

seancorfield05:04:48

@sova if-let treats both false and nil as negative conditions. if-some only treats nil as a negative condition.

seancorfield05:04:14

So if you have an expression that can yield truthy, false, or nil, where the first two are useful values and the third means “no result”, then you want if-some rather than if-let:

dev=> (if-let [x false] x :nope)
:nope
dev=> (if-some [x false] x :nope)
false

futurile10:04:37

Is there a way to list all namespaces in the REPL when using ClojureScript? The equivalent of all-ns in Clojure

flowthing11:04:33

There's https://github.com/clojure/clojurescript/blob/5091bab07e8e60f64d06e43bf07ba08204071b0d/src/main/clojure/cljs/analyzer/api.cljc#L212, but that is only useful if you need that information in Clojure (and maybe self-hosted ClojureScript -- not sure). What are you trying to do?

pavlosmelissinos11:04:52

Is there a cleaner and/or more idiomatic way to say this?

(filter #(and (= (:k1 %) (:k1 a-map))
              (= (:k2 %) (:k2 a-map))
              ...
              (= (:kn %) (:kn a-map))) coll-of-maps)
edit: generalized the example a bit for n keys

valtteri11:04:37

You could use select-keys and compare equality of resulting maps

👍 3
flowthing11:04:15

Or (clojure.set/join #{a-map} coll-of-maps), I suppose. 🙂

👍 3
flowthing11:04:55

But yeah, select-keys is probably the right answer here, unless you specifically want a set as a result.

Darin Douglass13:04:06

clojure.data/diff would work as well

3
👍 3
Sajjad11:04:32

Hi I am working on https://github.com/metabase/metabase project, It is a leiningen project and I am trying to using debugger on it after running project with `lein run` I installed calva on vscode and tried some steps to set up debugger, but I was out of luck I would be grateful if you tell me steps required to set up debugger 🙏

flowthing11:04:41

You will probably have better luck getting an answer over at #calva. Make sure you describe what being "out of luck" means specifically. Also, check out https://calva.io/debugger/.

Sajjad11:04:28

Thanks, Yeah I checked it out, but ok I will describe in #calva

code komali14:04:43

I am using vscode+calva. So far no issues having fun hacking clojure, except for one really annoying thing. clj-kondo is drawing sqiggly lines across many useful macros and makes the entire code ugly. I tried configuring it but failed. I created a .clj-kondo folder in project root and added config.edn. The below is my simple attempt to exclude deftest

code komali14:04:29

{:linters {:unresolved-symbol {:exclude [clojure.test/deftest]}}}

borkdude14:04:38

@code.komali You should not have to do that, clj-kondo is aware of all built-in clojure macros. It's likely that something else is wrong.

borkdude14:04:05

Please lint your code on the command line with the clj-kondo command line tool to see if you get any unexpected errors.

borkdude14:04:20

If not, then it's a downstream tooling problem. Pasting a screenshot might also help. Come talk in #clj-kondo or #calva to discuss further problems.

Stuart14:04:25

I'm pretty sure i also get squiggle on deftest with cava. I assumed it just wasn't supported. Will check when i get home.

code komali14:04:51

Thanks @borkdude I'll try doing that. But, even if the command line linting worked. I am very happy with calva. Hope the calva creator(s) do something about this.

borkdude14:04:16

Of course. This is just a way of finding out where the problem is. It should be resolved.

borkdude14:04:32

It turned out it was related to :refer :all and the problem is now fixed

code komali14:04:01

@borkdude yes. thanks for helping out!

Stuart16:04:49

DO you mean I shouldn't use :refer :all ? This is what I see:

Stuart16:04:08

My ns is like this:

(ns asm.parser-test
  (:require [clojure.test :refer :all]
            [asm.parser :refer :all]))

Stuart16:04:20

oh yeah! If I change it to

(:require [clojure.test :refer [deftest testing is]])
It removes the wiggles, thanks!

borkdude20:04:41

@code.komali @qmstuart well, shouldn't use is maybe too strong, but it helps clj-kondo more if you don't do that. However, if you have populated the cache with

mkdir -p .clj-kondo
clj-kondo --lint src:test --dependencies
then it will also work (I just realized this answering a similar question in #clj-kondo)

borkdude20:04:12

but since Calva uses LSP under the hood I would have expected it to have populated the cache, but maybe it doesn't do that if there is no .clj-kondo dir? /cc @ericdallo

ericdallo21:04:08

Good question, clojure-lsp doesn't handle any cache folder, it just pass the cache true flag for clj-kondo, I imagine clj-kondo don't create the .clj-kondo folder always?

borkdude21:04:47

ah yeah, clj-kondo doesn't do this automatically

borkdude21:04:02

since it doesn't know what the project root is

ericdallo21:04:35

Hum, so for those cases we are not using clj-kondo cache properly?

ericdallo21:04:58

This can explain issues with non analyzed definitions like refer all for deftest and so on

ericdallo21:04:43

Do you think it makes sense clojure-lsp creates that dir? (It seems odd the need to create another lib folder though)

ericdallo21:04:56

Maybe some flag to clj-kondo pointing the project root?

ericdallo21:04:09

So clj-kondo could create and handle that?

borkdude21:04:55

Well, clojure-lsp has more an idea of what the project is than clj-kondo, I always left this up to the user. But I think if clojure-lsp knows what the root is, then it makes sense that it creates the .clj-kondo folder if it doesn't exist

borkdude21:04:17

since it also benefits itself

ericdallo21:04:02

Alright, I think it's a start to fix that, I'll take a look so, thanks!

naxels20:04:21

Could someone take a look at my sample repo and tell me why the GraalVM compiled binary won't work? https://github.com/naxels/parse-rss-example

naxels20:04:41

Trying with clojure.data.xml won't even make an uberjar

naxels20:04:13

And i created a new project using leiningen, copy/paste the code and it won't work there either with the native-image plugin

naxels20:04:30

It always comes back with a 2 arg error to the SAX parse

naxels20:04:01

It's been frustrating me for 2 days straight ha, i can run it, debug it, CALVA it, uberjar it

naxels20:04:26

Just not get it working with native-image after compilation

naxels20:04:29

Thank you!

naxels20:04:31

I found where the issue is: as soon as I place the code to do xml/parse outside the globals and inside a function, it fails after compiling

naxels20:04:45

Earlier commits it was in the globals, worked super fast

borkdude21:04:58

@patrick.glind I suggest not using any tools other than uberjar + $GRAALVM_HOME/bin/native-image since it's pretty difficult to know what goes wrong where, if you use all kinds of "helper" tools. Check out the hello world examples here to get going with a simple example and then extend it to your example: https://github.com/lread/clj-graal-docs

borkdude21:04:24

There is also a #graalvm channel

borkdude21:04:55

If you need to parse some XML you can also use #babashka which comes with clojure.data.xml built in

naxels21:04:31

I did not know about the clj-graal-docs, will check that out tomorrow, thanks!

naxels21:04:54

The example is for a clojure study group i'm currently participating in and I wanted to show the native-image 'magic'

👍 2
naxels21:04:21

I will also try this with babashka, thanks for mentioning it