Fork me on GitHub
#clojure-uk
<
2016-09-02
>
jasonbell08:09:22

(is it) morning (?)

otfrom08:09:38

jasonbell: it is by UGT

jasonbell08:09:02

well that’s perfect then, morning!

korny11:09:39

happiness this morning, when a random 4clojure solution from years ago came back and was useful

korny11:09:01

so, quick puzzle for the channel - how would you transpose a matrix (i.e. nested vectors) so that (transpose [[:a :b :c][:d :e :f]]) => [[:a :d][:b :e][:c :f]])

korny11:09:51

(solution could use lists or seqs instead of vectors, of course)

djanus11:09:08

(def transpose (partial apply map vector))

djtango12:09:30

I remember I spent a whole day figuring out a recursive solution for transpose then saw that one-liner

korny12:09:14

yeah 🙂

korny12:09:50

I didn’t realize map could take multiple sequences before I came across this problem. It’s such a useful feature, but hard to notice it’s there until you see it in use

djtango12:09:34

One problem with map though is that it stops iterating once it's consumed the shortest list

korny12:09:52

true, but you can do tricks like (concat short-seq (repeat nil))

korny12:09:25

… not much use unless you have one list that isn’t infinite of course!

djtango12:09:22

I found an extend-tuple when browsing the clojure mailing list which also works for finite lists:

(defn extend-tuple
  [default & colls]
  (lazy-seq
    (let [seqs (map seq colls)]
      (when (some identity seqs)
        (cons (map (fnil first default) seqs)
              (apply extend-tuple default (map rest seqs)))))))

djtango12:09:47

what are you up to with matrices?

korny12:09:15

Nothing very complex - I was reading data from a spreadsheet that was in rows and I wanted it in columns

djtango12:09:06

Ah - have been learning machine learning atm so my ears pricked up at the mention matrices

thomas14:09:27

CLojure O’clock clj

thomas15:09:22

so…. I have a compojure app and it has an atom that holds the state (RESTful)…. how do I set the state of atom so that I can test various variations with clojure.test ?

thomas15:09:53

(I have used midje previously, but that doesn’t seem to work with 1.9, so rewriting my tests to clojure.test)

mccraigmccraig15:09:32

@thomas you mean something more than reset! ?

thomas15:09:22

can I just reset the atom from the test file?

mccraigmccraig15:09:19

unless i'm missing something, sure

thomas15:09:36

aah ok.. I didn’t know that. let me give that a try. ta

thomas15:09:22

ok got it working now…. learned something new again 🙂

mccraigmccraig15:09:38

what was the new thing @thomas ?

thomas15:09:56

that you can set an atom in a different file from where it is defined.

thomas15:09:30

I kinda assumed those things are local to the file…. but I had done a require of course on the file I am testing.

thomas15:09:44

and learning clojure.test as well now...