This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-12-04
Channels
- # adventofcode (154)
- # announcements (1)
- # babashka (8)
- # beginners (28)
- # bristol-clojurians (3)
- # calva (131)
- # cider (43)
- # clj-kondo (14)
- # clojure (135)
- # clojure-europe (1)
- # clojure-italy (7)
- # clojure-madison (1)
- # clojure-nl (6)
- # clojure-spec (8)
- # clojure-uk (90)
- # clojurescript (47)
- # core-async (9)
- # cryogen (4)
- # cursive (12)
- # datomic (9)
- # emacs (7)
- # fulcro (5)
- # graalvm (56)
- # joker (4)
- # juxt (1)
- # leiningen (6)
- # off-topic (62)
- # pathom (4)
- # pedestal (2)
- # reagent (2)
- # reitit (5)
- # ring (2)
- # schema (4)
- # shadow-cljs (133)
- # sql (38)
- # tools-deps (10)
- # vim (28)
What's the definition for non-negative?
? It's not a built-in.
I'm actually more surprised that NaNs return true for number?
and float?
.
I don't know what non-negative?
is, either, but its definition would probably make it clear, once you know how ##NaN
behaves in basic comparisons in Java: https://github.com/jafingerhut/batman
Probably a spec predicate?
There are generators that avoid generating NaN "values", in case they are causing you problems in generative/property-based testing, specifically because they are not =
to themselves.
Yes, excuse me, non-negative
indeed comes from the project that I work on. But the most surprising thing to me is the first one (number? ##NaN)
.
Agreed that sounds weird in English, but both 1.0 and NaN have type java.lang.Double in Java, and number?
's return value is based upon the type of the argument.
I suppose if you can wrap your head around “NaN is not equal to itself,” you can do the same with “Not-A-Number is a number”.
I remember there was a library that takes a regexp and returns a generator that matches that regexp. Does anyone know what I’m talking about?
Sometimes in the middle of a REPL session my exception stacktraces will suddenly stop working - any idea why that could be?
(try (+ 1 nil) (catch Exception e e))
;; => #error {
;; :cause nil
;; :via
;; [{:type java.lang.NullPointerException
;; :message nil}]
;; :trace
;; []}
Very likely you are not using this command line option when starting your JVM: -XX:-OmitStackTraceInFastThrow
Without that option, sometimes the JVM optimizes out stack traces.
Personally, I think it would be a good idea for the JVM to enable that option by default 🙂 But defaults are hard to change when you maintain a system with strong backwards compatibility. You will have to ask on the #cider channel what they recommend. It is pretty easy to copy and paste Leiningen project.clj file templates and clj/clojure deps.edn template files that contain those options.
Aha, I should have tried googling it before asking here 😅 Seems like it's a pretty common problem
I have heard from people running JVM's in production that just about everybody turns it on
i.e. uses that or a similarly effective command line option when starting production JVMs
does cheshire https://github.com/dakrone/cheshire have a maven target?
found it on mvnrepository https://mvnrepository.com/artifact/cheshire/cheshire/5.9.0
Any tips why could this
> Exception in thread "Clojure Server repl" http://java.net.SocketTimeoutException: Accept timed out [at server.clj:111 in (.accept socket)
]
be happening when asking Clojure to start a socket REPL server? (via -Dclojure.server.repl="{:port 55555 :accept clojure.core.server/repl}"
) It works locally but throws these exceptions on AWS Fargate.
What does it mean that (.accept socket)
times out? I am not even trying to connect yet...
(Clojure 1.10.1 on OpenJDK JRE 11 on Linux)
From JavaDoc:
> SocketTimeoutException - if a timeout was previously set with setSoTimeout and the timeout has been reached.
Does it mean that somewhere in the code (though I do not see that) I set a timeout and the server waits max this time for a conn to be made instead of "forever"?
Clojure's socket server does not set a socket timeout
Indeed. So how is it possible I am getting this exception?!
there may be some setting that you can specify in Java as a system property or even at os level that dominates when run in this env
In standard JDK, there is
for example, not sure if you're using OpenJDK or Amazon's Corretto or if that has different properties
it could also be that what you are trying to do needs additional config in the networking setup in aws
I am also running jetty on another port - which I assume also uses ServerSocket - and it doesn't throw exceptions so I do not think there is a system-level property, but will try to verify anyway. Yes, it is possible it is some AWS / Docker weirdness...
you might need to set address
on the server options
it defaults to loopback
I have to compare to what Jetty is doing because that works. I can try address "0.0.0.0"
I guess to star with... Thank you!!!
is this a valid keyword :
? clojure reader seems to accept it but cursive doesnt and from my understanding of the keyword/symbols reference it should not be valid right ?
My understanding is that several chars disallowed in keywords according to the clojure doc, are actually allowed currently. Cursive may be trying to do you a favor by honoring the doc. I suggest asking in #cursive .
@U45T93RA6 maybe my question was not properly formulated. I meant “is this a valid literal keyword …” ?
It is not supported according to the Clojure reference docs, but the Clojure reader accepts things that are not supported, anyway.
“Supported” might be a better word than “valid,” as in “the current reader will accept it, but there’s no guarantee that future versions will.”
you definitely should not use it as a literal keyword, regardless of if the reader accepts it, because the reader will interpret it as a namespaced keyword, which is almost certainly not what you want
since I am trying to create a grammar for clojure I am running into all these edge cases 😕 https://github.com/carocad/parcera
You definitely have some choices to make on whether you want to try to be compatible with some version of Clojure's built-in reader (it has changed only very slowly over different versions, if at all), or use some other behavior/documentation as your reference you are trying to conform to.
There are definitely some chars that are commonly used in keywords for Hiccup syntax, but are disallowed in the docs/spec. For example, "." (period) is not allowed in the keyword name according to the docs, but is very commonly used. So it seems very likely that it will be supported by the reader forever.
Can anyone recommend me either a lib or sample code to get my head around how to structure a background job queue in Clojure? I presume most people roll their own with core.async or similar. I'm coming from using Sidekiq in Ruby and got about 1/3 through inventing my own thing before realizing it's probably simpler than I think it is. (Same-ish use case: return a web request super quick with a 202 Accepted, and spin off a long processing job for the browser to come pick up later).
I'd consider an agent. They have fallen somewhat out of fashion with the advent of core.async but they're still around and working perfectly well. 🙂
Why not use something like Sidekiq then? Carmine ships with a redis-based message queue https://github.com/ptaoussanis/carmine/blob/master/src/taoensso/carmine/message_queue.clj
How can I terminate a clojure program if an exception is met?
(System/exit 0)
or whatever error code number you want to return.
(.System/exit)
?
No need to be fancy. Write one function that takes an event (as a data structure, not wire format) and processes it. Then write the glue code (a glorified polling loop) to process all the events, passing in the desired handler
nevermind, it is (System/exit 1)
Well. That does meet my growing expectation that 5 lines of clojure takes over from huge swathes of library code in my old life.
Howdy!
I am catching an Exception inside a try/catch. I want to display the exception with (timbe/warn (ex-data e))
but it is not being displayed
ex-data is just the map of data, not the message. It can be empty.
it is displayed as nil
if you are not getting a log line, that means you are not catching an exception, either because one is not being thrown, or it is being thrown outside of the scope of your try/catch
19-12-04 19:18:36 Tardis WARN [flowers.stuff:152] - nil
I see
Hi
How could I connect to a Postgres database using tunnel with a bastion in AWS?
I’m trying to do something like this using clj-commons/clj-ssh
but I get timeout connection to the database
(ns app.migrations
(:require [ragtime.jdbc :as jdbc]
[ragtime.repl :as repl]
[clj-ssh.ssh :as ssh]))
(def connection { :ip "0.0.0.0" ;ip of ec2 bastion
:port "22"
:username "ec2-user"
:private-key-path "ec2-key.key" ;ec2 bastion key
})
(def db-spec "jdbc:")
(defn load-config
[]
{:datastore (jdbc/sql-database db-spec)
:migrations (jdbc/load-resources "migrations")})
(defn migrate-implantation
[]
(let [agent (ssh/ssh-agent {:use-system-ssh-agent false})]
(ssh/add-identity agent {:private-key-path (:private-key-path connection)})
(let [session (ssh/session
agent
(:ip connection)
{:username (:username connection) :strict-host-key-checking :no})]
(ssh/with-connection session
(repl/migrate (load-config))))))
you can either implement IFn or use a proxy
(defn store! [db entity] ...)
(defn publish! [queue entity] ...)
(defn send-email! [srvr entity] ...)
But it feels kind’a wrong, since these sidefeffecting functions should really be returning void.
doto gets the arg order wrong for the example above, but that's easy to fix by rewriting the functions
there's a solid idiom of a function that acts like a method taking its object first, and to me those functions are trying to be methods on entity
In typing up the transcript of Rich Hickey's "Clojure Concurrency" talk, and then looking for, finding, and running the code he demonstrated and described during that talk, that was pre-Clojure 1.0 release when he wrote it, and it still runs perfectly with Clojure 1.10.1.

No big news there -- just kind of surprises me, despite already knowing the value Clojure implementers place on backwards compatibility.
Does anyone recall a Clojure talk that discussed debugging the Deep Space 1 mission using a Lisp REPL? I've looked at the conj talks for the last 5 years and I can't seem to find it. Perhaps it was at a different conference or it's just in my head that this talk actually happened.
I don't remember a talk about that, but I have heard the anecdote
https://ti.arc.nasa.gov/m/pub-archive/176h/0176%20(Havelund).pdf <- seems to be specifically about that
Yeah, that's the reference I have for the description of the incident. Perhaps I heard it described in a talk and misattributed it to a Clojure-related conference talk.
Might also be this (not a Clojure talk), but describes the incident https://www.youtube.com/watch?v=_gZK0tW8EhQ
That's it! Glad to know I am not hallucinating (at least in this case). Thanks!
Do we know any Clojure flavoured terraformers like Ansible / Docker-Compose so that I could terraform a dedicated Linux machine to my taste and have this configuration working for the nearest 10 years? I’ll be migrating a legacy project to a new server, will have to install MySQL, Redis, certbot and would like to preserve upstart/systemd init scripts.
I can't imagine any of the tools I've seen for that kind of thing (clojure based or not) being stable across 10 years. I think your best bet is to write a shell script
I know, right? I’m quite leaning to Ansible though
yeah, I know, I know
If you deploy the tool yourself and don't change its version, it won't become unstable.
Otherwise, there are potential problems even with bash
, at least when you suddenly have to deal with an older version.
@U2FRKM4TW sure! thanks for the input mate!
I know, right? I’m quite leaning to Ansible though
Sorry folks, I got another “stupid” question. Is it possible to “pass” data from defmulti to defmethod? It’s somewhat hard to explain, this is what I mean:
;; I have a defmulti that dispatches on the 'type' of a thing,
;; the 'type' can be determined only by
;; fetching data from the db
(defmulti foo [id]
(let [{:keys [type] :db-ctx}] (db/get-from-db {:id id})
(keyword type)))
(defmethod foo :bar-type []
;; now the question is:
;; can I re-use the data fetched from the DB (db-ctx) in the defmethod?
;; so I don't have to send another request
)
doing IO inside a multimethod dispatch seems weird to me
make a function that takes an id, looks it up in the db, then calls the multimethod on the result
I mean technically you could have a memoized function from object to fetched id, but it's still a weird interaction