Fork me on GitHub
#clojure
<
2022-01-07
>
Tatiane Berrocal00:01:37

Hey, team! I’m trying to run -M:clojure-lsp format, but the process stop at 10% and doesn’t to show anything. Has anyone had a similar problem? I appreciate any help with this.

ericdallo00:01:38

that's odd, sounds like some kind of corrupted cache, could you try rm -rf .lsp/.cache and try again?

Tatiane Berrocal01:01:03

Now, it worked! Thank you for your help.😀

ericdallo01:01:28

Good, I need to debug further later why sometimes it stuck like that

😃 1
👍 1
V10:01:18

Do you guys know if there is any library which can be used to generate test documentation in clojure?

delaguardo11:01:32

What do you mean by test documentation?

V12:01:44

Well i need to document the tests i have in my project. As to gain an overview of what business logic is being tested. Instead of having to update a document everytime a test is written, i thought it might be a start to generate this documentation using some framework. Maybe adding some metadata to every test and thereby keeping the documentation close to the code and easy to update

Jon Boone14:01:13

Similar to Javadoc, I imagine?

V15:01:36

Yes exactly

bortexz13:01:27

Is it possible to have 2 (:require …) on a namespace declaration? (Thinking about splitting :as-alias requires on 1.11-alpha)

Alex Miller (Clojure team)14:01:50

yes, although why not do them both in the same require?

bortexz15:01:33

just for organization, as I have many namespaces that are only for ns keywords, not code namespaces

bortexz15:01:18

I can have all in one require, this was a nice to have if it was possible to organize the requires that are for code from the ones that are for ns-kw

seancorfield18:01:04

You may find some linters object to multiple :require clauses.

emccue01:01:48

you can always just put a (require …) call outside fo the ns

bortexz10:01:04

thanks all for the answers, clj-kondo doesn’t seem to complain, good to know it works

roklenarcic14:01:26

How can I figure out if some object satisfies a protocol if it is done via metadata? satisfies? returns false when protocol is implemented via metadata

Alex Miller (Clojure team)14:01:32

call a protocol method on it

Alex Miller (Clojure team)15:01:27

in general, I think many uses of satisfies? are a smell that you are putting conditionality outside the protocol instead of inside a default protocol implementation

👍 1
💯 2
✖️ 1
🔢 1
1
vemv15:01:26

I agree, generally I only use it for specs/assertions or such, not for dispatch logic

roklenarcic15:01:56

can a protocol specify a default implementation?

roklenarcic15:01:11

i know multimethods can but a protocol?

p-himik15:01:34

Yes, indirectly. From https://clojure.org/reference/protocols: > To define a default implementation of protocol (for other than nil) just use Object

☝️ 2
Alex Miller (Clojure team)15:01:39

or alternately by wrapping protocol method calls in functions and handling these default in some other way

roklenarcic15:01:45

@U2FRKM4TW that Object impl will take precedence before any metadata based ones so that will effectively disable extension by meta

p-himik15:01:15

Huh, indeed, I didn't know about that.

p-himik15:01:46

Ah, wait, I tested incorrectly. What you wrote seems to be wrong:

=> (defprotocol P :extend-via-metadata true (a [_]))
P
=> (extend-protocol P Object (a [_] (println "a from Object")))
nil
=> (a (with-meta {} {`a (fn [_] (println "a from metadata"))}))
a from metadata
nil

Alex Miller (Clojure team)15:01:29

Per https://clojure.org/reference/protocols, "Protocol implementations are checked first for direct definitions (defrecord, deftype, reify), then metadata definitions, then external extensions (extend, extend-type, extend-protocol)."

Alex Miller (Clojure team)15:01:05

extensions to Object are the last category (external)

roklenarcic18:01:05

Hm it seems I read that wrong

Eugen21:01:01

is there a way to make Clojure use integers instead of longs in a literal? I'm trying to match the data (bellow) with the type definition (above) :

(def emps {:name "EMPS"
           :rowdef [{:name "EMPNO" :type SqlTypeName/INTEGER}
                    {:name "NAME" :type SqlTypeName/VARCHAR}
                    {:name "DEPTNO" :type SqlTypeName/INTEGER}
                    {:name "GENDER" :type SqlTypeName/VARCHAR}
                    {:name "CITY" :type SqlTypeName/VARCHAR}
                    {:name "EMPID" :type SqlTypeName/INTEGER}
                    {:name "AGE" :type SqlTypeName/INTEGER}
                    {:name "SLACKER" :type SqlTypeName/BOOLEAN}
                    {:name "MANAGER" :type SqlTypeName/BOOLEAN}
                    {:name "JOINDATE" :type SqlTypeName/VARCHAR}]
           :data [[100 "Fred" 10 nil nil             30 25 true false "1996-08-03"]
                  [110 "Eric"	20 "M" "San Francisco" 3	80	nil false	"2001-01-01"]
                  [110 "John"	40 "M" "Vancouver"	   2	nil false	true	"2002-05-03"]
                  [120 "Wilma" 20	"F"	nil	           1	5	nil true "2005-09-07"]
                  [130 "Alice" 40	"F"	"Vancouver"	   2	nil false	true	"2007-01-01"]]})

Eugen21:01:50

I'm working to implement a calcite example but I've hit the "Clojure uses long by default" issue here. I can fix the example above by changing the type to BIGINT, but wonder if I can make it work like it is

Eugen21:01:21

besides (int x) in every column - are there other solutions?

hiredman22:01:01

write a function that walks emps calling int on data that has a rowdef of SqlTypeName/INTEGER

dpsutton22:01:49

not following exactly what is going on, but why don’t you have a problem with strings and SqlTypeName/VARCHAR as well?

Eugen22:01:33

strings are mapped OK. Clojure uses long for integer literals. in the library there is a type cast to the sql type and it fails because long is bigger than Integer

hiredman22:01:34

somewhere, it whatever libraries they are using, there is a mapping between java types and sql types

👍 1
Eugen21:01:01

using Apache Calcite. I wrote a small library to interface with clojure. the above example is to demonstrate how to use it on q clojure datastructure.

Eugen21:01:36

I can write sql to filter data from that table

Eugen21:01:53

will make an announcement this week

hiredman22:01:58

common in things like jdbc drivers

dpsutton22:01:52

yes. so if its a problem on insertion, that seems to be the proper answer to me. I was thinking it also might be in comparing results in a test or something as well.

hiredman22:01:14

yeah, hard to say, no idea what emps is being passed to, which is where the error is actually happening, but presumably there is some place where a function f is being invoked on emps

hiredman22:01:44

emps has all the information you need to decide which columns need to be coerced

👍 1
hiredman22:01:22

so write a function g that takes emps and does the coercion, then (f (g emps))

👍 1
Cora (she/her)23:01:49

is count on a vec O(1)?