Fork me on GitHub
#clojure
<
2017-11-13
>
RFVenter03:11:04

Hello. I am learning clojure, lambda calculus, computation theory and architectural design

val_waeselynck07:11:52

Well Clojure is a good place to start for this, except maybe computation theory :)

igrishaev07:11:31

@trevor there is built-in feature to re-use connections: http://clojure-doc.org/articles/ecosystem/java_jdbc/reusing_connections.html#using-connection-pooling also, check for special libraries that manage connection pooling. We use https://github.com/tomekw/hikari-cp in our Postgres-driver Clojure project.

igrishaev07:11:18

@trevor moreover, take a look at conman library. It’s a mixture of HugSQL + connection pooling + small details that make everything work fine. https://github.com/luminus-framework/conman

abdullahibra10:11:15

what is the wrong with this code https://gist.github.com/aibrahim/f48b8d35eaa4e63013dd66e07fce47cc StackOverflowError java.math.MutableBigInteger.divide (MutableBigInteger.java:1153)

jeff.terrell12:11:48

A couple nit-picky points about your code: you can omit the commas (they are whitespace in Clojure) and your (zero? (mod n 2)) is equivalent to (even? n). Not a big deal in either case though. simple_smile

abdullahibra10:11:31

why clojure breaks for recursion like this

Olical10:11:17

You're not using tail recursion, so the stack will explode. And I think you're using "normal" integers alongside bigints. It may be out of date, but this could be helpful https://dev.clojure.org/display/design/Documentation+for+1.3+Numerics

Olical10:11:57

I doubt it will fix it but you could try adding an M suffix to your numbers like (/ n 2M). But you may want to redesign your algorithm to use the recur form in the tail position. https://clojuredocs.org/clojure.core/recur

abdullahibra10:11:10

why recursion like this not working in clojure?

timrichardt10:11:35

@abdullahibra also your code will logically never return, if you run (fast-fib 5), you will never reach the the case n=0

timrichardt10:11:50

you always divide the argument by two and call it again

abdullahibra10:11:03

user=> (fast-fib 3) [2 3] user=> (fast-fib 10) [55 89] user=> (fast-fib 5) [5 8]

abdullahibra10:11:14

only added 2M as olical suggested

abdullahibra10:11:32

user=> (fast-fib 100) ArithmeticException integer overflow clojure.lang.Numbers.throwIntOverflow (Numbers.java:1501)

timrichardt10:11:33

should not work...

Olical10:11:54

Because you're not using recur in the tail position though, it will blow the stack at some point.

timrichardt10:11:15

(defn fast-fib [n]
  (if (== n 0)
    [0, 1]
    (let [[a, b] (fast-fib (int (/ n 2)))
          c (* a (- (* b 2) a))
          d (+ (* a a) (* b b))]
      (if (zero? (mod n 2))
        [c, d]
        [d, (+ c d)]))))

jeff.terrell13:11:52

@abdullahibra - In case that wasn't obvious, he put a call to int around the (/ n 2). (/ 1 2) evaluates to 1/2 (the fraction), but (int (/ 1 2)) evaluates to 0.

timrichardt10:11:20

you have to do integer coercion

timrichardt10:11:46

otherwise you never reach the end, tail recursion is not the main problem here

ajs15:11:39

if I have :profiles :dev in my project.clj, under what conditions does that profile take effect by default without my explicit use of with-profile ?

borkdude15:11:18

Why doesn’t run! take an init argument?

ghadi15:11:39

because run! is about consuming each element individually, not accumulating

borkdude15:11:26

ok, I needed some state in my proc (alternating boolean), so I just used reduce

borkdude15:11:45

could have used map-indexed, but doesn’t matter I guess

rauh15:11:56

@borkdude If it's a vector you can use reduce-kv and check for even? / odd? to get alternating booleans

borkdude15:11:21

in hindsight I couldn’t use the index at all, because it depends…

borkdude15:11:39

so I need reduce for sure, but don’t need the end result.. hence my question 🙂

borkdude15:11:05

then again, the end result is a boolean, so who cares.

localghost17:11:35

I have a strange situation. A function works as expected in repl (freshly started, no old state build up) but not from a compiled uberjar.

(defn print-router-config [rcfg]
  (log/info "printing router config")
  (println rcfg)
  (let [cfg (:customer-router-config rcfg)
        fname (str (:region account) "_" (:alias account) "_" (:virtual-interface-id rcfg) "_" (:location rcfg) ".txt")]
    (spit fname (xml->json (xml/parse (java.io.ByteArrayInputStream. (.getBytes cfg)))))))


(defn download-router-config [account]
  (log/info "doing the thing")
  (let [cfgs (get-router-configs account)]
    (println "should map print over cfgs now")
    (println (type cfgs))
    (println (count cfgs))
    (println (type (first cfgs)))
    (map print-router-config cfgs)))
the print-router-config function doesn't get called over cfgs. any pointers appreciated..

hiredman17:11:11

map is lazy

madstap17:11:10

You can simply replace map with run!

localghost17:11:08

thanks @hiredman, @madstap! obviously i don't really understand laziness. reading https://stuartsierra.com/2015/08/25/clojure-donts-lazy-effects now. any other resources/books that may help with clarity?

localghost17:11:50

run! did the trick!! yay. thank you so much.

deactivateduser19:11:13

Apologies if this is the wrong channel, but is anyone else having trouble accessing http://jarkeeper.com/? I'm getting an "Origin DNS error" message from CloudFlare.

seancorfield19:11:20

@deactivateduser10790 Maven Central reported a DNS issue that seems to have screwed a lot of build systems up...

deactivateduser19:11:41

Ah ok - jarkeeper uses central for some of its info, I presume?

danielcompton20:11:06

Jarkeeper is down at the moment, it's been down for a few weeks now

seancorfield20:11:13

I was seeing Travis builds failing all over the place this morning (while trying to release a new version of clj-time).

seancorfield20:11:49

Oh, so this is unrelated? OK, I'll get back in my box... 😈

danielcompton20:11:52

@deactivateduser10790 I just announced https://versions.deps.co/ which provides the same service as Jarkeeper (and was forked from it)

deactivateduser20:11:43

I'm a big fan "public self shaming" as a motivation technique. 😉

deactivateduser20:11:52

Jarkeeper-type tools are great for this.

scknkkrer21:11:42

When I deploy my release to clojars, printing Failed to deploy artifacts/metadata: Cannot access releases with type default using the available connector factories: BasicRepositoryConnectorFactory`

scknkkrer21:11:59

What is that mean ?

tcrawley21:11:11

What tool are you deploying with?

ajs22:11:54

which profile in project.clj is the one that is distributed in a clojars dependency?