#clojure logs

2015-08-26

00:01amalloy,(/ Math/PI 4)
00:01clojurebot0.7853981633974483
00:01amalloyi think i actually meant pi/2 when i claimed cos(x)=x would be between pi/4 and 0, but i happened to get it right
00:03neoncontrailsClever, clever
00:06neoncontrailsSo this isn't quite right
00:06neoncontrails,(defn fix-iter [f initial] (take-while (fn [x] (not (= x (apply f x)))) (iterate (fn [x] (apply f x)) initial)))
00:06clojurebot#'sandbox/fix-iter
00:07neoncontrails,(fix-iter Math/cos 1)
00:07clojurebot#error {\n :cause "Unable to find static field: cos in class java.lang.Math"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to find static field: cos in class java.lang.Math, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6704]}\n {:type java.lang.RuntimeException\n :message "Unable to find static...
00:07amalloyneoncontrails: you just mean (f x), not (apply f x)
00:07TEttinger,(reduce #(if (= %1 %2) (reduced %2) %2) (iterate #(Math/cos %) 1))
00:07clojurebot0.7390851332151607
00:07amalloyTEttinger: we are letting neoncontrails write it
00:07amalloyit is not a difficult exercise for you to do
00:07TEttingerI didn't know if it would work
00:07TEttinger(also I was going to guess mine was going to take forever)
00:08amalloyand also Math/cos isn't a function, as you discovered, neoncontrails; you need to wrap it up in one via #(Math/cos %)
00:09sdegutis,(map (comp first (juxt identity (comp prn inc))) [1 2 3])
00:09clojurebot(2\n3\n4\n1 2 3)
00:09sdegutisbwahaha
00:09neoncontrailsOh, that makes sense. I was about to say, it didn't work before in the absence of (apply ...) either
00:09sdegutisit's like tap
00:09TEttingerthat's a clever technique though, neoncontrails, to avoid passing pairs by actually generating the next element in the function that is passed to take-while that can't take 2 args
00:12amalloyTEttinger: there is a rather simpler way to avoid generating pairs, which is to just write the tail-recursive function yourself
00:12amalloy(defn fix [f x] (let [y (f x)] (if (= x y) x (recur f y))))
00:12amalloy,(defn fix [f x] (let [y (f x)] (if (= x y) x (recur f y))))
00:13TEttingerwe seem to have found remarkably similar methods
00:13clojurebot#'sandbox/fix
00:13amalloy,(fix #(Math/cos %) 1)
00:13clojurebot0.7390851332151607
00:13sdegutisWhy did I need to do `lein clean` before (-> (require 'my.namespace) (ns-publics)) saw the new vars during `lein run`?
00:13sdegutisBtw that's pseudocode, the point is the main thing.
00:16neoncontrailsI'm getting flashbacks to Ch1 SICP... very useful to see the tail-recursive control flow mapped to Clojure
00:18sdegutisamalloy: do you know?
00:29sdegutisIs *ns* not guaranteed to be the last value of (ns)?
00:29sdegutisAh right, only at compile-time is it meaningful. At runtime it's who knows, in this case user.
00:32sdegutis...
00:32sdegutisRaise your hand if you have me on /ignore
00:32TEttingerhi sdegutis
00:32sdegutis:)
00:32sdegutisHow re you TEttinger2
00:33TEttingerI'm not sure why lein clean is sometimes necessary
00:33sdegutisFwiw I solved the second problem with (def this-ns *ns*)
00:33TEttingerusually it's gen-class or java-related
00:33sdegutisAhh could be that. Thanks.
00:33sdegutisamalloy: you didnt raise your hand
00:34TEttingergen-class only happens when you compile, and while lein run probably could be cleaning beforehand, I don't know if all versions do.
00:34sdegutisVery good point.
00:35TEttinger(it might be compiling only things that don't already have compiled versions in the output)
00:35sdegutismakes sense
00:35TEttinger(which would save a lot of time, yeah)
00:35TEttingerif it did a full recompile every time you did lein run, and you had a lot of gen-class stuff that hadn't actually changed, it would be slow
00:36sdegutistrue
00:36TEttingerbut I don't know how lein works really.
00:44sdegutisIs it possible to recreate something like (:require [my.namespace :as foo]) outside of (ns)?
00:44sdegutisAh, alias I think.
00:46sdegutis,(do (alias 's 'clojure.str) s/join)
00:47clojurebot#error {\n :cause "No namespace: clojure.str found"\n :via\n [{:type java.lang.Exception\n :message "No namespace: clojure.str found"\n :at [clojure.core$the_ns invokeStatic "core.clj" 4011]}]\n :trace\n [[clojure.core$the_ns invokeStatic "core.clj" 4011]\n [clojure.core$alias invokeStatic "core.clj" 4113]\n [clojure.core$alias invoke "core.clj" -1]\n [sandbox$eval25 invokeStatic "NO_SOURCE...
00:47sdegutis,(do (alias 's 'clojure.string) s/join)
00:47clojurebot#object[clojure.string$join 0x251f2a0a "clojure.string$join@251f2a0a"]
00:47sdegutisPhew.
00:51darth10//whois darth10
00:51darth10oops
00:54crocketIt seems clojure is a very practical community.
01:20cljnewbiehaven't got any response in #clojure-beginners, so maybe you can answer my supposedly easy question: https://www.refheap.com/921878412593a9371d1560eb5 :)
01:22rweir"Duplicate teste" <- really?
01:22luxbock,(doc case)
01:22clojurebot"([e & clauses]); Takes an expression, and a set of clauses. Each clause can take the form of either: test-constant result-expr (test-constant1 ... test-constantN) result-expr The test-constants are not evaluated. They must be compile-time literals, and need not be quoted. If the expression is equal to a test-constant, the corresponding result-expr is returned. A single default expression can foll...
01:23luxbockI think the issue is that the (key-code :kw) is not interpreted as an expression inside case
01:23amalloycljnewbie: case expressions must be constant
01:23amalloy"The test-constants are not evaluated."
01:23cljnewbieamalloy: ah :) thank you very much
01:24amalloyso in fact (key-code :dpad-up) will match either the symbol key-code or the keyword :dpad-up
01:24cljnewbiecljnewbie: so the cond is the straight-forward way to write this or do you see a more elegant way to write this?
01:25cljnewbiealloyed: see above :)
01:25luxbockcljnewbie: check out condp
01:25cljnewbieamalloy: see above... sorry channel, my coffee-level is too low currently
01:25cljnewbieluxbock: thanks
01:25cljnewbiealloyed: sorry for the misplaced ping
01:26amalloyright, (condp = (:key screen) ...) is the easiest way
01:33cljnewbieworks, excellent. thanks everyone
01:37jeayecljnewbie: Also, note that your println has a typo, the last one.
01:38cljnewbiejeaye: thanks, if written the cond-version afresh though
01:39cljnewbiecondp*
02:39en590hi everyone
04:21Rurik_#j #clojure-beginners
04:21Rurik_err
04:21Rurik_sorry
04:25Rurik_can anyone explain why a list is quoted?
04:26TEttingerRurik_: do you mean like '(1 2 3) ?
04:26Rurik_yep
04:26TEttingerthat's because if you don't quote a list, it's treated as a function call
04:26TEttinger,(+ 1 2 3)
04:26clojurebot6
04:26Rurik_ah
04:27Rurik_silly me
04:27Rurik_I forgot the first thing bout lisp
04:28TEttingervectors are the most common way of putting data in a program in a list-like form, in clojure. I can't remember the last time I used '(1 2 3) instead of [1 2 3]
04:28TEttingerthere are cases for it
04:29Rurik_TEttinger: I am doing the clojurescript koans
04:29TEttinger,(conj '(1 2 3) 4)
04:29clojurebot(4 1 2 3)
04:29TEttinger,(conj [1 2 3] 4)
04:29clojurebot[1 2 3 4]
04:30expezIs Luke VanderHart, aka levand, of quiescent fame ever around these parts?
04:45Rurik_What would be the answer to this koan? Higher-order functions take function arguments
04:45Rurik_(= 25 ( (fn [n] (* n n))))
04:46Rurik_nvm, solved
05:02Rurik_'(filter (fn [x] false) '(:anything :goes :here))
05:02Rurik_uh
05:02Rurik_,(filter (fn [x] false) '(:anything :goes :here))
05:02clojurebot()
06:03negaduckhi! Are transducers a replacement for reducers? I'm a bit confused. Please give me a hint when reducers better suit the job. Is it about r/fold, which can do parallel execution?
06:05dstocktonnegaduck: http://blog.cognitect.com/blog/2014/8/6/transducers-are-coming
06:06dstocktonthey are not a replacement but a further abstraction
06:10clgvhyPiRion: ping
06:12hyPiRionclgv: pong
06:13negaduckdstockton: do I get it right that if I need either of them, I just use transducers
06:14clgvhyPiRion: about the leiningen self-signed certificate issue - did Leiningen 2.5.0 check the certificates at all?
06:14hyPiRionclgv: yes
06:14clgvhyPiRion: I commented the :certificates option and 2.5.0 still works
06:14negaduckcould you give me a hint, when should I use reducers instead of transducers?
06:15clgvnegaduck: when you need built-in parallelization
06:15hyPiRionclgv: what do you mean by works? It lets you upload/deploy stuff without checking the cert?
06:16clgvhyPiRion: it lets me download/check artifacts without checking the certificate as it seems
06:16clgvhyPiRion: so the expected pem-file just contains the certificate I want to trust, right?
06:16hyPiRionclgv: right
06:17clgvhyPiRion: then it seems to me that 2.5.0 just does not check the certificate and from 2.5.1 the check is done but the specification of my pem file is ignored
06:18hyPiRionclgv: 2.5.1 should die if you specify certificates, so I guess the profile is shadowed
06:19clgvhyPiRion: my pem file contains the first part wrapped in BEGIN CERTIFICATE and END CERTIFICATE that you get when querying openssl s_client -showcerts -connect myrepository.tld:443 </dev/null
06:19hyPiRionclgv: yep, that's what it's supposed to be
06:19clgvhyPiRion: and 2.5.2 should work with the :certificates setting
06:19hyPiRionright
06:20clgvhyPiRion: :certificates is a toplevel option in project.clj as shown in the sample-project.clj right?
06:20hyPiRionclgv: right
06:20hyPiRionI'll be back in 30-40 mins
06:21clgvok. I'll update the issue meanwhile
06:27tdammersI have a project here where lein install works fine, but lein tests throws compiler errors in the project's core module
06:27tdammersa :require from core.clj fails
06:28tdammersany ideas how that is possible?
06:33clgvtdammers: some error in your testcode
06:34tdammersclgv: really? an error in my test code can cause a :require in the tested code to fail?
06:34tdammersactually, the :require also fails when doing it from the repl
06:34clgvtdammers: or some dependency problems with :dev :dependencies
06:35tdammersI don't have any :dev dependencies
06:35clgvtdammers: you description is too vague to do more than guessing ..
06:35tdammersyeah, I was afraid it would be
06:35clgvmake a minimal example that still fails and load that up
06:36tdammersthat's gonna be tricky, but I'll try
06:36clgvtdammers: maybe you already find the problem like that
06:37tdammersI'm familiar with the routine
06:37clgvtdammers: investigate the stacktrace/causetrace of the exception more closely
06:37tdammersit says that it can't find the thing I'm trying to :require on the classpath
06:40tdammersgreat, my minimal example doesn't fail
06:41tdammersoooooooooh...
06:41tdammers[org.clojure/clojure "1.6.0"]
06:42tdammersthat one fails
06:42tdammersbut if I change it to 1.7.0, it works
06:47clgvtdammers: that's weird. so maybe you are using a 1.7.0 feature? new function or similar? that might prevent the namespace from being compiled (exception) and hence it is "not found"
06:49tdammersyeah, that library I'm using uses cljc
07:21kungihow can I check if a vector of instants is in time increasing order?
07:21clgvhyPiRion: I confirmed that the file in :certificates is actually read by using a damaged certificate file which resulted in a different exception within sun.security.x509.X509CertImpl
07:21kungiI cannot use > or < because they compare numbers ....
07:22clgvkungi: you can reduce over the vector and short circuit on order violation via `(reduced false)`
07:23clgvalways return the new instant from the reducing function
07:23clgvkungi: or did you mean how to compare two instants?
07:24kungiclgv: no I meant something like (is (apply > [vector-of-instants]))
07:25clgvkungi: (reduce (fn [a, b] (if (instant-larger? a b) b (reduced false))) vector-of-instants)
07:26clgvkungi: you'll end up either with `false` or the smallest instant
07:26clgvwhich is truthy
07:26kungiwhat is "(reduced false)" ?
07:26TEttingerit's cool.
07:26clgv,(doc reduced)
07:26clojurebot"([x]); Wraps x in a way such that a reduce will terminate with the value x"
07:26kungiOh!
07:27TEttingerit shortcuts the reduce call to end early
07:27TEttingeramazing stuff
07:27TEttingerhere it will just return false
07:27kungiThis is much nicer than my solution :-) I converted all the instants to longs and used ">"
07:27TEttingerbut you can have it return other stuff too
07:28clgv,(reduce (fn [s, x] (if (< x 4) (+ s x) (reduced s))) (range 10))
07:28clojurebot6
07:28lumafi(every? (partial apply before?) (partition 2 1 vector-of-instants))
07:28lumafithis should also work
07:28lumafior #(before? %1 %2) instead of the partial
07:28clgvlumafi: but it's pretty complex in comparison
07:29clgvand lazy
07:29clgvthe `partition` part I mean
07:30kungilumafi: hmm this does not test monotonically increasing if I see correctly. because it only comepares value 1 and 2, 3 and 4 ...
07:30lumafikungi, it compares 1 and 2, 2 and 3, 3 and 4 etc.
07:30kungilumafi: oh sorry i did not see the 1 in the partition
07:30en590hi every1
07:30lumafi,(partition 2 1 (range 5))
07:30clojurebot((0 1) (1 2) (2 3) (3 4))
07:32en590do any of you all have clojure jobs?
07:34kungien590: I made my own :-)
07:34clgven590: if you count university jobs, then yes ;)
07:38en590that's cooler than what i want to do just work for some company that uses clojure
07:39en590but i gotta learn a lot more first can't keep being distracted by irc
07:42phillordJust on the off-chance, has anyone written a library for easy invocation of Maven from Clojure?
08:02schmirphillord: look at what leiningen itself is using
08:05clgvphillord: there are libs for calling external programs, if that is what you mean by "invocation of maven"
08:07phillordclgv: Yeah, I could do that, I think I may have to
08:08phillordWhat I have done is used maven to launch an nrepl and I was toying with the possibility having maven run goals within the same JVM
08:08phillordI suspect that it's going to be more effort than it is worth
08:17clgvphillord: ah I see, you'd have to check whether maven has an API for that
08:48OlajydWhat is the difference between the `pmap` and `map`, I don’t really undersatnd the documentation :|
08:49gilliard,(doc pmap)
08:49clojurebot"([f coll] [f coll & colls]); Like map, except f is applied in parallel. Semi-lazy in that the parallel computation stays ahead of the consumption, but doesn't realize the entire result unless required. Only useful for computationally intensive functions where the time of f dominates the coordination overhead."
08:49TEttingerOlajyd: pmap should have the same result as map, but sometimes does it faster (and often slower)
08:49gilliard"f is applied in parallel" - ie using multiple threads.
08:49TEttingerusually you're better off with map
08:50OlajydTEttinger, Hi.. :)
08:50TEttingerhello!
08:50Olajydgilliard too, hello :)
08:50gilliardHi :)
08:51gilliardmap is like asking a kid to get your shopping. pmap is like asking ten kids to get 1/10 of the shopping each.
08:51TEttingerif you have a function that uses a lot of CPU and can be run in parallel, pmap can use multiple threads to allow a multicore processor to be fully used (disk reading stuff would probably not benefit from this, but looping over many millions of complex pieces of data in each run of the function would)
08:52TEttingergilliard: yeah, and they all wait in the same line at the store
08:52TEttingerthere's some overhead for each one
08:53Olajydgreat
08:53Olajydso say (defn foo [x] (let [aa @a] (swap! a (fn [&args] x)) aa)), and (def a (atom 0)) (map foo (range 1 20))
08:53Olajydand using (def a (atom 0)) (pmap foo (range 1 20))
08:54Olajydwill produce different results I guess?
08:55TEttingerI would assume so. (swap! a (fn [&args] x)) can also be written as (reset! a x)
08:57TEttingerclojure has some tools to help with this though. one good one is that swap! with the right functions can be used just fine with pmap
08:57TEttinger,(def a (atom 0))
08:57clojurebot#'sandbox/a
08:57TEttinger,(defn foo [x] (let [aa @a] (swap! a inc)))
08:57clojurebot#'sandbox/foo
08:57TEttingerI can't pmap in a sandbox
08:58TEttinger,(map foo (range 1 20))
08:58clojurebot(1 2 3 4 5 ...)
08:58OlajydTEttinger, I was advised to not get used to using atoms to mutate data structures, and sometimes I’m tempted to do so, because I probably need to update a particular data structure to perform other functions.
08:58TEttingerorder doesn't matter for inc, or any addition by a constant
08:58TEttingeryeah, there are some good ways to handle mutation in a contained area if you need it
08:59TEttingerloop and recur are used together to do all sorts of code that can replace mutation.
09:00TEttingertransients are mutable snapshots of a clojure data structure, that must become immutable again by the time the function ends
09:00Olajydhmmm
09:01TEttingertransients don't support the whole seq-based set of fns in the standard lib
09:01TEttingerloop and recur are a bit tricky at first but really do a lot of things
09:01TEttingerif you need to perform other functions, that sounds like a loop situation
09:04TEttingerthe really good thing about loop is that you control when, and how, you go into the next iteration by using recur, even if you have multiple bindings that are being updated in each iteration.
09:05TEttingerwith map, an iteration is just a function called on one element of each collection you pass it. with for, it's a combination of every grouping of collections. but with loop, you could recur in more elaborate ways
09:07Olajydok, say I want to do a loop into a map, is this possible
09:08OlajydPlus can we keep track of state in a map?
09:09TEttingersort of. state-tracking is easier with loop, and possible though not always easy with reduce (which can produce a collection too!)
09:09TEttingerdo you have an example?
09:09TEttingerof what you use an atom for now?
09:13OlajydIts in relation to the problem you help me solve the other day
09:19sdegutisHello.
09:20TEttinger&(loop [coll [1] state 1] (if (> (count coll) 10) coll (recur (conj coll state) (+ (last coll) state))))
09:20lazybot⇒ [1 1 2 3 5 8 13 21 34 55 89]
09:20OlajydTEttinger, so my PM says the rows in of type `JavaRDD` which is similar to clojure lazy-sequence, There’s no inherent way of changing the type from clojure lazy sequence to type JavaRDD, and like you suggested, I could use an atom to keep track of state, or use reductions (which will work a given sequence or clojure lazy sequence) but will not work for the particular data type, he wants me to apply that function to. So I used an atom to hack my way throu
09:20Olajyd:), now we dont want to use an atom but come up with another way of fixing the problem
09:20sdegutisIf you do (require 'foo) instead of (ns (:require [foo])), how can you then do (foo/bar) somewhere inside that namespace without the compiler claiming that namespace 'foo doesn't exist?
09:21TEttingergotcha
09:21TEttingerOlajyd: it's likely the JavaRDD is mutable, and you can use mutable java objects just fine from clojure
09:22OlajydTEttinger, anyone in particular?
09:22TEttingerhow is it like lazy sequences?
09:22TEttingeruh, let's see
09:23justin_smithsdegutis: you can't, you'll have to use resolve
09:23sdegutisI was afraid of that.
09:23sdegutisYou mean ns-resolve right?
09:23TEttinger,(let [muta (java.util.HashMap.)] (.put muta "a" 1) (.put muta "b" 2) (.put muta "c" 3) muta)
09:23OlajydTEttinger, meaning its lazily evaluated too
09:24clojurebot{"b" 2, "c" 3, "a" 1}
09:24justin_smithsdegutis: eh, resolve, ns-resolve they are just two syntaxes for the same shit
09:24OlajydTEttinger, you still remmeber the problem right?
09:24TEttingervaguely
09:25TEttingerI remember I used reductions but I don't remember the JavaRDD part
09:25sdegutisjustin_smith: resolve takes an implicit *ns* which in this case won't let me specify the foo/ part
09:26justin_smith,(resolve 'clojure.string/join)
09:26clojurebot#'clojure.string/join
09:26sdegutisOoooh.
09:26sdegutisCool.
09:26TEttingeris it this class, Olajyd? https://spark.apache.org/docs/latest/api/java/org/apache/spark/api/java/JavaRDD.html
09:26sdegutisI was doing ##(ns-resolve 'clojure.string 'join)
09:26lazybotjava.lang.SecurityException: You tripped the alarm! ns-resolve is bad!
09:26OlajydTEttinger, a function to fill in an empty column from the last non-empty value
09:26sdegutis,(ns-resolve 'clojure.string 'join)
09:26clojurebot#'clojure.string/join
09:26TEttingerright!
09:26OlajydTEttinger, sure it is ::)
09:27sdegutisCan you make your own deref-able by implementing some protocol (via proxy)?
09:27justin_smith,clojure.lang.IDeref
09:27clojurebotclojure.lang.IDeref
09:28sdegutisAh yep clojure.lang.IDeref just found it in core.clj
09:30sdegutis,@(proxy [clojure.lang.IDeref] [] (deref [] 23))
09:30clojurebot23
09:30sdegutisyay
09:30sdegutisIs there another way of creating a defer-able in Clojure?
09:31justin_smithpromises and delays implement IDeref
09:32sdegutisI meant a custom one.
09:35TEttingerOlajyd: hm, I'm not sure how to work this RDD solution. http://stackoverflow.com/a/26060065
09:35TEttingerit
09:36TEttingerit's mentioned that RDDs are shuffled when they're used, there likely isn't a reliable ordering?
09:40sdegutisI've started considering that maybe loading namespaces should be a service that can be started/stopped via stuart sierra's Component thing.
09:41clgvsdegutis: there is reify as well
09:42sdegutiswait a second!!
09:43sdegutisIsn't there a way to set an individual namespace to be compiled ahead of time?
09:43clgvadereth: :aot in project.clj
09:43clgvsdegutis: ^^
09:44sdegutisahh
09:44sdegutisThanks, I'll read up on what the effects of that are.
09:57TEttinger$mail Olajyd consider using a Clojure binding to Spark, this one seems to be able to go back and forth from seq to RDD https://github.com/yieldbot/flambo#resilient-distributed-datasets-rdds
09:57lazybotMessage saved.
09:58blacbirdAnyone here have an idea why I can connect to a database using clojure.java.jdbc but not Korma? If it matters, it is an app running on elastic beanstalk worker tier (tomcat). The error messages are unhelpful to say the least, but from what I gather korma is having problems establishing a connection. It looks like it also uses jdbc under the hood, but maybe the pooling library is causing problems?
09:59sdegutisSorry I use Datomic.
10:00TEttingerhey Olajyd, $mail
10:00ddellacostablacbird: it's very easy to use c.j.j without Korma (arguably easier)
10:01ddellacostablacbird: what exactly are you trying to do? Just try a simple select or something if you are simply trying to diagnose the connection, I suppose
10:01blacbirdddellacosta: if i had to do it again, i'd use that or honeysql. yup, just a simple select trying to figure out what is going wrong
10:02ddellacostablacbird: honeysql + c.j.j is a much better choice in my opinion. :-)
10:02blacbirdddellacosta: really my questions is how in the world do i debug this. "it works fine witha local database" but we are moving it to aws and all of a sudden korma won't work
10:02ddellacostablacbird: can you try https://clojure.github.io/java.jdbc/#clojure.java.jdbc/get-connection for example?
10:02ddellacostablacbird: seems like a decent place to start
10:03blacbirdddellacosta: ya a select with c.j.j works fine. i have a test function that first does it with c.j.j then korma using the same env variables, cjj works fine
10:04ddellacostablacbird: er, hrm, can you put the korma exception in a gist or something and paste the link in?
10:05ddellacostablacbird: for what it's worth we were using korma and the problems with pooling were actually what made us drop it. :-/
10:07ddellacosta(context: https://github.com/korma/Korma/issues/64)
10:07blacbirdddellacosta: https://gist.github.com/anonymous/41983d26742740b7fe16
10:08blacbirdddellacosta: ya i don't think i would choose it again
10:08ddellacostayikes I may not be much help to you on thi sone
10:09ddellacosta*this one
10:09blacbirdddellacosta: haha no problem
10:09ddellacostablacbird: but, so, plain old c.j.j connects just fine huh?
10:10blacbirdddellacosta: yup
10:10ddellacostawonder if there's a way to toggle the connection pool off to test
10:10ddellacosta(in Korma I mean)
10:11blacbirdddellacosta: ya i thought i could pass {: maximum-pool-size 1, etc} to defdb but doesn't seem to be having an effect/changing anything
10:12ddellacostablacbird: I think that's because korma creates a connection pool by default, regardless of the size
10:12ddellacostablacbird: oh, looks like there's a :make-pool? setting?
10:12ddellacostahttps://github.com/korma/Korma/blob/996f056ec73d27d80d76a4acffcac2970d23cebe/src/korma/db.clj#L135-L148
10:14blacbirdddellacosta: i'll try setting it to false
10:15ddellacostablacbird: anyways, yeah, at this point I'd just be digging into the korma source to try to debug...not sure I can offer much more, sorry. :-/
10:15ddellacostablacbird: but I wish you good luck! And suggest you move to honeysql ASAP. :-)
10:15blacbirdddellacosta: ok, thanks a lot for the help anyway, and I might just do that!
10:15ddellacostablacbird: any time!
10:17negaduckhi! Is it ok to create them on events in cljs? Are they disposable?
10:18negaduckwhat if I use them instead of promises to read from them only once?
10:18ddellacostanegaduck: what is "them?"
10:19negaduckddellacosta: I'm sorry, core.async/chan
10:20ddellacostanegaduck: ah...I would caution against creating go blocks inside event handlers
10:20ddellacostanegaduck: but of course it really depends on what you're doing and how--I'd have to see a specific example or try to understand your use-case
10:20ddellacostanegaduck: simply creating channels is not a big deal I suppose, but again depends on what you're doing=
10:20ddellacostadoing*
10:21negaduckddellacosta: something like this: http://dimagog.github.io/blog/clojure/clojurescript/2013/07/12/making-http-requests-from-clojurescript-with-core.async/
10:22negaduckcreating a go block in ajax handler
10:24ddellacostanegaduck: that seems fine to me because it's not looping, it just goes away
10:24ddellacostanegaduck: although I struggle to see why one would do it this way, but I suppose it's just a toy example
10:24ddellacostaI'd be inclined simply to log right inside the callback...haha
10:25ddellacostabut anyways, yeah, seems fine to me, albeit pointless here
10:27negaduckddellacosta: I'm going to make sequential gets like (<! (-> (ajax.get "http://whatever) (then "rel-something) (etc) ...))
10:27ddellacostaand as one of the commenters mentions I would simply use put! in the callback vs. creating a go block and using >!
10:28negaduckddellacosta: basically following rest rels
10:28ddellacostanegaduck: I'm not really seeing it from the kinda-pseudo-code you just pasted, I'd need to see a more full example. I'm not sure what you mean by "sequential gets."
10:31negaduckddellacosta: get a rest entrypoint, get links from there and follow them like in slides 13 and 14 here: https://speakerdeck.com/basti1302/consuming-hypermedia-apis-with-traverson?slide=13
10:32negaduckddellacosta: this is built using promises, I want to write the same thing with core.async
10:34ddellacostanegaduck: I see. In that case I'd create a single channel that you are listening on in a go block elsewhere, pass that to the callback of whatever AJAX fn is GETing the values from the API
10:34negaduckddellacosta: so the question is: is it ok to use chans to be written and read exactly once to be then thrown away
10:34ddellacostanegaduck: I mean, I suppose you could do that too to get something more imperative
10:35ddellacostanegaduck: exactly as in the article you linked to
10:35ddellacostanegaduck: but my inclination would be to accumulate results in a go block with a single channel
10:36negaduckddellacosta: with a transducer maybe?
10:36ddellacostanegaduck: dunno, there are different ways to do it that are potentially equally valid depending on your app architecture
10:36ddellacostanegaduck: I don't know, depends on what you need the transducer for...haha
10:37ddellacostanegaduck: that is, I don't see where it fits in here particularly
10:37negaduckyes, just a thought
10:40negaduckddellacosta: ok, I'll think about a single channel
10:40negaduckddellacosta: thanks
10:40ddellacostanegaduck: I mean, that's how I'd do it but I think something like a let block inside a go block emulating the style in the article you linked to above is reasonable too
10:41ddellacostanegaduck: but in any case, good luck!
11:00negaduckddellacosta: is it necessary to close a channel? Is it ok to throw away an unclosed one?
11:01ddellacostanegaduck: my understanding is that you want to close channels if you have set up go blocks listening to them on a loop
11:02negaduckddellacosta: got it
11:03ddellacostanegaduck: (that is, assuming you no longer need them)
11:04negaduckddellacosta: ok. Is put! like (go (<! ...))? Can't figure out the difference
11:05justin_smithnegaduck: surely you mean (go (>! ...))
11:05ddellacostaput! doesn't block
11:05justin_smithddellacosta: (go ...) doesn't either
11:06ddellacostajustin_smith: sorry, I should clarify--
11:07ddellacostanegaduck: >! needs to be called inside a go block.
11:07justin_smithiirc put! does not return a channel, but does take an optional callback
11:07justin_smithddellacosta: what he asked was why you would use put! instead of making a go block and using >!, that is how I read it at least
11:07negaduckjustin_smith: ddellacosta: is go block for sequential >! and <!, and put! is like a go block with a single operation?
11:07ddellacostajustin_smith: ah, missed that I guess
11:07justin_smithnegaduck: not really
11:08justin_smithnegaduck: unlike a go block, put! does not return a channel
11:08justin_smithnegaduck: instead you can provide a callback that will be called when the value is consumed
11:09justin_smithor you can "fire and forget" of course
11:10justin_smithnegaduck: it's true that go blocks are more flexible and can be used for a series of reads and writes of channels
11:10negaduckjustin_smith: leaving the return value, are those two same?
11:10justin_smithif you ignore return values and don't use a callback they will behave the same, yes. But put! is more concise than making a go block of course syntax wise
11:10sdegutis,(->> (range) (run! prn))
11:10ddellacostanegaduck: think of put! kind of like a shorthand for the common use case of putting something in a channel without necessarily caring about what happens past that (other than the option for passing in a callback)
11:10clojurebot#<OutOfMemoryError java.lang.OutOfMemoryError: Java heap space>
11:11sdegutis,(->> (range 100) (run! prn))
11:11clojurebot0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n65\n66\n67\n68\n69\n70\n71\n72\n73\n74\n75\n76\n77\n78\n79\n80\n81\n82\n83\n84\n85\n86\n87\n88\n89\n90\n91\n92\n93\n94\n95\n96\n97\n98\n99\n
11:11sdegutisneat
11:11ddellacostanegaduck: without needing to set up a go block, especially if you don't need to return a channel from that
11:11negaduckI mean they do same thing, right?
11:11justin_smithright, except for the differences already described
11:12negaduckddellacosta: justin_smith: many thanks
11:38sdegutisWhat is run! meant for?
11:39sdegutisI suppose something like this would make sense: (run! handle-request (incoming-requests))
11:39pjstadig,(doc run!)
11:40clojurebot"([proc coll]); Runs the supplied procedure (via reduce), for purposes of side effects, on successive items in the collection. Returns nil"
11:40sdegutisWhere (incoming-requests) is just a seq or "process" that generates requests as they come in and just waits in between.
11:40pjstadigbasically sounds like (dorun (map ...))
11:40sdegutisOr (doseq [x coll] (f x))
11:41sdegutisThat's how I've always done it, dunno how run! is better.
11:41pjstadigit's not necessarily better, it is like (dorun (map ...))
11:41pjstadigwhich you may want to use if you have some function to apply
11:41pjstadigas opposed to writing a body of a doseq
11:45justin_smithpjstadig: it is better because unlike map it does not create a lazy seq you won't be using
11:47pjstadigjustin_smith: my understanding is that sdegutis was asking why run! is "better" than doseq
11:47sdegutis,(let [proc prn, coll [1 2 3]] (do (reduce #(proc %2) nil coll) nil))
11:47clojurebot1\n2\n3\n
11:47justin_smithpjstadig: not making things you don't use is better
11:47justin_smithoh, doseq
11:47sdegutisjustin_smith: I was wondering why there's run! when it's basically the same as doseq.
11:47justin_smithnever mind
11:47Bronsadoseq still consumes a seq
11:47justin_smithsyntax
11:47justin_smithBronsa: wouldn't run! also consume one?
11:47Bronsanot necessarily
11:48justin_smithahh...
11:48Bronsait uses reduce internally
11:48Bronsaso it can exploit the new reducible colls
11:48pjstadigrun! being a function also means that you can partial it, pass it as a value, return it as a value, etc.
11:48pjstadigit's just a different tool to be used in appropriate circumstances
11:49sdegutisrun! is literally (do (reduce #(f %2) coll) nil)
11:50sdegutisSo I'm guessing it's meant for this kind of thing:
11:50sdegutis(run! handle-request (incoming-requests))
11:51clgvsdegutis: reducers equivalent of `dorun` is my guess
11:52clgverm actually more like doseq but a function instead of a macro ;)
11:53Bronsa,(run! println (reify clojure.lang.IReduceInit (reduce [_ f _] (loop [a 10] (when (pos? a) (f _ a) (recur (dec a)))))))
11:53clojurebot10\n9\n8\n7\n6\n5\n4\n3\n2\n1\n
11:53Bronsajustin_smith: ^ a stupid example of run! w/o any coll realization
11:54sdegutisI once heard that the primary use of macros in traditional Lisps is to not have to write (lambda ...) so much.
11:54sdegutisWhat's the primary use of macros in Clojure?
11:54sdegutisBronsa: thats neat btw
11:57justin_smithBronsa: thanks
12:17OlajydCan I get a function such that (isAbbreviation("capture the flag","cptr”)) returns "aue the flag”?
12:18gilliardYou mean to remove all the instances of the 2nd string from the first string?
12:19Olajydyes
12:19Olajydgilliard sure
12:21Olajydgilliard,function call: (isAbbreviation "capture the flag" "cptr” ) ;=>"aue the flag”
12:21Bronsa,(reduce (fn [s el] (.replaceFirst s (str el) "")) "capture the flag" "cptr")
12:21clojurebot"aue the flag"
12:21gilliard,(apply str (filter (comp not (into #{} "cptr")) "capture the flag"))
12:21clojurebot"aue he flag"
12:22Bronsagilliard: (filter (comp not f) x) is (remove f x)
12:23Bronsahe doesn't want all the elements removed though, just the first instance IIUC
12:23gilliard,(apply str (remove (into #{} "cptr") "capture the flag"))
12:23clojurebot"aue he flag"
12:23gilliardNice thanks Bronsa.
12:24gilliardOlajyd: you have choices :)
12:24Olajydhahah
12:24Olajydanother tricky use case
12:25Bronsagilliard: he wants "aue the flag", your solutions return "aue he flag"
12:25Olajyd isAbbreviation("capture the flag","hello") returns null :)
12:26Olajydgilliard, isAbbreviation(String originalString,String abbreviation) If abbreviation is not valid, it returns null Otherwise, it returns a string of the characters that have been removed from originalString to make abbreviation
12:27BronsaOlajyd: (defn abbr [original abbreviation] (reduce (fn [s el] (if (not (.contains s (str el))) (reduced nil) (.replaceFirst s (str el) ""))) original abbreviation))
12:55snowellIs if-some just if-let with multiple bindings in its test?
12:55snowellI'm trying to grok what if-some does that if or if-let doesn't
13:00ToxicFrogsnowell: if-some is if-let, but it takes the else branch only if the binding value is nil
13:00ToxicFrog,(if-some [x false] :t :f)
13:00clojurebot:t
13:00ToxicFrog,(if-let [x false] :t :f)
13:00clojurebot:f
13:00ToxicFrogUse it when you want any non-nil value, and "any" can include false.
13:00snowellAh, that makes sense!
13:01snowellI thought it had something to do with (some) at first, and was confused :)
13:01snowell(inc ToxicFrog) ; Thanks!
13:01lazybot⇒ 5
13:02snowellOK, I see where it DOES have to do with (some). I speak before thinking.
13:04ToxicFrogsnowell: Also relevant, some->, which is -> but aborts at the first nil.
13:05pjstadigi brushed off and updated chouser's code
13:05pjstadig2008: http://n01se.net/paste/fZQ?pretty=no
13:05pjstadig2015: http://i.imgur.com/m6dSDll.png
13:06zerokarmaleftthat's sweet
13:09clgvpjstadig: hehe
13:10pjstadigi think it actually looks more of a contrast than it should. I think most of the Expr classes near the top, and Reader classes near the bottom existed in 2008. It's mostly the stuff in the middle that has changed
13:11pjstadigit doesn't include any of the classes that are generate from clojure code (like the gvec classes)
13:11amalloysnowell: 1.6 added a few "some"-flavored functions, which act like already-existing functions but only count nil as falsey, not even false
13:12amalloythat is, the only value that they consider to be falsey is nil
13:20chouserpjstadig: Thanks for doing that!
13:20chouserThe older version was manually adjusted to reduce diagram size and complexity.
13:21pjstadigah ok
13:22pjstadigchouser: it was interesting see the changes necessary to modernize the code
13:22pjstadigi have some old clojure lying around, but i don't think it's quite from that era
13:22chouserpjstadig: I'm sure. I've actually taken a crack or two at it before, but got bogged down, so thanks for finishing it up.
13:23pjstadigchouser: i can post it in a gist
13:23chouserok. or a pull request if you want. ... it is a git repo, right?
13:24pjstadigchouser: maybe? i grabbed it from here https://groups.google.com/forum/#!topic/clojure/H42kG6_aKms
13:26pjstadigchouser: https://gist.github.com/pjstadig/bade0e5eb130c255669f
13:28pjstadigoh yeah, this code is much better :) https://github.com/Chouser/clojure-classes
13:42noncomdid anyone use gorilla repl?
13:45justin_smithsemi-offtopic - is there git wizardry that would help automate a merge in a situation where I have moved some code into a different git repo?
13:46Olajyd,(defn abbr [original abbreviation] (reduce (fn [s el] (if (not (.contains s (str el))) (reduced nil) (.replaceFirst s (str el) ""))) original abbreviation))
13:46clojurebot#'sandbox/abbr
13:46sed-gnu-utils,abbr
13:46clojurebot#object[sandbox$abbr 0x7b887bd1 "sandbox$abbr@7b887bd1"]
13:46sed-gnu-utils,(partial abbr)
13:46clojurebot#object[sandbox$abbr 0x7b887bd1 "sandbox$abbr@7b887bd1"]
13:46Olajyd,(abbr ”capture the flag" "hello”)
13:46clojurebot#error {\n :cause "Unable to resolve symbol: ”capture in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: ”capture in this context, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6704]}\n {:type java.lang.RuntimeException\n :message "Unable to resolve symbol: ”captur...
13:46sed-gnu-utils,(= abbr abbr)
13:46clojurebottrue
13:47sed-gnu-utils,(= (partial abbr) abbr)
13:47clojurebottrue
13:47justin_smithOlajyd: your client is sending smart quotes
13:47justin_smithOlajyd: which are not valid clojure string delimiters
13:47sed-gnu-utils,[,abbr, (partial, abbr, "foo"),],
13:47clojurebot[#object[sandbox$abbr 0x7b887bd1 "sandbox$abbr@7b887bd1"] #object[clojure.core$partial$fn__4515 0x28fb8a64 "clojure.core$partial$fn__4515@28fb8a64"]]
13:48justin_smith,(abbr "capture the flag" "hello")
13:48clojurebotnil
13:48justin_smith,(abbr "capture the flag" "cptr")
13:48clojurebot"aue the flag"
13:49Olajydaite, thanks :)
13:54breadmonsterHi everyone.
13:54R0B_RODhi breadmonster
13:55breadmonsterI was thinking of diversifying languages, and someone recommended Clojure to me.
13:55breadmonsterSo just wondering if any of you have tips on how to get started.
13:55sed-gnu-utilsWhat's an unthinkable alternative for removing an element from a seq than (->> seq (remove (partial = el)))
13:55breadmonsterAlso, how does clojure compare with Haskell? It's the only other programming language I know.
13:56justin_smithsed-gnu-utils: hiring Peruvian peasants to do it by hand
13:56breadmonsterjustin_smith: lol
13:56justin_smithbreadmonster: he asked for "unthinkable"
13:56wasamasabreadmonster: I'd say it's more practical weren't it for haskell fanboys punching me for such accusations
13:56breadmonsterwasamasa: Doesn't like the JVM stop you from using tail recursion?
13:57wasamasabreadmonster: see, it's started
13:57breadmonsterlol no that was an honest question.
13:57breadmonsterThat said, Haskell has laziness as an issue.
13:58sed-gnu-utilsjustin_smith: technically correct
14:00sed-gnu-utilsbreadmonster: Clojure is neat, although I mostly like it for the native API to Datomic
14:00wasamasabreadmonster: tail recursion is how you do loops in clojure, duh
14:00sed-gnu-utilsjustin_smith: I'm running out of words for "good" in my thesaurus
14:00wasamasabreadmonster: you'll even get helpful compile errors if you try using recur in a non-tail position
14:00breadmonsterInteresting.
14:01breadmonsterCool stuff.
14:01sed-gnu-utilsjustin_smith: in this case, good -> great -> fantastic -> unthinkable, via Oxford American Writer's Thesaurus
14:01sed-gnu-utilswasamasa: scheme is inherently inferior to Clojure
14:01sed-gnu-utilsI WILL FIGHT YOU ABOUT THIS
14:01wasamasased-gnu-utils: fuck off
14:02wasamasased-gnu-utils: I've seen enough trolling by you on #emacs to know where that will lead
14:02sed-gnu-utilswasamasa: relax it was a joke
14:02sed-gnu-utilswasamasa: #clojure is a laid back and peaceful channel, enjoy it :)
14:05sed-gnu-utilsIs there an alternative to map like (something f coll) that just runs (f el) and returns coll?
14:05gfrederickssed-gnu-utils: run! will do that but returns nil
14:05justin_smith(do (f el) coll)
14:05gfredericks(doto coll (->> (run! f)))
14:05sed-gnu-utilsI'm hoping for something I can put inside of a ->>
14:06gfredericksyou'd need a <- to get it back to single arrow position
14:07amalloysed-gnu-utils: please stop changing your nick so that people like wasamasa who probably have sdegutis in their /ignore list don't have to keep adding to it
14:07sed-gnu-utilsamalloy: haha s/wasamasa/me/ don't try to hide it dude
14:08sdegutisHappy?
14:08amalloythanks
14:08amalloyatm you are in fact not on my /ignore list; i phase you in and out in case you stop doing stuff like threatening to fight people about scheme vs clojure
14:11sdegutisFor the record, I haven't trolled in over a year.
14:11justin_smithsdegutis: I'm ignoring you for that, on principle, sorry
14:11sdegutisAnd it's pretty clear that my response to wasamasa was a good-hearted joke.
14:11sdegutis(That's not the right expression but I can't remember what it's supposed to be.)
14:11wasamasawriting is hard
14:11blkcatfacetious?
14:12sdegutisNo like light-hearted and friendly or something.
14:13sdegutisI work remotely, so I come here for socialization, to share brain teasers, and to help the occasional newb. The brain teasers are the most fun part tbh.
14:21winkRough times in #clojure. If this keeps escalating at this pace... someone might write an angry tweet. /o\
14:22sdegutis:D
14:23wasamasaphew, I don't use twitter
14:23sdegutisI suppose (map #(doto % (f))) works
14:23wasamasaok, that's not quite right, I've got a novelty account I intended to use for a markov chain bot, but I dropped the project midways
14:24sdegutisIn Haskell?
14:24wasamasaclojure of course
14:24sdegutis:D
14:24sdegutissrc?
14:24wasamasawhy else would I tell this channel
14:24sdegutiscuz it's relevant to the current conversation
14:24wasamasawell, it's mostly a copy of http://howistart.org/posts/clojure/1/
14:25sdegutisnice
14:25wasamasaexcept that my sources weren't nearly as convenient for the suggested tweaks
14:34sdegutisfwiw, clojure.core/name isn't quite just a way to turn a symbol/keyword into a string... it's more like basename but for the /
14:35gfrederickssdegutis: http://hacklog.gfredericks.com/2013/08/10/clojure-overloads-the-term-namespace.html
14:41wasamasaheh, hacklog
14:45sdegutisgfredericks: nice
14:45sdegutis,((juxt namespace name) :foo.bar/quux)
14:45clojurebot["foo.bar" "quux"]
14:45sdegutis,((juxt namespace name) 'foo.bar/quux)
14:45clojurebot["foo.bar" "quux"]
14:45sdegutis,((juxt namespace name) "foo.bar/quux")
14:45clojurebot#error {\n :cause "java.lang.String cannot be cast to clojure.lang.Named"\n :via\n [{:type java.lang.ClassCastException\n :message "java.lang.String cannot be cast to clojure.lang.Named"\n :at [clojure.core$namespace invokeStatic "core.clj" 1529]}]\n :trace\n [[clojure.core$namespace invokeStatic "core.clj" 1529]\n [clojure.core$namespace invoke "core.clj" -1]\n [clojure.core$juxt$fn__4498 i...
14:45sdegutisha
14:46sdegutisIs there another way to write a literal symbol besides (quote foo)?
14:47gfredericksyou're wondering about a syntax that would allow whitespace or something like that?
14:47sdegutisNo, I just mean it feels a bit weird to use (quote), like it's a leaky abstraction from the compiler, an implementation detail we really shouldn't know about.
14:47sdegutisUnless of course the symbol is being used at compile-time or macro-expansion-time, in which case it makes perfect sense.
14:48gfredericksyou can call the reader to get a symbol
14:48sdegutisBut you still need to give it a string.
14:48gfredericksyep
14:48sdegutis,(symbol "foo")
14:48clojurebotfoo
14:48sdegutisJust like that.
14:48gfredericksno I don't think there's anything along the lines you're asking about
14:48sdegutisOkay.
14:48sdegutisThanks gfredericks.
14:48gfredericksnp
14:51sdegutisIs (apply concat) the best way to "flatten" a seq of seqs one-level deep?
14:51sdegutisOH! (flatten) exists!
14:51sdegutisI hadn't thought of that until I phrased my question, haha.
14:51gfredericks~flatten
14:51clojurebotflatten is rarely the right answer. Suppose you need to use a list as your "base type", for example. Usually you only want to flatten a single level, and in that case you're better off with concat. Or, better still, use mapcat to produce a sequence that's shaped right to begin with.
14:51gfrederickssdegutis: flatten is recursive, so apply concat is actually better
14:51sdegutisTouche :D
14:52sdegutisIn this case though I think I can actually use mapcat, ha!
14:52gfredericksfor is also good at this stuff
14:53sdegutisTrue, I use for a lot. Except inside ->>
14:54sdegutisDo yall often use `lein check` and put type hints everywhere it suggests?
14:55pjstadigif i want to avoid reflection, yes
14:56gfredericksor better you can set *warn-on-reflection* to true in the project.clj
14:56pjstadigbut you can also tell leiningen to warn on reflection every time it compiles
14:56gfrederickswhich I almost never do
14:56gfredericksthat can also be noisy since it warns about libraries as well
14:56sdegutisgfredericks: I like that!
14:57sdegutisBtw this is how I'm building my schema dynamically: https://gist.github.com/sdegutis/e5ee9f088d258186d6c0
14:57sdegutisWhen I call (build-schema), it looks through all my code for (def ^:schema some-attributes [...]) and uses them.
14:58Olajydcan someone put me through `iterator-seq` in clojure? :|
14:59sdegutisI plan to do a similar thing with routes, where I would define one like (defn ^{:method :POST :route "/foo/bar"} my-route-handler [req] ...)
14:59sdegutisOlajyd: did you read this?
14:59gfrederickssdegutis: I just started using fnhouse, which is similar, and I love it
14:59sdegutis(doc iterator-seq)
14:59clojurebot"([iter]); Returns a seq on a java.util.Iterator. Note that most collections providing iterators implement Iterable and thus support seq directly. Seqs cache values, thus iterator-seq should not be used on any iterator that repeatedly returns the same mutable object."
14:59sdegutisgfredericks: never heard of it, will look it up, thanks
14:59sdegutisgfredericks: I had this idea a year ago but never had time to merge my branch with that (and fix the bugs) until now
15:00Olajydsdegutis, a simpler explanation will do :)
15:00gfrederickssdegutis: fnhouse is especially good if you like prismatic/schema, which I do
15:01sdegutisOlajyd: Most likely you never need it, what makes you wonder if you need it?
15:01sdegutisgfredericks: I like it in theory but have never tried it.
15:01sdegutisgfredericks: oh, by the same people, cool
15:02gfrederickssdegutis: I think prismatic/schema starts to get really useful when you use coercers
15:02sdegutisI'm excited about alternatives to Compojure gaining popularity, I can't wait for Compojure's mindshare to die down.
15:02sdegutiscoercers?
15:03pjstadiggfredericks: inc
15:03gfrederickswhich also works well with fnhouse; so e.g. I can say that a particular query param or uri-param is an integer, and it will get parsed for me
15:03Olajydsedgutis, ok somebody used it `(iterator-seq it)` just wondering why though :)
15:03pjstadigespecially if you're stuck with anemic data formats like JSON
15:04sdegutisamalloy_: that was the real reason I did /nick btw
15:04sed-gnu-utilsOlajyd: got a link?
15:04sed-gnu-utilsgfredericks: oh man that sounds awesome and super convenient
15:05sed-gnu-utilsgfredericks: as long as the declaration is succinct, I'm sold
15:05gfredericksit's not too bad
15:06sed-gnu-utilsBtw I like the idea of no global state, but to some extent vars and namespaces already are unavoidable global state.
15:06gfredericksnot if they're constant
15:07gfredericksthey're definitely potentially state, which is what code reloading is all about; but that's different from using them for your app's global state
15:07Olajydsed-gnu-utils: was going through http://stackoverflow.com/questions/32207234/convert-from-clojure-lang-lazyseq-to-type-org-apache-spark-api-java-javardd/32211936#32211936
15:07sed-gnu-utilsThat's part of what attracted me to Haskell, with its unified concept of non-stateful state and no distinction between compile time and runtime.
15:07sed-gnu-utilsgfredericks: touche
15:11xemdetiawtf
15:11sed-gnu-utilsxemdetia: ?
15:25sed-gnu-utilsWhoa. Turns out my technique is super slow.
15:27sed-gnu-utilsOrdinarily (build-schema) is only called once at start-up, but I forgot it runs at the beginning of each 700 of our tests.
15:28justin_smithoops forgot to ignore the other nicks
15:30snowellafaik my client resets the /ignore list on a restart :/
15:31amalloymine does too, and it's annoying, but also reminds me to give people a chance to change
15:31snowellYou're far more optimistic than I :D
15:34sed-gnu-utils(defn ^:memoize foo [...] ...) should be a shortcut (def foo (memoize (fn [...] ...)))
15:35sed-gnu-utilsjustin_smith: lol
15:36Bronsased-gnu-utils: stop changing nicks.
15:36sed-gnu-utilsBronsa: this nick is legitimately easier for non-regulars to mentally parse and respond to correctly than sdegutis
15:36sed-gnu-utilstime and time again they type "sdegutils" or "sedutis" etc
15:37sed-gnu-utilsProbably 80% of them.
15:49sed-gnu-utils,(concat [1] nil [2 3])
15:49clojurebot(1 2 3)
15:49sed-gnu-utilscool
16:24Olajydcan somebody explain .swap with use cases? :|
16:25sed-gnu-utilsOlajyd: you mean swap!?
16:25sed-gnu-utilsOlajyd: have you read (doc swap!)
16:25sed-gnu-utils(doc swap!)
16:25clojurebot"([atom f] [atom f x] [atom f x y] [atom f x y & ...]); Atomically swaps the value of atom to be: (apply f current-value-of-atom args). Note that f may be called multiple times, and thus should be free of side effects. Returns the value that was swapped in."
16:26kavkazIs there a built in function for finding the first item in a sequence which returns logical true for a given function?
16:26Olajydsed-gnu-utils: he used `#(.swap %)`
16:26sdegutisIt's the same as JavaScript's = operator.
16:26sdegutisOlajyd: oh then it's just a Java method.
16:26kavkazI thought it'd be more efficient than (first (filter f seq))
16:26sdegutiskavkaz: that's the solution I keep going back to, and it's pretty efficient
16:26oddcullyOlajyd: it calls the method .swap on the object. what is the object there?
16:26kavkazsdegutis: Perhaps because of lazy sequences?
16:26sdegutiskavkaz: with lazy seqs it stops when you find it and doesn't consume the rest
16:26sdegutisyeah
16:27kavkazI'm not too sure
16:27kavkazoh i see
16:27kavkazThank you sdegutis
16:27sdegutisoddcully: it's % of course
16:27sdegutis;)
16:27sdegutiskavkaz: btw I usually put them inside ->> like (->> coll (filter f) (first))
16:28sdegutisMakes me feel like I'm using JavaScript or something.
16:28Olajydoddcully, I’m guessing its an anonymous function that takes in input like [[“foo” “bar”] 1]
16:28kavkazsdegutis: lol, the threading operators are something that I am yet to get used to.
16:28kavkazMakes it more confusing for me personally but I could see why some people prefer them
16:33oddcullyOlajyd: it is some java object and the method .swap is called on that object. if you want to know, what gets passed in there, you have to debug at least the (type %).
16:34oddcullyOlajyd: if you can not give any hint on the object used here, you would have to guess from the params, that this might simply swap two elements
16:38Olajydoddcully, well I saw this on stackoverflow: `(def rdd-idx (f/map-to-pair (.zipWithIndex rdd) #(.swap %)))` dont know if that helps :|
16:41oddcullyi'd consult the spark/flambo man pages
16:43OlajydI understand what the .zipWithIndex and map-to-pair will do though, I just dont understand the .swap :(
16:45Olajydthanks oddcullly
17:55Stalkr_Hi, I have a course about programming language concepts. Virtual machines, byte code, abstract syntax trees etc. We use F# for this, how well does Clojure work as an interpreter/compiler? How does it compare to F# or Haskell? I hope my question makes sense, this is very new stuff for me
17:56Stalkr_I guess it comes down to using Clojure as a lexer/parser?
17:57justin_smithStalkr_: clojure does not have an interpreter, and does not use the javac compiler, it compiles to jvm bytecode
17:57justin_smithStalkr_: lisps do compilation a little differently
17:57Stalkr_justin_smith: Sorry, I worded it wrong. I meant to use Clojure as a lexer, for my own language
17:57justin_smithas one, or as a language in which to write one?
17:57hiredmangenerally, if I am doing that sort of thing in clojure, the language I am implementing is also a lisp, so I often just use clojure's reader
17:58Stalkr_justin_smith: Not sure I follow. Say I want to lex/parse C code, is Clojure suitable for that?
17:58hiredmanclojure doesn't so much have a lexer or a parser, it has a reader, which you basically interact with like a some kind of json codec (if you used one of those in another lnaguage)
17:59hiredmanthere are some really neat clojure parsing libraries like instaparse which you can use for building parsers for whatever
17:59amalloyStalkr_: you can of course write a lexer and a parser yourself in clojure
17:59Stalkr_I haven't done anything like this, it's a course I am taking and interested in trying than something else than F#
17:59Stalkr_trying something*
17:59amalloyusing some library like hiredman says. note though that if you actually want to parse a .c file in an entirely standards-compliant way that is a lot of work
17:59hiredmanit is true
18:00amalloychoosing a less warty language to parse would be a good idea, unless you specifically need to parse c
18:00Stalkr_C was just an example, could be whatever. It would probably be my own little toy language
18:01hiredmanhttps://github.com/hiredman/prubasic uses instaparse to parse a language not unlike basic
18:01Stalkr_so basically any language can work as a lexer, FP is just great for interpreters/compilers? I just hear Haskell often when talking about compilers
18:01amalloyStalkr_: clojure is a fine language for that, and haskell also has some great parsing libraries. i don't know about f#
18:01hiredmanhttps://github.com/hiredman/prubasic/blob/master/src/prubasic/parser.clj instaparse takes a bnf like syntax
18:02hiredmanStalkr_: compilers are generally pipelines of transformations over graphs
18:02hiredmanfunctional programming does pretty well at that
18:03Stalkr_I see, I'll have to play around with Clojure when I understand more. First lecture tomorrow
18:06sdegutishiredman: how has been your experience using instaparse?
19:19seangroveOk, deep into personally unexplored territory
19:19seangroveI've gone to https://github.com/google/closure-compiler, cloned it, run `ant jar`, and now I have build/compiler.jar
19:19seangroveWhat's the process for getting lein/clojurescript to use that instead of whatever it's currently pulling in?
19:37ebzzryWhere/how is #_ defined?
19:48amalloyebzzry: in the reader, in LispReader.java
19:51ebzzryamalloy: aside from line 105, what else should I look at?
19:52amalloyebzzry: note that 105 refers to a DispatchReader for #, and then there's a dispatchMacros with a DiscardReader for _
19:53ebzzryamalloy: thanks!
20:57rasmustowhoops, I was relying on (set [1 2 3]) coming out ordered
22:17sdegutishaha
22:17sdegutisrasmusto: I think there is some kind of ordered set tho iirc
22:17sdegutis,(distinct [1 2 2 3])
22:17clojurebot(1 2 3)
22:17sdegutisyeah that works
22:17justin_smith,#{3 21}
22:17clojurebot#{21 3}
22:17justin_smitherr
22:18justin_smith,#{3 2 1}
22:18clojurebot#{1 3 2}
22:21bacon1989does that mean sets are stored as binary trees, or some variant?
22:25mangebacon1989: the default set is a hash-set, which is one of these https://en.wikipedia.org/wiki/Hash_array_mapped_trie
22:27bacon1989oh neat
22:27bacon1989so the characteristics of the set we're seeing is a result of the trie part?
22:27bacon1989I just assumed a binary tree, since it's evaluating and storing the values in the order 3 2 1
22:27bacon1989but results in 1 3 2
22:28bacon1989so I figured it looks like...
22:28bacon1989/\
22:28bacon19892 3
22:28bacon1989then
22:28mangeI think it's more the hashing that's causing it.
22:28mange,(map hash [1 2 3])
22:28clojurebot(1392991556 -971005196 -1556392013)
22:29bacon1989hmm
22:29mangeIf you want a binary tree, though, you can use sorted-set, which is a persistent red-black tree.
22:30mange,(sorted-set 3 2 1)
22:30clojurebot#{1 2 3}
22:31bacon1989ah ok
22:33seangroveBronsa: Trying to use t.a.js, and get an error "resolve-var does not exist" with the latest version
22:36seangroveBronsa: Seems to happen on `(require '[clojure.tools.analyzer.js :as a])`
22:37amalloyseangrove: gist a stacktrace: it'll provide information about what file contains the offending reference, at least
22:40amalloymy bet is on a version conflict between two libraries you depend on that both depend on tajs
22:40amalloysince tajs hasn't changed in 8 months
22:40seangroveamalloy: Likely, yes
22:41seangrovehttps://gist.github.com/sgrove/d5527266131a1c5135b6
22:42seangroveThis may be a slightly over-ambitious approach for what I'm trying to do actually
22:45amalloyyeah, i think you are just not using the latest version of tajs at all, since the form that is causing the problem in your stacktrace can't behave that way with the code on github
22:45seangroveOk, perhaps backing up would be a good idea
22:46seangroveLet's say I have n-forms, the first is a ns-form, and then *probably* some top-level def forms. A file for the ns already exists, and maybe have code in it.
22:47seangroveI would like to know where I can insert the new forms such that dependencies will be satisfied
22:50mordocaiMy midje tests don't appear to be running. I just upgraded everything (all dependencies) and have been having trouble since. Any ideas? I get this output: https://www.refheap.com/108827 and here is my code: https://github.com/mordocai/mordocai.net
22:50mordocaiI haven't done any clojure for a while so...
22:50mordocaiI'm lost
22:50seangrovee.g. the new forms may reference existing vars in the file, so they need to be placed after those vars
22:51seangroveI guess that actually shouldn't be too bad
22:52andyf_seangrove: You have some new forms you want to add to an existing source file, and you are hoping to use tools.analyzer.* lib to help you determine the earliest point in the file the new form can go such that it won't get an error when compiling the file?
22:52seangroveandyf_: Yeah, exactly
22:53seangroveWell, actually, any suggestions for taking a form and getting the fully qualified name of every vary in it? Probably any var that 1. isn't prefixed with a / and is not in t.a.* env is a ns-local var
22:53seangroveAnd I can just walk down the tree and build up a list of these, then scan the file for the location of the vars
22:53andyf_Would always putting the new form at the end be correct, or can there be forms already in the file that depend upon the new form you are adding?
22:54amalloyseangrove: you think nobody ever uses :refer or :use?
22:54seangroveamalloy: You bastard
22:55seangroveandyf_: If they define new forms while simulataneously redefining existing forms, that gets tricky
22:55seangroveI'm working on adding persistence to this https://www.dropbox.com/s/pvpgprg5kzq8sy4/dato_live_editing_2.mp4?dl=0
22:55amalloyi mean i know i do. (ns foo.blah (:require [clojure.java.jdbc :as jdbc :refer [with-db]])) or whatever, where i refer to the stuff that i think reads better without a ns prefix
22:55mangemordocai: I don't think you can nest your fact assertions, like [url status] => [url 200], inside the form like that. I think you'll have to use something more like (fact [url status] => [url 200]).
22:56mangeI've not used Midje for a long time, though, so I could be remembering that incorrectly.
22:56seangroveMaybe I should just go smalltalk browser and do single-fn defs - feels like a cop-out though
22:56seangroveamalloy: Yeah, it's a good point
22:56seangroveamalloy: I assume t.a.* gives you sufficient info to figure that out though?
22:56amalloyha, amusingly tajs itself makes liberal use of :refer
22:57amalloyseangrove: i assume so, yes, but the point is that whether a thing includes a / or not makes no difference if you are using tajs, because it's already figured that stuff out for you
22:57seangroveamalloy: Yeah, another well-made point
22:57mordocaimange: Hmmm... well it used to work 10 months ago :P. I'll try it with fact.
22:58mordocaiEither that or I never got my tests working before
22:58seangroveamalloy: I guess this is an indication https://github.com/clojure/tools.analyzer.js#outdated that Bronsa already knows, added two weeks ago
22:59mangemordocai: I would be somewhat surprised if your tests used to work. I don't think Midje has ever done that sort of transformation.
23:12mordocaimange: So wrapping those tests with fact didn't work either, same output. I know that code is running because if a put a println right above the facts it works. Also, I know it used to work as the place I got my info from (a blog post, but that blog post seems down) has a github repo here: https://github.com/cjohansen/cjohansen-no that has it the same way. So.... idk. I might just use clojure.test instead and see if I can get it
23:12mordocaiworking.
23:16mordocaiYeah, I don't think midje was working properly. Probably setup wrong. In any case, clojure.test works fine.
23:16mordocaiPushing shortly if you are interested, but it is super simple
23:19mangeOkay, so it seems midje doesn't report its failures into the normal clojure.test metrics stuff, so putting the (fact ...) wrapper around the assertions makes them print their own error output, but the clojure.test stuff still says no tests were run.
23:19justin_smithyeah, it's a one or the other thing, they aren't designed to work together
23:21mangeI can now see that it's even mentioned on this page: https://github.com/marick/Midje/wiki/A-tutorial-introduction-for-Clojure.test-users, I just missed it on my earlier skim.
23:26amalloyyou can just put your facts into a deftest (and you really should, i think it's gross that midje doesn't encourage that)
23:26amalloy(deftest whatever (fact (+ 1 1) => 2)) works fine i believe
23:26justin_smithoh, I had no idea
23:27amalloyat any rate that's something you should try; i may have an overoptimistic memory
23:27justin_smithhha
23:28timothywdoes anyone know if/how I can get a lazy reduce?
23:28timothywneed to iterate / map / whatever, over a sequence where the current value needs the last calculation
23:29timothywpartition won't work, because each partitioned list won't know about any previous ones
23:29timothywany ideas?
23:29justin_smithreductions
23:29justin_smith,(reductions + (range))
23:29clojurebot(0 1 3 6 10 ...)
23:30timothywreductions does show intermediate results… but can a current iteration use a result from a previous one
23:31justin_smithumm, that is how it works
23:31justin_smiththe first arg is the previous return value, the second is the next input in the in seq
23:32timothywgot it - that’s embarrasing :)
23:32timothywlemme have a look
23:32justin_smithanother example ##(reductions conj () (range))
23:32lazybotExecution Timed Out!
23:32justin_smith,(reductions conj () (range))
23:32clojurebot(() (0) (1 0) (2 1 0) (3 2 1 0) ...)
23:36justin_smithtimothyw: if you need to carry more than one value (like a total and a previous input), a common idiom is to use destructuring
23:37timothywyeah, I just tried it out and reductions does exactly what I need
23:37timothywI knew I was missing something
23:37timothywand yes on the destructuring front
23:38timothywthat’ll make the code more readable
23:38justin_smith,(reductions (fn [[total prev] n] [(str total prev n) n]) ["" ""] '[a b c d e f g])
23:38clojurebot(["" ""] ["a" a] ["aab" b] ["aabbc" c] ["aabbccd" d] ...)
23:38justin_smithwait, no
23:38justin_smith,(reductions (fn [[total prev] n] [(str prev total n) n]) ["" ""] '[a b c d e f g])
23:38clojurebot(["" ""] ["a" a] ["aab" b] ["baabc" c] ["cbaabcd" d] ...)
23:39timothywfar out…
23:39justin_smith,(reductions (fn [[total prev] n] [(str total n prev) n]) ["" ""] '[a b c d e f g])
23:39timothyw,(+ 1 1)
23:39clojurebot(["" ""] ["a" a] ["aba" b] ["abacb" c] ["abacbdc" d] ...)
23:39clojurebot2
23:39justin_smiththat one has musical patterns ^
23:40timothywniiice - I thought clojurebot was a user
23:40justin_smitha very special one :)
23:40timothywyes, exactly, lol!!