Fork me on GitHub

Hey beginner here, can someone point me to the simplest way to use a java library from clojure? Specifically I want to try using jsyn - I saw it being used in alda and I want to play with it a bit


the easiest way is to make a leiningen project, add the library to your project.clj file, and use it via interop

Mike C08:10:00

I’m trying to make a rake / mix-syle task in Lein, but am getting stuck on passing arguments in. What I want to be able to do is run ‘lein name-mapping foo.txt bar.txt’ and have that run a function for me, passing in the two filenames. Currently I have this in project.clj: :aliases {“name-mapping” [“exec” “-ep” “(use ’ (name-mapping-main)“]})


Tangentially, if you’re interested in command-line clojure, you’ll want to check out planck and/or lumo (if you haven’t already).

Mike C08:10:28

That runs the function, but I can’t get a hold of the arguments: command-line-args is nil in the name-mapping function

Mike C08:10:46

It seems like this should be more straightforward than I’m making it — am I missing something?

Mike C08:10:13

Actually in this particular case it looks like I can alias use lein run -m instead, although I’d still be interested in knowing whether there’s an answer to the exec approach


hello all, does anybody know of something like "lein deps :tree" that makes a propper tree (i.e. not with indents but propper data)


lein vizdeps makes a graphviz graph. I find it much nicer than lein deps tree for reasoning about my deps. It presumably makes some kind of tree to feed to graphviz, maybe you can check out the source code.


Hi Cheenu welcome


When using test.check in a deftest, should I check on the :result that all tests passed. (deftest X (is (:result (tc/quick-check 100 my-prop-test)))


Hello Clojurians 👋 I'm trying to play around with the following vector of maps. I have the definition for the vector example and I'd like to use (map) to add a calculated map to each map within example (e.g. each map's :some-count value divided by the max :some-count: value from the entire vector of maps).

(def example [{:name "Foo" :some-count 18} {:name "Bar" :some-count 24}])
(def max-some-count (reduce (fn [result coll] (max result (:some-count coll))) 0 example))
  (fn [max-count coll] (conj (/ (:some-count coll) max-count) coll))
My example above is currently complaining about an IllegalArgumentException Don't know how to create ISeq from: java.lang.long clojure.lang.RT.seqForm (


do you mean reduce instead of map?


I'm sure there will be a much cleaner / more idiomatic way of achieving this result, so would love seeing these to learn from my mistakes, but the current version is for specific illustration purposes (even though it is probably quite verbose)


Hmmm... Maybe this is a bad use-case for map :thinking_face:


the function you pass to map only takes a single argument if you only pass it one collection


and you can't map over a number


Isn't it taking the max-count ( in the form of max-some-count) and the collection (`example`)?


no, map takes a single function, and any number of collections


Ah, I think you are right, I'm using the reduce argument definition


It's more in line with (reduce f val coll)


I was using (map f val coll), but that is invalid


try replacing max-some-count with (repeat max-some-count)


to make it a collection


I think that gets me a step further, but now I have a ClassCastException


clojure.lang.Ratio to clojure.lang.IPersistentCollection


Let me go back to the drawing board on this and think if I'm approaching this from the right point of view


conj takes the collection first, then the value


Hi again. Is there a way to perform inc on a range?


e.g. take the list from (range 5) and use inc to end with (1 2 3 4 5)


Like, (map inc (range 5))?


You could also just do (range 1 6)?


map is perfect. Thank you Brian 👍


Irony is that I'm trying to use this within an example to better grok map


lol. nice. I wasn’t sure of the context. If it helps, one of the things that made it click for me was seeing stuff like (map :fname people) where a person map might be a huge object with lots of fields. Being able to concisely slice out data is nice.


or like (map #(select-keys % [:a :b]) foo)


Yes, Sundar mentioned the same method to me earlier. That makes sense. I think it's more the joining of different collections that is confusing my at the moment (i.e. (map f c1 c2)). It makes sense when I look at a pre-existing example, but when I try and apply it to something relevant to my types of data sets, I tend to hit a bit of a brick wall, if that makes sense.


Something like this, but potentially with more complex collections (map hash-map (repeat :position) (map inc (range 5)))


(map vector coll1 coll2) can be helpful to understand what arguments the function will be called with.


also zipmap might be what the map hash-map example is driving at?


I'll make a note to look further into zipmap


Might do that once I get my current example working and see how I can improve upon my result 🙂


oh. let’s say you have a list of users and a list of addresses and you want to merge them into something. (map (fn [person addr] (assoc person :address addr)) people addrs)


I think that's a pretty close match for the type of thing I'm trying to get working now


Haha, this feels like a very far distance from being idiomatic: (map (fn [coll cPos] (assoc coll :position cPos)) (reverse (sort-by :follow-count awards)) (#(map inc (range (count %))) awards))


lol. yeah. I’m not sure what the function being mapped over the list is doing (as far as human meaning) but maybe it could be its own function for clarity. also maybe do the counting and incrementing in the fn part since now you’re mapping over the range twice (once for each map used). Am I correct in guessing that awards is a collection of lists?


So "basically" this part (reverse (sort-by :follow-count awards)) is sorting awards (a vector of maps) by the :follow-count key value


☝️ that's the coll argument being passed into f for map


(#(map inc (range (count %))) awards) is generation a list (for cPos argument) of sequential numbers to be used to make a new key-value pair within each hash-map for an "ordering key"


It might be a little redundant (the example), but it's for illustration purposes


ok cool. I think the thing that was giving me pause was that the two collections being fed into the fn were both derivative of the awards collection.


@yogidevbear there’s sort-by which can take a comparison argument to decide the order of the result


oh, you are already using sort-by, and both sort and sort-by take the optional comparison


(ins)user=> (sort > [6 1 2 3 4])
(6 4 3 2 1)
(ins)user=> (sort-by :a > [{:a 6} {:a 1} {:a 2} {:a 3} {:a 4}])
({:a 6} {:a 4} {:a 3} {:a 2} {:a 1})


Is there a way to sort in different directions for juxt? e.g. (sort-by (juxt :parent-name :follow-count) awards) sorts by both :parent-name and :follow-count in ascending order


I want to sort by :parent-name asc, :follow-count desc


(ins)user=> (sort-by (juxt :a :b) (complement compare) [{:a 6 :b 2} {:a 6 :b 3} {:a 1} {:a 2} {:a 3} {:a 4}])
({:a 6, :b 2} {:a 6, :b 3} {:a 1} {:a 2} {:a 3} {:a 4})


oh, mixing asc and desc is trickier


Yip, that's what I'm realising 🙂


instead of (complement compare) you can use a different function, as long as it returns true for the right order of args, and false for the wrong one, when given two args


oh wait, complement compare was totally wrong anyway