Fork me on GitHub

is there a deps.edn version of lein clean?


@wei rm -rf .cpcache 🙂

🙏 1
👍 1
Lennart Buit05:05:06

Maybe drop the -f, removing with force always is ill advised

👍 1

Decades-long habits are hard to break 🙂

Lennart Buit05:05:27

Haha just as guilty ^^!


You can use clj -Sforce to force the dependencies to be recalculated and the cache ignored, but I'm not sure if that overwrites the .cpcache folder...


yes, it overwrites (for the specific command you ran)

Dominic Pearson07:05:27

Does anyone have any experience with jnr-ffi? I am trying to write some clj bindings for a c library. i saw from caesium's source code how to do it when the functions return primitives, but the ones i am trying to bind return structs, and i haven't a clue how to approach it. it looks like, from java examples, that I need to extend the struct class with fields, but i don't know how to do that in clojure.

Dominic Pearson09:05:58

(in jnr-ffi, it looks as though in order to use structs you need to extend the Struct class with additional fields. that's the bit i don't know how to do.)


@lilactown it would be good to wrap your hooks/userReducer to work with multimethods


or maybe even with whatever implementes Ifn


had to wrap it myself


You mean you can't pass a mulimethod to useReducer?


If so can you open an issue please so I remember


and yes that was the issue


multimethods are very convinient with respect to state management


issue opened

Yehonathan Sharvit10:05:35

A question related to maps and sequences. Some of the sequence functions work on map e.g. first, rest, map (they convert a map to a sequence via seq) However nth doesn’t work on a map


nth is for integer indexed cols, maps and sets are not integer indexed

Yehonathan Sharvit06:05:16

Something is still confusing me: On one hand, when we call seq on a map we get a sequence that is not indexed, on the other hand nth works on it

(indexed? (seq {:a 1})) ;; false
(nth (seq {:a 1}) 0) ;;  [:a 1]


In general, ops in Clojure have strong perf expectations and you’d expect nth to only work on indexed things. However, nth has a fallback mode that does a linear search so it works on seqs. This is the only example like this I’m aware of in Clojure (and I believe it’s probably to support destructuring)

Yehonathan Sharvit12:05:07

I see. So now I raise back my original question: why nth doesn’t work on a map (with an implicit transformation of the map into a seq)?


It’s a collection function, not a sequence function, so does no seq coercion


Since maps are unordered, asking for the nth thing is meaningless


If you explicitly convert to a seq, then you have something ordered, and you can ask the question

Yehonathan Sharvit12:05:53

Would it be accurate to say that seq coercion occurs only inside functions where the perfs on seq are good?


No, seq coercion occurs on all seq functions


Not a perf thing

Yehonathan Sharvit13:05:57

What is the exact meaning of a seq function?


the functions described at the bottom of - functions that take a seqable as last arg and return a sequence (really a seqable)


as opposed to collection functions which take a data structure as first argument and operate on the data structure (assoc, conj, nth, disj, contains?, get, etc)

Yehonathan Sharvit15:05:37

I don’t want to drag your attention to unimportant details, but nth appears in the list at the bottom of Also, I noticed that last works on maps


last is a seq function so coerces to seq

Yehonathan Sharvit19:05:11

according to the previous definition, last is not a seq function as it doesn’t return a sequence


ok, "most" return a sequence :)

Yehonathan Sharvit10:05:42

Is there a good reason for that?


hash-things (hash-map and hash-set) has no notion of order. Do not make sense ask for "the second item" first and rest make some sense once you can understand "give me 'any' first item"

Yehonathan Sharvit10:05:21

second works on maps


who could agree with me: stacktraces should show what was the input...


I wanted this so many times... but input may be huge for example. I guess it's hard to solve in general.


so it should be in a separate stacktrace like *e2 or something...


disagree, this is one way for personally identifiable information to end up in logs


This could be enabled only in "dev" mode. But I guess the problem is that it really isn't that easy - exceptions can occur at many different levels - at each step you'd need to capture the input and possible decide whether (and what) to show it.

👍 1

does clojure have a trace (from CL) equivalent?


"Whenever a traced function is invoked, information about the call, about the arguments passed, and about any eventually returned values is printed to trace output."

(defun fact (n) (if (zerop n) 1 (* n (fact (- n 1)))))
=>  FACT
 (trace fact)
=>  (FACT)
;; Of course, the format of traced output is implementation-dependent.
 (fact 3)
>>  1 Enter FACT 3
>>  | 2 Enter FACT 2
>>  |   3 Enter FACT 1
>>  |   | 4 Enter FACT 0
>>  |   | 4 Exit FACT 1
>>  |   3 Exit FACT 1
>>  | 2 Exit FACT 2
>>  1 Exit FACT 6
=>  6


Yes, this is useful and something I (sometimes) use (via Cider). However, you need to instrument the function beforehand - it may be harder if the error isn't that easy to reproduce (which is a problem anyway) or it may just took way longer or it may be deep down in java call stack...


haven't tried this, but does this help at all?


Not sure how practical this approach is, but I think you ultimately need JVMTI agent (or something equivalent) - this could be an interesting thing to explore: - -

👍 1

Can I make (instance? "Ljava/lang/Integer;" x) work? (`instance?` rejects strings as criteria)


which is logical because an array is not an object... anyway my question stands - can I check if something is an array of x?


ok, this is a FAQ easy to find, sorry for the noise


> (instance? (Class/forName "[Ljava.lang.String;") (into-array String ["s"]) ) => true


Nice one! I ended up avoiding the scary notation completely: (instance? (class (make-array String 0)) (into-array String ["s"]))

Yehonathan Sharvit15:05:08

What are the exact relationships between collections and sequences? Here the Seq interface is describe by means of 3 functions first, rest and cons but in the description (and the signature of the function), the term collection is used instead of sequence. Can someone clarify it?


sequences are (logical) collections


Collections are (in Clojure) defined by IPersistentCollection


Sequences are defined by ISeq (which extends IPersistentCollection)


IPersistentCollection extends Seqable (to request a seq view of a collection)

Yehonathan Sharvit15:05:51

Thanks @alexmiller. I am going to meditate on it


One thing I think is useful when contemplating sequence vs. collection: A collection is a finite, non-scalar grouping of some 'things', e.g. List, Vector, Set, Map. A seq is an interface to data that makes sense to apply to collections, and also to non-collection, infinite things like (range), (iterate), (cycle), et al. You can compute infinities with a seq, but not with a collection.


given that sequences are collections, collections are not necessarily finite


one term used in some of the clojure reference docs to refer to list, vector, map, set. sorted set, sorted map, etc is "data structure", which are finite


there is no "type" in the Clojure impl that contains those data structures but not sequences


sometimes "collection" is used to mean "the data structures but not seqs" and sometimes it is used to mean "all collections, including seqs". this is not done consistently either in the docs, or the code, or the broader community.


Yeah, it's worthwhile to understand the context that the word 'collection' is being used, with more precision than 'talking about Clojure the language'


I need to write some code that writes to a unix socket (in this case, /dev/log so I can write a timbre appender to send logs direct to syslog). Right now I'm puzzling my way through netty code as it seems to be the only java library that packages the native integration sensibly, but their relative lack of docs is making that pretty slow going. Does anyone know of a clojure library/feature I may have missed for doing so?

Yehonathan Sharvit17:05:32

@alexmiller I am trying to understand exactly what is the meaning of “Collections are represented by abstractions, and there may be one or more concrete realizations.” from


I think it means that the actual underlying type might change, but the interface will stay the same if you have an operation that produces the same collection type


for instance, I believe Clojure maps use a PersistentArrayMap under the hood up until a certain size, which then switches to a different type PersistentHashMap


for various performance reasons


like in scheme and common lisp there are map-hash, map-vector, but in clojure you just use map?


this difference is opaque to you, because they have the exact same interface


yes, the seq interface is even more general


i think F# is kinda annoying in this way.


it must have gotten it from OCaml 😛 +, +., oh-my!


clojure of course has + and +', but the meaning is much different


Yes, unfortunately only supports udp/tcp (and is also abandoned)


If Unix socket's a hard req I dunno if there's much pre-existing help out there. You can find some other stuff that'll do the JNI lifting for you (e.g., and I'm inclined to trust Charles Nutters' code...)


But you're still gonna be doing the Java interop yourself


Yeah I'm chatting with our sysadmins to see if they'll consider opening up a plain old net socket, that'll simplify things considerably


jnr-unixsocket looks like a possible option though, much simpler than going the netty route. thanks 🙂

Yehonathan Sharvit18:05:17

Another question about sequences and collections. In the Seq interface is said to be made of first, rest and cons. Why empty? is omitted?


empty? is just the negation of clojure.lang.RT/seq

alexmiller18:05:35 expands on the question above in a lot more detail


and also in Clojure Applied, ch 2, which has a great picture that I am unable to share with you due to copyright :)

Yehonathan Sharvit19:05:46

No worries. I have this book


So, I have a weird problem where I removed a circular namespace dependency, and now I'm getting a spec failure on ns inside a third party library. If I put it back, it works.


I'm baffled at how to even debug this.


maybe share the error?


prob your prior cycle was hiding the load of it somehow


latest pedestal is 0.5.5


not sure when that was fixed exactly


I guess it was in 0.5.5


you'll only see that fail as of Clojure 1.10.0


welp, I figure you've just saved me three hours of debugging. I'll buy you some kind of bevarage at the next conj.


no need, happy to help ;)