This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-11-13
Channels
- # beginners (71)
- # boot (61)
- # clara (49)
- # cljs-dev (9)
- # cljsjs (2)
- # cljsrn (5)
- # clojure (55)
- # clojure-android (1)
- # clojure-italy (4)
- # clojure-spec (39)
- # clojure-uk (56)
- # clojurescript (69)
- # cursive (5)
- # data-science (1)
- # defnpodcast (6)
- # devcards (1)
- # duct (12)
- # figwheel (3)
- # fulcro (18)
- # leiningen (35)
- # lumo (19)
- # midje (1)
- # off-topic (22)
- # om (3)
- # onyx (23)
- # portkey (3)
- # re-frame (20)
- # reagent (23)
- # ring-swagger (6)
- # shadow-cljs (119)
- # specter (7)
- # unrepl (25)
Hello. I am learning clojure, lambda calculus, computation theory and architectural design
Well Clojure is a good place to start for this, except maybe computation theory :)
@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.
@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
Hey guys, 4Clojure problems updated on Clojurecademy - https://clojurecademy.com/courses/17592186045426/learn/syllabus
hi guys
what is the wrong with this code https://gist.github.com/aibrahim/f48b8d35eaa4e63013dd66e07fce47cc StackOverflowError java.math.MutableBigInteger.divide (MutableBigInteger.java:1153)
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.
why clojure breaks for recursion like this
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
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
why recursion like this not working in clojure?
@abdullahibra also your code will logically never return, if you run (fast-fib 5)
, you will never reach the the case n=0
you always divide the argument by two and call it again
works
user=> (fast-fib 3) [2 3] user=> (fast-fib 10) [55 89] user=> (fast-fib 5) [5 8]
only added 2M as olical suggested
user=> (fast-fib 100) ArithmeticException integer overflow clojure.lang.Numbers.throwIntOverflow (Numbers.java:1501)
should not work...
Because you're not using recur
in the tail position though, it will blow the stack at some point.
(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)]))))
@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
.
you have to do integer coercion
otherwise you never reach the end, tail recursion is not the main problem here
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 ?
@borkdude If it's a vector you can use reduce-kv
and check for even? / odd?
to get alternating booleans
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..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?
run!
did the trick!! yay. thank you so much.
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.
@deactivateduser10790 Maven Central reported a DNS issue that seems to have screwed a lot of build systems up...
Ah ok - jarkeeper uses central for some of its info, I presume?
Jarkeeper is down at the moment, it's been down for a few weeks now
I was seeing Travis builds failing all over the place this morning (while trying to release a new version of clj-time
).
Oh, so this is unrelated? OK, I'll get back in my box... 😈
@deactivateduser10790 I just announced https://versions.deps.co/ which provides the same service as Jarkeeper (and was forked from it)
I'm a big fan "public self shaming" as a motivation technique. 😉
Jarkeeper-type tools are great for this.