Fork me on GitHub

is there a variant of map in core or so which runs till the longest sequence ends? (maybe with an extra function which provides for the missing values, or just supporting mapping functions with all of the arities?)


I am nearly certain there is no such variant of map in core.


thanks! must be easy to write one for myself


@UGSM2S2CS I'm curious as to what the mapped function should be passed in the case of a shorter sequence argument "running out"?


(long-map (fn [a b] ???) [1 2 3] [:a :b :c :d]) -- what would a be when b is passed :d?


Also watch out if one of the sequences is infinite. I imagine no core function exists because of these boundary conditions.


not sure really, maybe just a nil or provided default value? (suppose the sequences are homogenous) anyway, just learning this, and the “right padding all vectors with default” was pretty ugly so thought im missing something


I guess I'd push back and ask what problem you're trying to solve? How have you gotten into a situation where this is the function you think you need? @UGSM2S2CS


How many arguments to map do you have? Do you know in advance which are the shorter sequences (and why)?


trying to sum up vector of vectors eg. (apply map + [[1 2 3 4] [10 20 30]])


(FWIW, I don't think I've ever needed this function in a decade of production Clojure so I'm genuinely curious)


and wanted 11 22 33 4 instead of 11 22 33


yes, im probably missing something 🙂


apply map + doesn't look very idiomatic so can you take a step back and explain what problem you're trying to solve?


(I'm out for the evening, but if you answer while I'm gone, I'll respond when I'm back)


Thank you. Actually not even sure how I got here, but what I got is a list of varying-length int vectors where I wanted to sum the rows.

(summ [[1 2 3 4 5] [6 7 8 9] [10 11 12]]) ;=> [17 20 23 12 5]


one way I would approach this problem (without understanding better the actual context) is to explicitly fix the sizes of the arrays

(defn summ [args]
  (let [longest (apply max (map count args))
        fix-size (fn [arr] (concat arr (repeat 0)))]
    (apply map + (map #(if-not (= longest (count %)) (fix-size %) %) args))))


Is it worth learning Java before getting into Clojure/ClojureScript? My background is in JS/Ruby/PHP and I have had very little exposure to Java so far


great advice I once got from here. "Better way to learn Clojure is by learning Clojure" hehehe


@mail188 I think it's good to know at least enough Java to be able to read / write interop code freely. This way you'll have access from your clojure code to many many things that Java and thousands of available Java libraries provide.

✔️ 6

Thanks 🙂 I’ll give Clojure a go and see where I get. I’m sure it can’t hurt to learn a little Java over time

Giovani Altelino17:07:25

IMO, no need to learn Java, at least in my experience from small projects, you will hardly need to use interop for Clojure, it's mostly for Clojurescript and in this case you will use Javascript which you already know.

Quentin Le Guennec17:07:00

yeah no need to learn java, clojure is a language on its own


@mail188 About the only "Java" thing you'll really need to learn to deal with is reading big stack traces 🙂


(you will need to learn some of the JVM ecosystem concepts, like classpath, but you can mostly learn those in the context of Clojure alone, as and when they crop up)


ah I think that’s where I was getting confused (between Java/JVM). Excellent, that means I can keep my focus on Clojure 👍


@mail188 A lot of Rubyists have come to Clojure and like it enough to stay 🙂

💯 3

(my arc was from C++ to Java to Groovy to Scala to Clojure -- with some ColdFusion on the side along the way)


Nice journey! I’ve mostly worked with JS on the front-end so quite excited about ClojureScript. I’ve been getting more interested in functional programming but frustrated that the languages I’ve used are too loose/inconsistent


@seancorfield so it was your first lisp then?


I did quite a lot of Lisp and FP at university in the early '80s. My PhD was on the design and implementation of FP languages so I wrote a Lisp and used it to write various FP languages on top. But there were no jobs in FP so I did C and assembler professionally (and some COBOL), then started my OOP journey with C++ in '92.


I had hoped that Haskell would take the world by storm when it appeared in the early '90s but that turned out to be wishful thinking 🙂


hello, i have two separate projects (folders separated) that i'd like to share a .cljc file between. i created a symbolic link to the file using ln -S sourcefile newlinknameorlocation and just about everything worked perfectly except... the namespace declaration (ns some.nested.folders ) did not transfer easily, so i don't know how to go about it trying to share one cljc file between two projects


how about either making it a third library that both depend on, or giving it a path that works for both projects (and ns to match)


a namespace prefix shouldn't be dictated by file path, the file path should be dictated by the namespace prefix


anyone know how i can sort the following vector

[[\h 1] [\a 1] [\d 2] [\r 2]]
So that it sorts by the second value in each sub vector descending, then the first value in each vector ascending? Best i have so far is (sort-by (juxt second first) xs) But then that returns : ([\a 1] [\h 1] [\d 2] [\r 2]) When I'd like to get back: ([\d 2] [\r 2] [\a 1] [\h 1]) I think I need to use the (sort-by comparater func xs) but I can't get it working over multiple columns


I thinK I Just need to write my own sorting function dont I?


(defn cmp [[a0 a1] [b0 b1]] (let [c (compare b1 a1)] (if (zero? c) (compare a0 b0) c)))

👍 3

@noisesmith like making it its own project and then importing it to the other 2?


right, that's the principled solution, the other suggestion is a hack that would at least work (as would load-file with an explicit file path)


And I use that as the comparer function to sort not sort-by, cheers!


So If I'm understanding that, compare returns 0, 1 or -1. You compare the second item in the second vector with the second item in the first vector, if that's zero (i.e. they are the same, compare the first items) And you use compare x y and compare y x to do > or <


except it's not 1/-1, can be any number, I think user=> (compare \a \c) -2