Fork me on GitHub
#clojure
<
2020-11-10
>
valerauko03:11:42

Is there a feature request for named protocol impls? Currently extend-protocol-defined functions look like this in the stacktrace:

at app.core$eval3547$fn__3548.invoke(core.clj:23)
	at app.core$eval3522$fn__3523$G__3513__3532.invoke(core.clj:14)
Needless to say these aren't exactly descriptive. Not to mention the lines it refers to are where extend-protocol and defprotocol were called, not where the function definition is. I'd hope for something like app.core/MyProtocol/IfaceImplemented/function_name_1234 with the line number where the "offending" piece of code is, not the definition.

didibus03:11:39

I don't know, but http://ask.clojure.org is where you want to look for one. And if you don't find one, create one their, this would be a nice improvement

Alex Miller (Clojure team)03:11:56

without thinking about it a lot, I think this is a lot more complicated than it appears. perfectly fine to file a request at ask.clojure though

didibus03:11:12

How does (fn foo [] "something") work? Just a change to that would probably help, if it just did: at app.core$eval3547$Protocol_function-name__1234 I think that would already help, or even if just function name

valerauko03:11:46

I'll come back after a bit more debugging \

valerauko05:11:01

Getting rid of the eval or fixing the line numbers was beyond me, but I could improve it a little. My logs are now like this:

at app.core$eval3965$ProtocolName__FnName__3966.invoke(core.clj:23)
at app.core$eval3940$ProtocolName3932__3941$__FnName3930__3950.invoke(core.clj:14)
Is this something that could make it into core?

Alex Miller (Clojure team)05:11:26

I can’t answer that without doing a lot more work

👍 3
Alex Miller (Clojure team)05:11:59

The way to start is to put a request on http://ask.clojure.org

👍 3
bronsa10:11:34

you can use extend

👎 3
bronsa10:11:36

user=> (defprotocol p (f [_]))
p
user=> (extend String p {:f (fn string-f [_] (throw (ex-info "" {})))})
nil
user=> (f "")
Execution error (ExceptionInfo) at user/eval233$string-f (REPL:1).

Daniel Stephens12:11:02

Is it documented anywhere how edn/read-string deals with multiple forms? From testing it seems it just ignores anything past a valid first form, regardless of validity. Is this behaviour something that can be relied upon?

Daniel Stephens12:11:46

I read through http://edn-format.org for a while but I might have missed something

borkdude12:11:45

> Reading multiple EDN values from stdin

borkdude12:11:18

(replace stdin with any other reader in your program)

Daniel Stephens12:11:00

thanks, that's interesting, so to read multiples from a string you would first turn it into a stream? At the moment I'm more hoping just to clarify from a security point of view that all further forms are just completely ignored since I currently just need the first form.

borkdude12:11:37

yes, you can rely on that: > Reads one object from the string s.

🎉 3
borkdude12:11:02

With edn/read you can read as many objects as you want from a given reader.

👍 3
Daniel Stephens12:11:23

Oh gah, my bad, I interpreted object a bit more vaguely than is intended!

Daniel Stephens12:11:50

thanks for the help 🙂

👍 3
jmckitrick12:11:44

Has anyone successfully gotten a cloud provider CI/CD to work with a Luminus template project?

emccue19:11:15

I am not using system or anything similar

emccue19:11:45

but using the general design pattern of starting/stopping all stateful stuff in one chunk has been enlightening

emccue19:11:21

(defn create-chat-subsystem
  "Creates an object that holds the info required to manage
  the chat subsystem, including sending notifications to
  users when messages are sent."
  [db ^JedisPool redis-client-pool]
  (let [;; Map of user-id to callbacks to call when a
        ;; new message comes through for them.
        connections (atom {})
        subsystem {::connections connections
                   ;; Objects needed to manage subscribing to redis
                   ;; for messages posted on other nodes.
                   ::redis-client (.getResource redis-client-pool)
                   ::redis-pub-sub (chat-messages-listener db connections)
                   ::subscription-executor (Executors/newSingleThreadExecutor
                                             (-> (BasicThreadFactory$Builder.)
                                                 (.namingPattern "chat-subsystem-%s")
                                                 (.build)))}]
    (.submit (::subscription-executor subsystem)
             (reify Runnable
               (run [_]
                 (utils/restart-on-failure
                   (.psubscribe (::redis-client subsystem)
                                (::redis-pub-sub subsystem)
                                (into-array [(message-key "*" "*")]))))))
    subsystem))

emccue19:11:58

and designing complex stuff like this finally feels tenable

emccue19:11:11

so thanks to just the community at large for emphasizing non-global-ness and managing stateful components

kanwei20:11:42

has anyone seen this issue? we're using CLI/deps and trying to download dependencies results in these errors:

kanwei20:11:47

Downloading: metosin/ring-swagger-ui/2.2.10/ring-swagger-ui-2.2.10.pom from central
Downloading: metosin/ring-http-response/0.9.1/ring-http-response-0.9.1.pom from central
Downloading: cprop/cprop/0.1.17/cprop-0.1.17.pom from central
Download corrupted: Checksum validation failed, expected <html><head><meta but is e77f06aade54d598b1bbbae2b323931860869c21
Download corrupted: Checksum validation failed, expected <html><head><meta but is 6ecc4f0b6bce542e93079bf778210431a6cff9c6
Download corrupted: Checksum validation failed, expected <html><head><meta but is b40aeb79526974d53f99da42b38dea46fffe1ee6
Download corrupted: Checksum validation failed, expected <html><head><meta but is 60283f999a6296706d4595f38a1502b2e6e2ae44

kanwei20:11:00

for pretty much every package

kanwei20:11:32

clean install of clojure still has this issue

walterl20:11:39

My first guess would be that it's an HTTP proxy issue

Alex Miller (Clojure team)20:11:31

you've got bad downloads in your ~/.m2/repository

Alex Miller (Clojure team)20:11:17

this can be the result of a lot of different issues but maven will sometimes download an html error page and save it as a jar/etc

Alex Miller (Clojure team)20:11:08

you could either rm ~/.m2/repository or maybe more selectively remove parts of it to fix

Alex Miller (Clojure team)20:11:16

after that you, should use clj -Sforce to force a re-download of all the deps and compute a fresh classpath

jmckitrick01:11:30

Will that work with loading CIDER as well?

Alex Miller (Clojure team)03:11:43

sorry, not sure what you're asking, sorry

jmckitrick09:11:02

I’ve always used lein with just a little exposure to clj tools. So now that I’m starting CIDER on a clj tools project and running into the same error @U0ELT5ZDE mentioned, I’m not sure how to solve it. I’m going to try clearing m2 again and cross my fingers…..

jmckitrick10:11:43

clj starts fine from any other directory, but in the project, it has the same ‘download corrupted’ and ‘file not found exception’.

kanwei21:11:17

@alexmiller thanks, I tried doing that

kanwei21:11:27

weird thing is that only one computer has this issue

kanwei21:11:30

both clean installs

kanwei21:11:00

nuked the repositories for both, brew reinstalled clojure, etc,

Alex Miller (Clojure team)21:11:45

have you tracked down the file in your repo that's actually an html page and looked at it?

Alex Miller (Clojure team)21:11:02

from the error it looks like it's an .asc checksum file

Alex Miller (Clojure team)21:11:33

probably something in the last dep you downloaded if you've got a fresh repo

Alex Miller (Clojure team)21:11:28

using -Sthreads 1 might help ensure serializability of the log messages too

murtaza5222:11:12

there is an interesting test failure, it seems the sort fn is returning strings in the wrong order -

(is (= '("xd507n6mE"
               "wrMwC27cY7q9T9okmvn8Y"
               "R3aRg3DzZ8Gz21bBmP"
               "Pg1u6YdDNqGf7s3iPMaTllMeP"
               "KREG77"
               "cNITJp"
               "Bcsk9y950nJQZ"
               "84dB5"
               "3zxKEYfyjZAG7saw"
               "26GOS2")
             (sort #(compare %2 %1) '("xd507n6mE"
                                      "wrMwC27cY7q9T9okmvn8Y"
                                      "R3aRg3DzZ8Gz21bBmP"
                                      "Pg1u6YdDNqGf7s3iPMaTllMeP"
                                      "KREG77"
                                      "cNITJp"
                                      "Bcsk9y950nJQZ"
                                      "84dB5"
                                      "3zxKEYfyjZAG7saw"
                                      "26GOS2"))))
the sorted coll below was retrieved from postgresql -
("xd507n6mE"
               "wrMwC27cY7q9T9okmvn8Y"
               "R3aRg3DzZ8Gz21bBmP"
               "Pg1u6YdDNqGf7s3iPMaTllMeP"
               "KREG77"
               "cNITJp"
               "Bcsk9y950nJQZ"
               "84dB5"
               "3zxKEYfyjZAG7saw"
               "26GOS2")
I am trying to test if postgres returned a sorted coll, for that I was running a sort on the returned coll, and interestingly the manual sort returns an unsorted coll !

dpsutton22:11:07

is there a question here? lots of stuff going on here and not sure what you're looking for

murtaza5222:11:39

yup my sort is failing, so trying to understand why ...

murtaza5222:11:36

Expected:
  ("xd507n6mE"
   "wrMwC27cY7q9T9okmvn8Y"
   "R3aRg3DzZ8Gz21bBmP"
   "Pg1u6YdDNqGf7s3iPMaTllMeP"
   "KREG77"
   "cNITJp"
   "Bcsk9y950nJQZ"
   "84dB5"
   "3zxKEYfyjZAG7saw"
   "26GOS2")
Actual:
  ["xd507n6mE"
   "wrMwC27cY7q9T9okmvn8Y"
   +"cNITJp"
   "R3aRg3DzZ8Gz21bBmP"
   "Pg1u6YdDNqGf7s3iPMaTllMeP"
   "KREG77"
   -"cNITJp"
   "Bcsk9y950nJQZ"
   "84dB5"
   "3zxKEYfyjZAG7saw"
   "26GOS2"]
maybe the above is more explanatory

didibus22:11:22

This is the definition of lexicographic ordering. If two strings are different, then either they have different characters at some index that is a valid index for both strings, or their lengths are different, or both. If they have different characters at one or more index positions, let k be the smallest such index; then the string whose character at position k has the smaller value, as determined by using the < operator, lexicographically precedes the other string. In this case, compareTo returns the difference of the two character values at position k in the two string -- that is, the value: this.charAt(k)-anotherString.charAt(k) If there is no index position at which they differ, then the shorter string lexicographically precedes the longer string. In this case, compareTo returns the difference of the lengths of the strings -- that is, the value: this.length()-anotherString.length() For finer-grained String comparison, refer to Collator.

dpsutton22:11:25

how did you come up with your expectation?

dpsutton22:11:44

ah, you want a case insensitive comparison?

dpsutton22:11:15

your fundamental issue is that you don't like that (compare "c" "B") is positive

dpsutton22:11:40

(compare "a" "b") is -1 (a comes before b) but (compare "a" "B") is positive, (a comes after B)

murtaza5222:11:43

aah got you ... its the case sensitivity that is causing the problem

noisesmith22:11:03

you could lower-case in the compare

dpsutton22:11:27

(.compareToIgnoreCase "a" "B")

dpsutton22:11:05

(sort #(.compareToIgnoreCase %2 %1)
            '("xd507n6mE"
              "wrMwC27cY7q9T9okmvn8Y"
              "R3aRg3DzZ8Gz21bBmP"
              "Pg1u6YdDNqGf7s3iPMaTllMeP"
              "KREG77"
              "cNITJp"
              "Bcsk9y950nJQZ"
              "84dB5"
              "3zxKEYfyjZAG7saw"
              "26GOS2"))

emccue00:11:47

(sort-by string/lower-case ...)

emccue00:11:50

will also work