This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-05-13
Channels
- # announcements (34)
- # aws (1)
- # beginners (99)
- # boot (19)
- # calva (26)
- # cider (24)
- # cljdoc (8)
- # cljs-dev (29)
- # clojure (107)
- # clojure-dev (3)
- # clojure-europe (12)
- # clojure-finland (1)
- # clojure-italy (24)
- # clojure-nl (5)
- # clojure-spec (13)
- # clojure-sweden (3)
- # clojure-uk (36)
- # clojurescript (4)
- # community-development (14)
- # cursive (3)
- # data-science (6)
- # datascript (57)
- # figwheel-main (3)
- # fulcro (9)
- # graalvm (11)
- # hoplon (18)
- # jobs (1)
- # jobs-discuss (2)
- # joker (10)
- # leiningen (13)
- # off-topic (23)
- # other-languages (1)
- # pathom (24)
- # pedestal (5)
- # re-frame (6)
- # reagent (45)
- # reitit (3)
- # rewrite-clj (1)
- # spacemacs (2)
- # sql (23)
- # tools-deps (6)
- # vim (5)
Decades-long habits are hard to break đ
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)
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.
(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
@lilactown ok, will do
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
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)
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
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
What is the exact meaning of a seq function?
the functions described at the bottom of https://clojure.org/reference/sequences - 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)
I donât want to drag your attention to unimportant details, but nth
appears in the list at the bottom of https://clojure.org/reference/sequences
Also, I noticed that last
works on maps
last is a seq function so coerces to seq
according to the previous definition, last
is not a seq function as it doesnât return a sequence
ok, "most" return a sequence :)
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"
second works on maps
I wanted this so many times... but input may be huge for example. I guess it's hard to solve in general.
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.
"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? https://github.com/kkinnear/zpst
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: - https://stackoverflow.com/questions/42226592/how-to-get-the-values-of-method-local-variables-and-class-variables-using-jvmti - https://github.com/cretz/stackparam
[ANN] Cognitect Labs' aws-api 0.8.305 https://groups.google.com/forum/#!topic/clojure/rKAbv6-U3CM
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?
> (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"]))
What are the exact relationships between collections and sequences? Here https://clojure.org/reference/sequences#_the_seq_interface 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)
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?
@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 https://clojure.org/reference/data_structures#Collections
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
like in scheme and common lisp there are map-hash, map-vector, but in clojure you just use map
?
clojure of course has +
and +'
, but the meaning is much different
@robertfrederickwarner Did you take a look at https://github.com/RackSec/unclogged
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. https://github.com/jnr/jnr-unixsocket, and I'm inclined to trust Charles Nutters' code...)
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 đ
Another question about sequences and collections. In https://clojure.org/reference/sequences#_the_seq_interface 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
http://insideclojure.org/2016/03/16/collections/ 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 :)
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.
maybe share the error?
that was a real spec error, fixed here https://github.com/pedestal/pedestal/commit/64b8f877590c8bb66341544728da576d8e33124f#diff-5695192ae2429b3d8cf22903401a1be9
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 ;)