Fork me on GitHub
#clojure
<
2016-06-01
>
lmergen10:06:57

ok, given 5 different sequences of the same length L, how do i build a single sequence of objects out of this, with 5 different keys? so, for example, a function that does something like this:

(combine-sequences :a [1 2 3] :b [3 2 1]) -> [{:a 1 :b 3} {:a 2 :b 2} {:a 3 :b 1}]

lmergen10:06:42

looks like mapv is the answer!

m1dnight12:06:19

Is reduce lazy?

m1dnight12:06:17

I want to populate a database (sqlite) with some test data (few million records) and I want to print the progress of the insertion. So I have the following code which is run at compile time:

(let [lines (get-lines "filtered.txt")
      linec (count lines)]
  (reduce (fn [i line]
            (when (= (mod i 1000) 0)
              (println "Lines left: " i))
            (process-message line)
            (dec i))
          linec
          lines))
For some reason, if I don’t put a (println “inserting”) in a method that is called in process-message I get an almost instant printout of Lines left: xxxx

m1dnight12:06:59

That’s kind of odd, since it does show the side effect from the println in the reduce, but not the side-effects of the process-message function 😛

ryanguill12:06:01

@m1dnight: I am a complete noob, so im probably wrong - but maybe get-lines is returning a lazy sequence and you need something like doall or dorun?

m1dnight12:06:41

Hmm, I took care of that in get-lines:

(defn get-lines [fname]
  (with-open [r (reader fname)]
    (doall (line-seq r))))

m1dnight12:06:59

I put on my Holmes hat and took my magnifying glass 😆

ryanguill12:06:38

ah, so thats why I couldnt find docs for get-lines 🙂 yeah dont know then

m1dnight12:06:37

Ugh, I found it. I made a regex booboo. :<

m1dnight12:06:58

I forgot to keep spaces and therefore my algorithm figured all my inputs were single words and ignored them..

ryanguill12:06:47

gotta love regex

james12:06:29

> Some people, when confronted with a problem, think “I know, I'll use regular expressions.” Now they have two problems. <cite>Jamie Zawinski

james12:06:48

Not sure if I agree with it, but it’s a nice quote. 🙂

niquola13:06:21

Stupid question - can lein run multiple commands at once?

niquola13:06:21

I need sequentially;)

niquola13:06:54

Just build time optimization

tap13:06:07

lein do command1, command2, command3, ..

iwankaramazow18:06:30

Uberjar aborting because jar failed: clojure.lang.MapEntry cannot be cast to clojure.lang.IPersistentMap Has anyone else encountered this?

plexus18:06:12

that's a pretty generic error... maybe something funny in your project.clj?

iwankaramazow18:06:19

Could be, I've got absolutely no idea where this is coming from. Development works just fine

iwankaramazow18:06:26

I'll look into my project.clj

plexus18:06:02

I suppose you don't have a stacktrace or any extra information?

iwankaramazow18:06:45

Nothing just that one line

hiredman19:06:44

you have a source file that isn't valid somewhere in your project, an you are doing aot compile all or something that is causing all source files to be loaded with a jar is created

hiredman19:06:21

go through the source files in your project, loading them, and one of them will throw that error with a real stacktrace

hiredman19:06:45

if you put lein in debug mode, it will actually print the stacktrace

iwankaramazow19:06:14

@hiredman: Excellent, I think I found the file. Thanks

hiredman19:06:21

DEBUG=y lein uberjar

josh_tackett19:06:08

Does anyone know how to catch errors in a loop, but make sure they don’t prevent the loop from finishing?

bja19:06:15

josh_tackett: do you want to do anything with those errors?

josh_tackett19:06:33

would be good to print them out

pbaille19:06:53

Hi, how can I eval an AST produced by tool.analyser?

seancorfield19:06:02

Would need to see code to be more specific @josh_tackett

josh_tackett19:06:16

It’s alright I’ll just handle with a try catch

josh_tackett19:06:27

the code is side effecting, so I don’t need the return structure

seancorfield19:06:37

try/catch was going to be my suggestion anyway 🙂

josh_tackett19:06:37

@seancorfield: Hmmm the try catch still get’s stopped:

josh_tackett19:06:38

(mapv #(try (eval (% {:1 (prn (+ 1 1))
                      :2 (/ 1 0)
                      :3 (prn (+ 2 2))}))
         (catch Exception e (str "caught exception: " (.getMessage e))))

      [:1 :2 :3])

josh_tackett19:06:43

here is some example code

genRaiy19:06:03

just discovered that if I use transit with kinesis that I need to exclude jackson.core due to a version conflict - I wasted a shitload of time on this … just wondering where the best place is to post this so that it’s not me blowing it into the wind 😉

conormcd19:06:33

Does it barf earlier or in a more obvious fashion if you use :pedantic? :abort in your project.clj?

caio19:06:21

@josh_tackett: shouldn’t you quote those forms inside the map?

danmidwood20:06:59

Hey #C03S1KBA2, I just hit a problem with upgrading a lein plugin/clojars that I didn't think or expect could happen and which has left me a bit confused and concerned. The lein-release artifact id corresponds to two different projects, lein-release the release plugin https://github.com/relaynetwork/lein-release and lein-release the bundle everything into a tarball plugin https://github.com/technomancy/lein-release (now renamed to lein-tar since ~6 years ago) We were using version 1.0.9 of the former. Running lein-ancient suggested upgrade to 1.1.3 since it's a later version. So I did that and then tried to release my project but got left with a tar file instead

iwankaramazow20:06:06

@hiredman @plexus: solved it, there was a { misplaced in project.clj, thanks for the guidelines

tcrawley20:06:50

@danmidwood: version 1.0.9 of lein-release on clojars is still the relaynetwork version. Are you sure the technomancy version you were using was ever on clojars?

tcrawley20:06:13

it did indeed change

tcrawley20:06:17

that's weird

danmidwood20:06:26

Yeah. Up to 1.0.9 is relaynetwork, on to 1.1.3 is technomancy https://clojars.org/lein-release/versions

danmidwood20:06:52

I guess that Clojars understands that 1.0.9 was released later by timestamp

tcrawley20:06:00

I don't know the history there, but it looks like @kyle.burton may have had rights to the lein-release project, and pushed versions that were older than what was there?

tcrawley20:06:34

I'd file an issue on lein-release and ask for a release higher than 1.1.3 to appease lein-ancient

danmidwood20:06:17

They're not older versions really, just two distinct projects that happen to share the same group/artifact ids

tcrawley20:06:30

right, but lein-ancient has no way to know that

danmidwood20:06:22

Yep. Sorry, I misunderstood what you intended before

tcrawley21:06:13

sorry, I should have said "lower" instead of "older"

danmidwood21:06:34

Np. I'll raise an issue on the relaynetwork github about it

kyle.burton21:06:34

Hi, regarding lein-release, I'm no longer with relaynetwork

kyle.burton21:06:52

so I don't know that I can perform releases of that project at this point.

seancorfield21:06:16

@josh_tackett: Because you are always evaluating (/ 1 0)

seancorfield21:06:58

@josh_tackett:

boot.user=> (mapv #(try (eval (% {:1 '(prn (+ 1 1))
       #_=>                       :2 '(/ 1 0)
       #_=>                       :3 '(prn (+ 2 2))}))
       #_=>          (catch Exception e (str "caught exception: " (.getMessage e))))
       #_=>       [:1 :2 :3])
2
4
[nil "caught exception: Divide by zero" nil]

seancorfield21:06:42

Note that the forms in the map are quoted — so this selects the map entry first, then evals it, and now only the one evaluation fails, and it side-effects to print 2 and 4 as expected and returns nil for those expressions (`prn` returns nil).