beginners

Getting started with Clojure/ClojureScript? Welcome! Also try: https://ask.clojure.org. Check out resources at https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f.
raspasov 2021-04-24T04:38:19.019300Z

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

sova-soars-the-sora 2021-04-24T05:15:26.020500Z

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

seancorfield 2021-04-24T05:49:48.021400Z

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

seancorfield 2021-04-24T05:52:14.022600Z

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

futurile 2021-04-24T10:02:37.022800Z

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

pavlosmelissinos 2021-04-24T11:13:52.025200Z

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

flowthing 2021-04-24T11:25:33.025500Z

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?

valtteri 2021-04-24T11:28:37.027600Z

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

👍 1
flowthing 2021-04-24T11:30:15.027900Z

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

👍 1
flowthing 2021-04-24T11:35:55.028600Z

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

Sajjad 2021-04-24T11:40:32.032300Z

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 🙏

flowthing 2021-04-24T11:47:41.032400Z

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/.

Sajjad 2021-04-24T11:58:28.032700Z

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

Darin Douglass 2021-04-24T13:17:06.033400Z

clojure.data/diff would work as well

👍 1
1
code komali 2021-04-24T14:35:43.036200Z

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 komali 2021-04-24T14:36:29.036300Z

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

borkdude 2021-04-24T14:37:38.037Z

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

borkdude 2021-04-24T14:38:05.037600Z

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

borkdude 2021-04-24T14:38:20.037900Z

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.

2021-04-24T14:42:25.038100Z

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 komali 2021-04-24T14:45:51.040Z

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.

borkdude 2021-04-24T14:46:16.040400Z

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

borkdude 2021-04-24T14:56:32.041Z

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

code komali 2021-04-24T14:57:01.041400Z

@borkdude yes. thanks for helping out!

2021-04-24T16:45:49.042100Z

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

2021-04-24T16:46:08.042400Z

My ns is like this:

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

2021-04-24T16:47:20.042800Z

oh yeah! If I change it to

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

borkdude 2021-04-24T20:02:41.045Z

@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)

borkdude 2021-04-24T20:05:12.045700Z

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

naxels 2021-04-24T20:42:21.046700Z

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

naxels 2021-04-24T20:42:41.047400Z

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

naxels 2021-04-24T20:43:13.048400Z

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

naxels 2021-04-24T20:43:30.049Z

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

naxels 2021-04-24T20:44:01.049900Z

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

naxels 2021-04-24T20:44:26.050700Z

Just not get it working with native-image after compilation

naxels 2021-04-24T20:44:29.050900Z

Thank you!

naxels 2021-04-24T20:45:31.052400Z

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

naxels 2021-04-24T20:45:45.053Z

Earlier commits it was in the globals, worked super fast

borkdude 2021-04-24T21:06:58.055200Z

@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

borkdude 2021-04-24T21:07:24.055600Z

There is also a #graalvm channel

borkdude 2021-04-24T21:08:55.056300Z

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

naxels 2021-04-24T21:09:31.057300Z

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

naxels 2021-04-24T21:11:54.060Z

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

👍 1
naxels 2021-04-24T21:12:21.060700Z

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

ericdallo 2021-04-24T21:39:08.060900Z

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?

borkdude 2021-04-24T21:39:47.061100Z

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

borkdude 2021-04-24T21:40:02.061300Z

since it doesn't know what the project root is

ericdallo 2021-04-24T21:40:35.061500Z

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

borkdude 2021-04-24T21:40:55.061700Z

I think so

ericdallo 2021-04-24T21:40:58.061900Z

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

borkdude 2021-04-24T21:41:06.062100Z

yeah

ericdallo 2021-04-24T21:41:43.062300Z

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

ericdallo 2021-04-24T21:41:56.062500Z

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

ericdallo 2021-04-24T21:42:09.062700Z

So clj-kondo could create and handle that?

borkdude 2021-04-24T21:42:55.062900Z

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

borkdude 2021-04-24T21:43:17.063100Z

since it also benefits itself

ericdallo 2021-04-24T21:45:02.063300Z

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