Fork me on GitHub

Does anyone know why ##NaN (not a number) is a non-negative number? 🙂


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:


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.


Well, is it a negative? No, it's not a negative.


So, it's a non-negative.


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

👍 4

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.


Thanks! Will try adding that and see if the behaviour pops up again


Would it be a good idea for tools like Cider to enable that option by default?


as a dev-time REPL you probably want full stacktraces all the time


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 have a maven target?


why not ask over github issues?

Jakub Holý (HolyJak)17:12:25

Any tips why could this > Exception in thread "Clojure Server repl" 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"?

Alex Miller (Clojure team)17:12:49

Clojure's socket server does not set a socket timeout

Jakub Holý (HolyJak)17:12:00

Indeed. So how is it possible I am getting this exception?!

Alex Miller (Clojure team)17:12:42

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

Alex Miller (Clojure team)17:12:29

In standard JDK, there is .client.defaultConnectTimeout for example, not sure if you're using OpenJDK or Amazon's Corretto or if that has different properties

Alex Miller (Clojure team)17:12:51

it could also be that what you are trying to do needs additional config in the networking setup in aws

Jakub Holý (HolyJak)17:12:38

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

Alex Miller (Clojure team)17:12:34

you might need to set address on the server options

Alex Miller (Clojure team)17:12:01

it defaults to loopback

Alex Miller (Clojure team)17:12:37

might need an ipv6 address for example, etc

👀 4
Jakub Holý (HolyJak)17:12:33

I have to compare to what Jetty is doing because that works. I can try address "" 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 …” ?


I can input it on a repl, I am not trying to programmatically create it


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

☝️ 8

user=> (namespace :)


ok, seems like I am opening a pandora box 😅


since I am trying to create a grammar for clojure I am running into all these edge cases 😕


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

🙏 4

huh, no kidding. Hadn't even considered that.


Why not use something like Sidekiq then? Carmine ships with a redis-based message queue

Eduardo Mata19:12:07

How can I terminate a clojure program if an exception is met?


(System/exit 0) or whatever error code number you want to return.

Eduardo Mata19:12:22



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

🙏 4
💯 4
Eduardo Mata19:12:44

nevermind, it is (System/exit 1)


Do not interleave glue with event specifics


You don’t need core.async or agents for this


and that's off on its own thread, and we're done?


Sure. The whole worker loop is in a thread


Keep it dumb and then refine. Don’t reach to libraries too early

💯 4

Well. That does meet my growing expectation that 5 lines of clojure takes over from huge swathes of library code in my old life.


Consider retry policies, etc.


yeah, here in the first iteration shrugging and making the user try again is OK.

Eduardo Mata19:12:47

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


what do you mean by empty and not being displayed?

Alex Miller (Clojure team)19:12:53

ex-data is just the map of data, not the message. It can be empty.


if ex-data is empty, you will still get a log line for it

Eduardo Mata19:12:59

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

Eduardo Mata19:12:13

19-12-04 19:18:36 Tardis WARN [flowers.stuff:152] - nil


that is a valid return value from ex-data


user=> (ex-data (Exception.))


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 "" ;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
                    (:ip connection)
                    {:username (:username connection) :strict-host-key-checking :no})]
      (ssh/with-connection session
        (repl/migrate (load-config))))))


how do I implement AFn in clojure for a deftype?


(deftype Foo []
  (throwArity [this n]
didn't work


You can do protocols or interfaces like that

Alex Miller (Clojure team)19:12:05

you can either implement IFn or use a proxy


So a somewhat stylistic question:


Say I have a couple of sideeffecting functions, eg


(defn store! [db entity] ...)
(defn publish! [queue entity] ...)
(defn send-email! [srvr entity] ...)


My goto approach for coding up this would be


(->> entity (store db) (publish! queue) (send-email! srvr))


But it feels kind’a wrong, since these sidefeffecting functions should really be returning void.


(doto entity
  (store db)
  (publish! queue)
  (send-email! srvr))


what’s the idiomatic way to do this? doto


yeah, or just do 😛


doto gets the arg order wrong for the example above, but that's easy to fix by rewriting the functions


doto-last 🙂


(doto entity ((flip store!) db)).. blegh... just do would do it for me 😉


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


it’s akin to, queue.publish(entity) etc


so with doto this would be, entity.publish(queue) etc.


That would be like programming with mixins or some such.


or in other programming paradigms it could be an IO Entity state m-word thing

trollface 4

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.

👍 4
clj 20
👀 4

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.

Alex Miller (Clojure team)22:12:15

I don't remember a talk about that, but I have heard the anecdote


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.


that might be from the component talk


Might also be this (not a Clojure talk), but describes the incident


That's it! Glad to know I am not hallucinating (at least in this case). Thanks!

Ivan Fedorov22:12:49

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

Ivan Fedorov23:12:56

I know, right? I’m quite leaning to Ansible though


yaml is gross

Ivan Fedorov23:12:54

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.

Ivan Fedorov14:12:56

@U2FRKM4TW sure! thanks for the input mate!


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


and there is no reason to call keyword on the type from the database


I mean what you’re saying makes sense about IO and stuff. As I said “it’s a stupid question”. I just needed to illustrate the problem.


Thank you guys.


so I can dispatch on “db data” but defmulti would return (:type db-data) then defmethod will have access to it. Makes sense. Thank you @hiredman