clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
2020-11-10T00:52:06.284Z

What's different about the use cases?

jimmy 2020-11-10T01:11:31.284200Z

As I see it, specter is motivated by allowing generic, arbitrarily nested transformations. It gives you a grammar to talk about performing "in-place" changes to data structures in a way that scales to arbitrary size and depth. Meander is much more focused on specific transformations that change structure, it has little support for changing something in place and does not help you very much with things of an arbitrary depth. Here is an example use case that motivates meander. https://jimmyhmiller.github.io/building-meander-in-meander

valerauko 2020-11-10T03:27:42.288600Z

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.

bronsa 2020-11-10T10:25:34.292600Z

you can use extend

šŸ‘Ž 1
bronsa 2020-11-10T10:25:36.292800Z

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

2020-11-10T03:40:39.288800Z

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

alexmiller 2020-11-10T03:45:56.289Z

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

2020-11-10T03:49:12.289200Z

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

valerauko 2020-11-10T03:57:46.289500Z

I'll come back after a bit more debugging \

valerauko 2020-11-10T05:05:01.289800Z

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?

alexmiller 2020-11-10T05:16:26.290900Z

I canā€™t answer that without doing a lot more work

šŸ‘ 1
alexmiller 2020-11-10T05:16:59.292Z

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

šŸ‘ 1
Daniel Stephens 2020-11-10T12:20:02.294300Z

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 Stephens 2020-11-10T12:22:46.294400Z

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

borkdude 2020-11-10T12:23:15.294700Z

@dstephens Check out this for reading multiple vals: https://github.com/borkdude/babashka/blob/master/doc/io-flags.md#edn-input

borkdude 2020-11-10T12:23:45.295100Z

> Reading multiple EDN values from stdin

borkdude 2020-11-10T12:24:18.295300Z

(replace stdin with any other reader in your program)

Daniel Stephens 2020-11-10T12:26:00.295500Z

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.

borkdude 2020-11-10T12:26:37.295700Z

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

šŸŽ‰ 1
borkdude 2020-11-10T12:27:02.295900Z

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

šŸ‘ 1
Daniel Stephens 2020-11-10T12:27:23.296100Z

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

Daniel Stephens 2020-11-10T12:27:50.296600Z

thanks for the help šŸ™‚

šŸ‘ 1
jmckitrick 2020-11-10T12:51:44.297300Z

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

emccue 2020-11-10T19:25:15.302100Z

I am not using system or anything similar

emccue 2020-11-10T19:25:45.302800Z

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

emccue 2020-11-10T19:26:21.303100Z

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

emccue 2020-11-10T19:26:58.303900Z

and designing complex stuff like this finally feels tenable

emccue 2020-11-10T19:29:11.304700Z

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

2020-11-10T20:15:42.305600Z

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

2020-11-10T20:15:47.305900Z

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

2020-11-10T20:16:00.306200Z

for pretty much every package

2020-11-10T20:17:32.306600Z

clean install of clojure still has this issue

walterl 2020-11-10T20:19:39.307Z

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

alexmiller 2020-11-10T20:37:31.307300Z

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

alexmiller 2020-11-10T20:38:17.308100Z

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

alexmiller 2020-11-10T20:39:08.308900Z

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

alexmiller 2020-11-10T20:40:16.309500Z

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

jmckitrick 2020-11-11T09:48:02.346800Z

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 @kanwei mentioned, Iā€™m not sure how to solve it. Iā€™m going to try clearing m2 again and cross my fingersā€¦..

jmckitrick 2020-11-11T10:01:43.347Z

clj starts fine from any other directory, but in the project, it has the same ā€˜download corruptedā€™ and ā€˜file not found exceptionā€™.

2020-11-10T21:05:17.310Z

@alexmiller thanks, I tried doing that

2020-11-10T21:05:27.310400Z

weird thing is that only one computer has this issue

2020-11-10T21:05:30.310600Z

both clean installs

2020-11-10T21:06:00.311200Z

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

alexmiller 2020-11-10T21:08:45.312100Z

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

alexmiller 2020-11-10T21:09:02.312400Z

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

alexmiller 2020-11-10T21:12:33.313300Z

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

alexmiller 2020-11-10T21:13:28.313800Z

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

murtaza52 2020-11-10T22:27:12.316700Z

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 !

murtaza52 2020-11-10T22:27:52.317100Z

^ @cldwalker @jimberlage

dpsutton 2020-11-10T22:30:07.317700Z

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

murtaza52 2020-11-10T22:35:39.318300Z

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

murtaza52 2020-11-10T22:36:36.318900Z

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

2020-11-10T22:39:22.319Z

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.

dpsutton 2020-11-10T22:42:25.319200Z

how did you come up with your expectation?

dpsutton 2020-11-10T22:42:44.319400Z

ah, you want a case insensitive comparison?

dpsutton 2020-11-10T22:43:15.319600Z

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

dpsutton 2020-11-10T22:44:40.319800Z

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

murtaza52 2020-11-10T22:44:43.320Z

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

2020-11-10T22:45:03.320200Z

you could lower-case in the compare

dpsutton 2020-11-10T22:46:27.320400Z

(.compareToIgnoreCase "a" "B")

dpsutton 2020-11-10T22:47:05.320600Z

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

murtaza52 2020-11-10T22:58:43.320800Z

thanks @didibus @dpsutton @noisesmith - that solved it !