#clojure log - Dec 03 2015

The Joy of Clojure
Main Clojure site
Google Group
List of all logged dates

3:07 kenrestivo: i'm getting a classnotfound error, but the jar is on the classpath and the class is inside the jar... are there weird java version mismatch issues that might be causing this?

3:07 i'm not a java guy so please forgive my jvm ignorance

3:21 tolstoy: ,(String. (byte-array '(-61 -72)))

3:21 clojurebot: "ø"

3:22 tolstoy: Are you using -jar?

3:26 TEttinger: kenrestivo: what does your command line look like?

3:26 if it isn't an uberjar you likely need -cp to change the classpath

3:28 jonathanj: ugh

3:28 Error compiling:

3:28 /Users/jonathan/Coding/clj-documint/test/documint/session_test.clj:21:14 No

3:28 single method: get_session of interface: documint.session.ISessionFactory

3:28 found for function: get-session of protocol: ISessionFactory

3:29 the slightly important part that error seems to totally forget to mention is the object the method is trying to be invoked on

3:30 pretty sure if it had said "No method get-session for object HeyGuysThisIsNotASessionFactory" i would have spent a lot less time scratching my head

3:30 tolstoy: I get those a lot. Missing parameter for me. ;)

3:37 thatslifeson: how to convert a string to a vector without all of the additonal \? i.e. 12345 => [\1 \2 \3 \4 \5]

3:37 looking for [1 2 3 4 5]

3:38 into [] is adding the \

3:42 tolstoy: ,(mapv str "abc")

3:42 clojurebot: ["a" "b" "c"]

3:43 beaky: i love mapv

3:43 TEttinger: ,(mapv #(- % 42) 12345)

3:43 clojurebot: #error {\n :cause "Don't know how to create ISeq from: java.lang.Long"\n :via\n [{:type java.lang.IllegalArgumentException\n :message "Don't know how to create ISeq from: java.lang.Long"\n :at [clojure.lang.RT seqFrom "RT.java" 535]}]\n :trace\n [[clojure.lang.RT seqFrom "RT.java" 535]\n [clojure.lang.RT seq "RT.java" 516]\n [clojure.core$seq__4116 invokeStatic "core.clj" 137]\n [clojure.co...

3:43 TEttinger: ,(mapv #(- % 42) "12345")

3:43 clojurebot: #error {\n :cause "java.lang.Character cannot be cast to java.lang.Number"\n :via\n [{:type java.lang.ClassCastException\n :message "java.lang.Character cannot be cast to java.lang.Number"\n :at [clojure.lang.Numbers minus "Numbers.java" 137]}]\n :trace\n [[clojure.lang.Numbers minus "Numbers.java" 137]\n [clojure.lang.Numbers minus "Numbers.java" 3692]\n [sandbox$eval77$fn__78 invoke "NO_SO...

3:43 TEttinger: ,(mapv #(- (int %) 42) "12345")

3:43 clojurebot: [7 8 9 10 11]

3:43 TEttinger: ,(mapv #(- (int %) 48) "12345")

3:43 clojurebot: [1 2 3 4 5]

3:44 tolstoy: ,(mapv #(Integer/parseInt %) (mapv str "123"))

3:44 clojurebot: [1 2 3]

3:44 TEttinger: yeah, tolstoy has a good approach

3:45 the two mapv

3:45 tolstoy: Isn't that a function that turns a method into a clojure function?

3:45 TEttinger: memfn

3:45 (doc memfn)

3:45 clojurebot: "([name & args]); Expands into code that creates a fn that expects to be passed an object and any args and calls the named instance method on the object passing the args. Use when you want to treat a Java method as a first-class fn. name may be type-hinted with the method receiver's type in order to avoid reflective calls."

3:45 TEttinger: but your case is a static function not a method

3:46 tolstoy: Ah. I think I've been down that road before.

3:46 TEttinger: ,(mapv (comp read-string str) "12345")

3:46 clojurebot: [1 2 3 4 5]

3:46 tolstoy: ,(mapv #(Integer/parseInt (str %)) "1234")

3:46 clojurebot: [1 2 3 4]

3:47 tolstoy: Or turn it into a transducer? ;)

3:47 TEttinger: ,(mapv (comp read-string str) "123+-")

3:47 clojurebot: [1 2 3 + -]

3:47 TEttinger: neat

3:47 it works for one-char variable names too...

3:49 tolstoy: Ever had the case where there's a ö in your json on the client and when it arrives in your java server (aleph) over a websocket (FreeBSD), it because a "?"?

3:50 beaky: https://www.youtube.com/watch?v=c2wyg9-4rR0 wow his posteroir deltoids

3:50 oops wrong channel

3:54 jonathanj: i read some interesting anecdote that people like Lu Xiaojun have a mechanical advantage in weightlifting by having a shorter than normal femur

4:15 can i combine (doto) and (..)?

4:15 (doto obj (.. some nested method arg))

4:16 to mean, in Java: obj.some.nested.method(arg)

5:06 sara_: Hi,Do anyone know how to redirect into a new page in clojure using om and react

5:07 jonathanj: I have a concurrency problem I'm not too sure how to resolve: https://pb.codehash.net/17aa60b4ee7a4e34bb2d4b1677325451

5:08 I don't know when to (.close src-doc) because I don't know how to tell when all the futures have been resolved.

5:08 beaky: is there something like >>=, <$>, and <*> in clojure

5:08 jonathanj: (piped-input-stream) is ring.util.io/piped-input-stream: https://github.com/ring-clojure/ring/blob/1.4.0/ring-core/src/ring/util/io.clj#L11

6:57 ashwin_: how can I decode cookies recieved in a request?

6:57 is there a standard library?

7:03 I think this must be a standard problem

7:03 has'nt anyone faced this before?

7:14 the_nonameguy: ashwin_: https://ring-clojure.github.io/ring/ring.middleware.cookies.html ?

7:15 are you looking for this, or the decoder function itself?

7:20 ashwin_: the_nonameguy, I need the decoder function itself

7:21 the_nonameguy: even the ring library just url decodes the string

7:41 jonathanj: hrm, i'm having some trouble getting clojure.data.json/write to do the right thing

7:48 (clojure.data.json/write {:some "fields"} (OutputStreamWriter. output-stream)) doesn't seem to actually write stuff

7:50 (.write output-stream "HELLO") appears to work fine

7:52 hrm, i guess i probably need to close the writer

7:52 (and use clojure.java.io/writer)

8:03 the_nonameguy: ashwin_: well then the decoder depends on the cookie encode, which you didn't state

8:04 if you do it yourself, the namespace containing the encoder usually contains the decoder as well

8:05 ashwin_: hmm

8:05 thanks I'll look into it

8:05 the_nonameguy: np

8:06 jonathanj: you possibly need to flush the buffer

9:12 jonathanj: hrm, is there any obvious way to convert https://pdfbox.apache.org/docs/2.0.0-SNAPSHOT/javadocs/org/apache/pdfbox/cos/COSDictionary.html to a Clojure map?

9:17 the_nonameguy: have you tried (into {} dict)?

9:19 jonathanj: yeah, it looks like that works, although i'm left with all these stupid java objects as keys and values

9:20 guess there's not really any way around writing a bunch of code to convert them

9:20 the_nonameguy: yeah, Clojure doesn't know how to turn Java classes into keywords :)

9:22 jonathanj: maybe this? http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/bean

9:23 also checkout: http://blog.jayfields.com/2011/05/clojure-converting-java-object-to.html

11:07 beaky: http://www.thedotpost.com/2015/11/rob-pike-simplicity-is-complicated wow what a contrast to rich hickey's philosophy :D

11:12 jonathanj: holy crap, (bean) works magic

11:12 what the heck is a JavaBean?

11:14 sdegutis: Is it possible to make `cider-interrupt` cancel a ProcessBuilder's Process on the main thread?

11:14 That would rock you know.

11:15 jonathanj: interface{} everywhere definitely feels the opposite of simple

11:17 sdegutis: jonathanj: we talkin about Go?

11:19 jonathanj: sdegutis: beaky linked Rob Pike's talk on simplicity in Go

11:19 sdegutis: Heh.

11:19 Oh Rob Pike, you're such a character.

11:19 jonathanj: <beaky> http://www.thedotpost.com/2015/11/rob-pike-simplicity-is-complicated wow what a contrast to rich hickey's philosophy :D

11:28 beaky: btw how come logic programming hasnt taken over programming

11:28 like oop and fp have

11:28 i dont see scala or js bragging about 'wow we have a logic constraints engine baked into the stdlib now! :D'

11:29 instead its all about lambdas or mixins and classes

11:29 or some sort of concurrency paradigm

11:29 sdegutis: beaky: it aint easy

11:29 beaky: oop is easy

11:30 beaky: logic is pretty simple imo you just list a bunch of rules and the system figures out what you want

11:33 xemdetia: beaky, well there was those couple disasters in the 70s

11:33 or was it the 80s?

11:35 beaky: ah those disasters

11:36 idk isnt oop also a failed disaster in a way (what happened to all those 90s stuff like COM+ and CORBA)

11:36 xemdetia: yeah but then java happened

11:36 corba is more an interop thing that kind of works

11:36 beaky: ah

11:37 xemdetia: C++ was still hot too

11:37 logic programming never really had a C++ or Java level penetration

11:37 sounds like we need a rebranding!

11:37 because even if its the same thing called something different somehow this works

11:38 sdegutis: afaiui, C++ and Java were highly corporation-friendly because they allowed strong decoupling of system components, so that teams could work on it simultaneously

11:38 plus they had a low barrier to entry, being so unfortunately similar to what was taught in university

11:38 that's a recipe for large scale adoption

11:38 anyway im just guessing

11:39 xemdetia: so lets call it aool

11:39 agile object oriented logic

11:39 just enough buzzword soup

11:40 xaxes`: xemdetia: you forgot web-scale! everything has to be web-scale these days

11:41 xemdetia: xaxes`, but I thought that was yesterday's words

11:41 how about webscale 2.0

11:41 agile web scale oriented object logic 2.0

11:41 awsool

11:42 we're one vowel-prefixed word away from almost having something convenient to say and also under the dos filename limit!

11:42 xaxes`: we're closer to awesome

11:42 :D

11:44 gfredericks: , #_ #nope 42

11:44 clojurebot: #<RuntimeException java.lang.RuntimeException: No reader function for tag nope>

11:44 beaky: btw why cant you nest #()

11:44 gfredericks: beaky: the arg symbols would be ambiguous

11:44 beaky: ah

11:44 why not just have an extra % for each level deep :D

11:44 gfredericks: :P

11:45 that would make moving code around a pain

11:49 xaxes`: justin_smith: so, I have to (ns luthien.palantiri (:require [(file-load "path/to/plugin.clj") :refer [name-of-some-function-from-file]))?

12:01 seppo: hi

12:02 does anyone know how to require this library in clj file? https://clojars.org/org.clojars.nakkaya/jnativehook

12:04 devn: seppo: you can open up the jarfile and see which files exist in there

12:07 seppo: devn sure

12:07 keymone: is there a way to make read-string not evaluate anything?

12:08 seppo: keymone for which purpose are you using read-string

12:08 devn I opened the jar file. what's next?

12:09 keymone: seppo: i want to write a simple s-exp diffing program, need to read clj file into tree and compare that to another tree - don't care about correctness of stuff in those trees

12:13 fuuduCoder: i want to be able to pass a filter condition to distinct. https://clojuredocs.org/clojure.core/distinct

12:14 gfredericks: fuuduCoder: what would the filter do?

12:14 fuuduCoder: what would be the best way. i want to filter out distinct maps from a vector of maps using certain keys

12:15 gfredericks: seppo: for the most part read-string already doesn't evaluate anything

12:15 fuuduCoder: maybe try giving an example?

12:15 fuuduCoder: yeah. so for e.g [{:a 1 :b 1} {:a 2 :b 2} {:a 1 :b 2}] on filter key :a would give me [{:a 1 :b 1} {:a 2 :b 2}]

12:15 i ahte emoticons.

12:15 *hate

12:16 gfredericks: fuuduCoder: that sounds like something that doesn't exist in clojure called distinct-by

12:16 github.com/Prismatic/plumbing has it

12:16 fuuduCoder: yeah. so for e.g [{:a 1 :c 1} {:a 2 :c 2} {:a 1 :c 2}] on filter key :a would give me [{:a 1 :c 1} {:a 2 :c 2}]

12:17 gfredericks: fuuduCoder: a quick and dirty impl is

12:17 ,(defn distinct-by [f coll] (->> coll (group-by f) (vals) (map first)))

12:17 clojurebot: #'sandbox/distinct-by

12:17 gfredericks: ,(distinct-by :a [{:a 1 :c 1} {:a 2 :c 2} {:a 1 :c 2}])

12:17 clojurebot: ({:a 1, :c 1} {:a 2, :c 2})

12:17 fuuduCoder: haha ..

12:17 gfredericks: not even all that dirty really

12:17 fuuduCoder: thats cool. but my map can get complex with multiple keys

12:18 gfredericks: so what would it mean to pass in multiple keys?

12:18 fuuduCoder: lets say keys :a and :b together would determine whether your map is unique or not

12:18 :a and :c

12:18 gfredericks: (juxt :a :c) would be your function then

12:18 ,(distinct-by (juxt :a :c) [{:a 1 :c 1} {:a 2 :c 2} {:a 1 :c 2}])

12:18 clojurebot: ({:a 1, :c 1} {:a 2, :c 2} {:a 1, :c 2})

12:19 fuuduCoder: let me try that.. seem spromising. thanks gfredericks

12:20 gfredericks: np

12:20 fuuduCoder: do you have functions at the tip of your mouth. i spent last 30 mins trying to figure out if there’s a useful function i could reuse

12:20 :-)

12:20 gfredericks: yes

12:30 fuuduCoder: gfredericks++

12:44 justin_smith: ,(defn distinct-by' [f coll] (peek (reduce (fn [[found results] e] (let [index (f e)] (if (contains? found index) [found results] [(conj found index) (conj results e)]))) [#{} []] coll)))

12:44 clojurebot: #'sandbox/distinct-by'

12:44 justin_smith: ,(distinct-by' (juxt :a :c) [{:a 1 :c 1} {:a 2 :c 2} {:a 1 :c 2}])

12:44 clojurebot: [{:a 1, :c 1} {:a 2, :c 2} {:a 1, :c 2}]

12:45 justin_smith: the (only?) advantage of my version is that with longer inputs the output would still be in order

12:55 gfredericks: oh yeah that's why it's dirty

13:37 JDShu: hi, does anybody have experience getting cider to work with maven?

13:38 justin_smith: JDShu: cider needs lein, and lein works well with maven

13:38 JDShu: are you trying to add deps at runtime? pallet / alembic makes that easy

13:39 JDShu: justin_smith: I'm working on a project that uses only maven and I'd like to use cider the same way I would with lein

13:39 justin_smith: JDShu: good luck, I think that would be a lot of work

13:41 JDShu: :( I'll try something else then - thanks though! good thing I asked here so I didn't end up spending a ton of time trying to do this

13:41 justin_smith: though I guess the main things you need are the same things that you would need to set up with boot https://github.com/boot-clj/boot/wiki/Cider-REPL

13:42 boot also doesn't use lein, so the instructions for making cider work with boot should be transferrable to a maven based project maybe?

13:42 the tricky part I guess is getting the right middleware injected for nrepl

13:43 amalloy: clojurebot: justin_smith is (paraphrased) boot is basically just maven

13:43 clojurebot: Ok.

13:43 justin_smith: umm....

13:43 amalloy: not quite what I meant

13:43 amalloy: well of course not, but what is the point of having factoid lookups for a person if not silly misquotes

13:44 justin_smith: haha, OK

13:45 JDShu: heh

13:45 alright thanks, I'll give that a shot

13:46 justin_smith: I wouldn't be surprised if you could load some of boot from within a maven launched repl (but don't have proof it works either)

13:49 dxlr8r: anybody tried coils? web framework for clj

14:03 tolstoy: Is it possible, using leiningen, to use JDK8 to target JDK7 for an uberjar?

14:06 amalloy: tolstoy: yes, set the appropriate javac-otions

14:06 see sample.project.clj

14:07 tolstoy: amalloy: Okay. It wasn't clear to me those options weren't just for the javac task. Thanks.

14:11 bendlas: tolstoy: they are just for the javac task, what else would you need to customize for targeting different jdks?

14:11 tolstoy: bendlas I want to build an uberjar with JDK8 to run on JDK7.

14:12 justin_smith: tolstoy: nothing in clojure itself targets jdks after 6

14:12 only the java compilation would do that

14:13 tolstoy: Ah, I'm getting java.lang.ClassNotFoundException: java.util.concurrent.CompletableFuture which must mean some lib or other I'm using deps on Java 8.

14:13 Or Oracle's JVM or something. Oy.

14:14 justin_smith: one of your deps must be trying to use that

14:14 bendlas: tolstoy: yes, ClassNotFound is a source code issue. If it were a target-jdk issue, you'd get some errors about invalid byte code versions or such

14:15 tolstoy: bendlas Yeah. I didn't even read the stack-trace when asking. Oops!

14:16 justin_smith: bendlas: "incompatible major/minor version...." iirc

14:16 tolstoy: And then it mentions 54. Or something like that.

14:16 bendlas: justin_smith: yes, I think YRC

14:29 jonathanj: (:a {} 42)

14:29 ,(:a {} 42)

14:29 clojurebot: 42

14:30 jonathanj: ,({} :a 42)

14:30 clojurebot: 42

14:30 jonathanj: hrm

14:30 justin_smith: ,(:a 42 42)

14:30 clojurebot: 42

14:30 jonathanj: i thought there was one of these forms that didn't support a default value

14:30 clojurebot: Titim gan éirí ort.

14:30 justin_smith: ,(nth nil 42 42)

14:30 clojurebot: 42

14:32 beaky: ,(apply (partial apply +) [[1 2 3] [4 5 6] [7 8 9]])

14:32 clojurebot: #error {\n :cause "clojure.lang.PersistentVector cannot be cast to java.lang.Number"\n :via\n [{:type java.lang.ClassCastException\n :message "clojure.lang.PersistentVector cannot be cast to java.lang.Number"\n :at [clojure.lang.Numbers add "Numbers.java" 128]}]\n :trace\n [[clojure.lang.Numbers add "Numbers.java" 128]\n [clojure.core$_PLUS_ invokeStatic "core.clj" 962]\n [clojure.core$_PLUS...

14:32 beaky: :(

14:33 justin_smith: ,(apply + (map (partial apply +) [[1 2 3] [4 5 6] [7 8 9]]))

14:34 clojurebot: 45

14:34 jonathanj: i don't think there's any point trying to partially apply + without any arguments, it takes & args anyway

14:34 justin_smith: jonathanj: you need apply

14:34 jonathanj: (reduce + (flatten [[1 2 3] [4 5 6] [7 8 9]]))

14:34 ,(reduce + (flatten [[1 2 3] [4 5 6] [7 8 9]]))

14:34 clojurebot: 45

14:34 justin_smith: ,flatten

14:34 clojurebot: #object[clojure.core$flatten 0x3ec68d46 "clojure.core$flatten@3ec68d46"]

14:34 justin_smith: ~flatten

14:34 clojurebot: flatten 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:34 justin_smith: jonathanj: flatten is the worst thing

14:34 ,(flatten {:a 1 :b 2})

14:34 clojurebot: ()

14:35 jonathanj: (reduce (partial apply +) [[1 2 3] [4 5 6] [7 8 9]])

14:35 ,(reduce (partial apply +) [[1 2 3] [4 5 6] [7 8 9]])

14:35 clojurebot: #error {\n :cause "clojure.lang.PersistentVector cannot be cast to java.lang.Number"\n :via\n [{:type java.lang.ClassCastException\n :message "clojure.lang.PersistentVector cannot be cast to java.lang.Number"\n :at [clojure.lang.Numbers add "Numbers.java" 128]}]\n :trace\n [[clojure.lang.Numbers add "Numbers.java" 128]\n [clojure.core$_PLUS_ invokeStatic "core.clj" 962]\n [clojure.core$_PLUS...

14:35 jonathanj: oh, that's the same problem as originally

14:35 justin_smith: why does flatten even exist then?

14:35 justin_smith: it's a mistake, and it is still there for backward compatibility I guess

14:36 I take the urge to flatten something as a sign I have made a mistake in my design

14:36 usually mapcat suffices

14:36 jonathanj: i've never actually called (flatten) before, i've just seen the function

14:39 gfredericks: ,(flatten {:a 1 :b [3]})

14:39 clojurebot: ()

14:39 gfredericks: I guess it treats maps as scalars doesn't it

14:39 ,(flatten [{:a 1 :b [3]}])

14:40 clojurebot: ({:a 1, :b [3]})

14:40 justin_smith: gfredericks: yeah, same with strings and sets iirc

14:41 jonathanj: ,(reduce (partial apply +) 0 [[1 2 3] [4 5 6] [7 8 9]])

14:41 clojurebot: 45

14:42 gfredericks: the other use cases of flatten are solved better by tree-seq

14:43 ,(tree-seq coll? seq {:a 1 :b [3]})

14:43 clojurebot: ({:a 1, :b [3]} [:a 1] :a 1 [:b [3]] ...)

14:43 gfredericks: ,(remove coll? (tree-seq coll? seq {:a 1 :b [3]}))

14:43 clojurebot: (:a 1 :b 3)

14:43 justin_smith: ,(remove coll? (tree-seq coll? seq {:a 1 :b [3 "hello"]}))

14:43 clojurebot: (:a 1 :b 3 "hello")

14:44 justin_smith: interesting

14:44 gfredericks: it's customizable as hell

14:44 ,(let [coll? (some-fn coll? string?)] (remove coll? (tree-seq coll? seq {:a 1 :b [3 "hello"]})))

14:44 clojurebot: (:a 1 :b 3 \h ...)

14:45 gfredericks: you could treat integers as collections of 1s if you wanted to

14:45 justin_smith: gfredericks: I still stand by flattening being a sign of either a bad design or a bad api (AKA someone else's bad design, but maybe you are stuck with it)

14:45 gfredericks: justin_smith: some things are treeful

14:50 justin_smith: gfredericks: hmm, I'll accept it as long as you name it "rake-leaves"

14:51 gfredericks: I think $ would be a good namespace for global mutable stuff

14:51 probably just repl-oriented

14:52 justin_smith: gfredericks: like how vinyasa does stuff?

14:52 gfredericks: maybe, I forgot that existed

14:54 woah this library is crazy

14:57 I wonder if he thought of the . namespace himself

15:26 jonathanj: is there a better way of spelling (- 0 n)?

15:28 matthavener: jonathanj: you can do (- n)

15:28 jonathanj: ah, thanks, i didn't even think to try that

15:30 has anyone used Graphics2D.rotate?

15:32 domokato_: in a macro, how do i get the namespace-qualified symbol of a passed-in symbol, for use in derive

15:32 ?

15:33 gfredericks: domokato_: I'm not sure if that problem is well-defined

15:34 domokato_: my guess is it'd be easier/cleaner to always have explicit namespaces anywhere you intend to use inheritance

15:35 domokato_: gfredericks: ah okay, that makes sense

15:37 Trioxin: I was surprised to not see any youtube vids on work in convolutional neural networks in clojure using opencl and/or cuda.

15:39 see libs in google though

15:40 domokato_: gfredericks: hm, in my macro i'm using the symbol to defrecord before using it in derive, which means I can't fully qualify it in the macro call since it doesn't exist yet

15:42 Trioxin: eh, https://github.com/whilo/nd4clj "Not really usable yet, as it is not compliant to core.matrix"

15:42 gfredericks: domokato_: symbols don't have to be "created", you can use any symbol anywhere anytime

15:43 ,'my.ns.SomeDefRecord

15:43 clojurebot: my.ns.SomeDefRecord

15:43 gfredericks: domokato_: I'm starting to think you might be asking about something else

15:43 probably the class instead of the symbol

15:44 domokato_: ,(doc derive)

15:44 clojurebot: "([tag parent] [h tag parent]); Establishes a parent/child relationship between parent and tag. Parent must be a namespace-qualified symbol or keyword and child can be either a namespace-qualified symbol or keyword or a class. h must be a hierarchy obtained from make-hierarchy, if not supplied defaults to, and modifies, the global hierarchy."

15:44 domokato_: i tried passing in the full symbol, org.aiinventions.aetherships.model/ShieldState, for example

15:44 but i'm getting "java.lang.RuntimeException: Can't refer to qualified var that doesn't exist" at compile time

15:47 ,(defrecord sandbox/test-record [thing])

15:47 clojurebot: #error {\n :cause "Can't refer to qualified var that doesn't exist"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Can't refer to qualified var that doesn't exist, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyzeSeq "Compiler.java" 6891]}\n {:type java.lang.RuntimeException\n :message "Can't refer to qualified var that do...

15:48 domokato_: gfredericks: so it looks like i need a non-fully qualified symbol for defrecord but a fully qualified symbol for derive. not sure how to do that

16:07 gfredericks: domokato_: I think you're still confused about the difference between a symbol and a class, but I can't help any further right now

16:08 justin_smith: domokato_: what are you doing with derive?

16:09 domokato_: justin_smith: i'm trying to implement polymorphic records

16:10 justin_smith: so you are using multimethods on records, and using derive to describe their heirarchy?

16:10 domokato_: haven't gotten to the multimethods yet, but yes

16:10 justin_smith: records are already "polymorphic", they can hold any data type you like

16:10 jakedust: hi, what's the most idiomatic way to test unexported functions (unexported as in `defn-`)

16:11 justin_smith: jakedust: @#'the-ns/the-private-fn

16:11 domokato_: justin_smith: i mean records that can be extended by other records

16:12 justin_smith: domokato_: so you want multimethod dispatch to find defaults based on some other more general record type?

16:12 jakedust: justin_smith: thanks! what's the difference between derefing it and not derefing it? both ways seem to work

16:12 justin_smith: because records don't do field inheritence or protocols or interface inheritence

16:13 jakedust: #'foo when called does an automatic deref

16:13 jakedust: oh, I see, thanks!

16:13 justin_smith: jakedust: but if you are using a value, you need the explicit @, so it's good to get in the habit

16:13 the calling case is special and the @ is optional then

16:15 domokato_: justin_smith: not sure what you mean by defaults. My "super records" are just lists of fields and don't have an actual class. When a record extends a super record, i just conj those super fields and put them in the defrecord call

16:15 justin_smith: so you are rolling your own inheritence by hand

16:15 domokato_: yep

16:16 i have different records that share a sprite field, for example, and i'd like to be able to get the sprite field out of all of them without having to switch on the type

16:16 justin_smith: domokato_: (map :sprite coll-of-heterogenous-records)

16:17 domokato_: i'm using records because keyword access to records is slow for some reason

16:17 er

16:17 .field

16:18 justin_smith: #(.field %) then ?

16:18 hiredman: it is slow because you have many different types so you are blowing the catch

16:18 cache

16:18 domokato_: justin_smith: doesn't that need to be type hinted to avoid reflection?

16:19 hiredman: oh, i didn't know that. but in my case there's not really a way around that, or is there?

16:19 hiredman: why aren't you using a single record type if they all have the same field?

16:20 if you do keep them as distinct records, use a protocol

16:20 domokato_: hiredman: because they have different fields in addition to that shared field. A ship has a sprite and a pilot, etc.. A bullet has a sprite and a lifespan

16:21 hiredman: use a protocol

16:22 domokato_: hiredman: use a protocol in what way?

16:22 hiredman: (defprotocol IHaveASprite (get-sprite [thing-with-a-sprite]))

16:23 justin_smith: agreed, if you find keyword lookup too slow, you won't like multimethod dispatch time

16:23 hiredman: extend the protocol to the records inline in your defrecords

16:23 domokato_: hiredman: also, going back to what you said before. are you saying if i process all of my ships in order, then all of my bullets, etc, i won't blow the cache and it'll be much faster?

16:24 hiredman: domokato_: no, the cache is monomorphic if I recall

16:24 once you start having different types going through callsite performance will tank

16:25 that is the case in generally for exverything on the jvm

16:26 an inline defprotocol on the jvm actually works around that (because everything that implements the protocol inline shares an interface)

16:27 so instead of having a bunch of types which, as far as the jvm and the jit knows, having nothing to do with each other, you get a bunch of types that the jits knows share some structure

16:31 domokato_: hiredman: okay! i think i got it

16:31 hiredman: for a second i forgot defrecord can extend protocols

16:32 thx hiredman and justin_smith

16:42 hibou: ,(map #(apply + %) (map list '(1 2 3) (rest '(1 2 3))))

16:42 clojurebot: (3 5)

16:42 hibou: is there any better way to do that ?

16:42 justin_smith: ,(map + '(1 2 3) (rest '(1 2 3)))

16:42 clojurebot: (3 5)

16:42 hibou: yes of course thanks justin_smith

16:43 gfredericks: ,(->> '(1 2 3) (partition 2 1) (map #(apply + %)))

16:43 clojurebot: (3 5)

16:43 gfredericks: nah justin_smith's is better

16:43 justin_smith: yours is more clever though

16:52 gfredericks: no way man

16:57 didibus: I'm calling into a java method, but Clojure seems to be selecting the wrong overload. I've tried to type hint, but I'm not sure how to do so it can pick the right overload

16:58 gfredericks: didibus: does *warn-on-reflection* still give you reflection warnings?

16:58 justin_smith: didibus: is it varargs? varargs methods from clojure are a bit weird

17:01 hiredman: didibus: why do you think it is picking the wrong overload?

17:01 didibus: Hum, actually, it might be my fault.

17:01 I think I might just have the signature wrong

17:08 WorldsEndless: Any ideas why my repl tells me "Please, install (or update) cider-nrepl 0.10.0 and restart CIDER" when I'm using today's package?

17:12 codahale: WorldsEndless: CIDER 0.10 was released today.

17:12 WorldsEndless: Right. And I'm using it (was using snapshot before)

17:12 The start of that message, before it starts warning about all the unspported nREPL ops, is:

17:12 ; CIDER 0.10.0 (package: 20151203.822) (Java 1.8.0_65, Clojure 1.7.0, nREPL 0.2.12)

17:13 codahale: Odd. No idea, sorry.

17:16 hibou: http://paste.ofcode.org/JbLWDZqqVRs287ReQESUFL

17:17 I got the error java.lang.ArithmeticException: integer overflow

17:17 in the last test https://www.4clojure.com/problem/132

17:18 gfredericks: hibou: looks like that means your function isn't lazy

17:18 hibou: the sequence created in that test throws that exception if you consume too much of it

17:18 hibou: because I used that zip (map list l (rest l)) ?

17:19 gfredericks: not sure, I didn't look at your code much after I didn't find any arithmetic there

17:19 hibou: when I do a (rest l) then my code is not lazy anymore ?

17:20 gfredericks: hibou: I suspect it's because you're using recur, which is eager

17:32 pvinis: hello. i wanna test all the things in a vector, without having many `(is (somefn item))`

17:32 can i do that?

17:32 gfredericks: doseq

17:32 (doseq [item items] (is (somefn item)))

17:32 pvinis: aha

17:32 awesome. thanks

17:44 kenrestivo: i love destructuring. makes code so much cleaner and concise

18:11 MONODA: I'm using cursive and intellij to debug some code but in order for my repl session to see the changes I make I need to restart the repl and start over again. any ideas why?

18:11 cfleming: MONODA: What sort of changes are you making?

18:12 MONODA: I'm writing the matrix library protocols for my matrix implementation

18:12 justin_smith: MONODA: higher order functions won't see new definitions for your defs / defns unless you re-run them

18:12 that's a common gotcha

18:13 MONODA: How do I rerun the defs? I thought I was doing that when I synced the current file with the repl

18:13 justin_smith: MONODA: oh, yeah, protocols are not very nice about reloads

18:13 MONODA: hmm ok... any workarounds?

18:13 justin_smith: you can make the protocol method call a def - then changing the def will update what the protocol does

18:14 but you would want to move it back from the def into the protocol when done debugging - you lose performance when you move it out to a def

18:14 MONODA: sounds easy enough

18:14 thanks

18:15 alive876_: i, could anyone take a look at my project.clj file, getting loading error http://pastebin.com/DdTmryNL much thanks!

18:15 MONODA: Im also having another problem where I get a stack overflow when I run some buggy code and then the repl starts acting weird until i reset

18:15 is that expected? any solutions other than restarting repl session?

18:16 cfleming: MONODA: What do you mean by acting weird?

18:17 MONODA: it will only respond with "stack overflow" until i restart it

18:17 but there are some functions I can call and it will respond as expected

18:18 cfleming: Is the loop in the stacktrace in your code, or in something else? It sounds like your buggy code is hanging around and being called somehow.

18:19 MONODA: im not sure, would I just check that with (pst) ?

18:20 cfleming: Yeah, or you can use the button in the Cursive REPL window to print the last exception

18:20 MONODA: so how would I kill my buggy code?

18:27 justin_smith: MONODA: is it happening in a thread somewhere?

18:27 MONODA: no im not doing any concurrency

18:28 justin_smith: then I don't see how the errors are repeating if you have a repl prompt...

18:49 pvinis: i want to chck if numbers in a seq are continious, is that close? `(reduce (fn [a b] (= (inc a) b)) (list 4 5 6))`

18:49 j-pb_: monotonic, or really off by one?

18:50 pvinis: by one

18:50 justin_smith: pvinis: that won't work because you need to return the previous item

18:50 pvinis: 456 is true, 356 is false

18:50 could you point me to the correct function?

18:50 maybe with doseq?

18:51 justin_smith: (every? #(= 1 %) (map - (rest coll) coll))

18:51 j-pb_: (= s (range (first s) (inc (last s)))

18:52 justin_smith: j-pb_: oh, that's a good one

18:52 pvinis: ok, i have to try them to understand

18:52 one sec

18:52 j-pb_: missing paren in my one, add one to the end ;D

18:53 probably not the most efficient one, since last is O(n)

18:54 justin_smith: (every? (map = s (range s Integer/MAX_VALUE)))

18:54 pvinis: j-pb_: ah cool! so you make the range from the first, and just cheeck if same

18:54 interesting..

18:54 j-pb_: justin_smith: nice even better :D

18:55 pvinis: justin_smith: trying yours now

18:55 justin_smith: pvinis: I think every? might be missing an arg there

18:56 pvinis: the first one is fine

18:57 yea, the second one is complaining

19:02 (every? (fn [[a b]] (= (inc a) b)) (partition 2 1 s))

19:02 someone on slack offered this..

19:03 partition with step works interestingly too

19:05 domokato: justin_smith, hiredman: it works! extensible records! http://pastebin.com/Xw796bk3 one level deep at least

19:07 j-pb: (= (rest s) (butlast (map inc s)))

19:10 pvinis: j-pb: is butlast faster?

19:10 isnt it same as last?

19:10 justin_smith: pvinis: butlast is all elements but the last

19:11 j-pb: nope

19:11 pvinis: yea. so to get that, itsnt it O(n) again?

19:11 j-pb: yeah

19:11 pvinis: oh linear time says the doc

19:11 cool

19:12 last is also linear..

19:12 j-pb: (or how about this

19:12 pvinis: what was O(n) that you said before?

19:12 j-pb: (apply = true (map = s (range (first s))))

19:12 last

19:13 pvinis: omg the one with butlast is magic!

19:13 justin_smith: (every? true? (map = s (range (first s)))

19:14 j-pb: (every? true? (map = s (iterate inc (first s)))

19:14 justin_smith: j-pb: that won't work actually - first is is used as the upper limit

19:14 right

19:14 j-pb: doesn't have chunking though so slower

19:14 yeah

19:14 justin_smith: or (range (first s) Integer/MAX_VALUE)

19:14 pvinis: my brain = mush

19:14 j-pb: yeah but dat max_val D:

19:15 ;D

19:15 but has chunking so thats nice

19:15 I wonder, does inc autoconvert to bignums once it hits the limit?

19:15 justin_smith: j-pb: it stops when the shorter collection runs out

19:15 j-pb: nope, but inc' does

19:15 ,(doc inc')

19:15 clojurebot: "([x]); Returns a number one greater than num. Supports arbitrary precision. See also: inc"

19:15 j-pb: noice

19:15 ,(doc inc")

19:15 clojurebot: #<RuntimeException java.lang.RuntimeException: EOF while reading string>

19:16 justin_smith: ,(inc' Long/MAX_VALUE)

19:16 clojurebot: 9223372036854775808N

19:16 justin_smith: ,(inc Long/MAX_VALUE)

19:16 clojurebot: #error {\n :cause "integer overflow"\n :via\n [{:type java.lang.ArithmeticException\n :message "integer overflow"\n :at [clojure.lang.Numbers throwIntOverflow "Numbers.java" 1501]}]\n :trace\n [[clojure.lang.Numbers throwIntOverflow "Numbers.java" 1501]\n [clojure.lang.Numbers inc "Numbers.java" 1839]\n [sandbox$eval93 invokeStatic "NO_SOURCE_FILE" 0]\n [sandbox$eval93 invoke "NO_SOURCE_FIL...

19:16 j-pb: ah, you never stop learning

19:17 irctc: Hi all. :)

19:17 j-pb: oi

19:17 pvinis: ok tried the apply one, and the too every

19:17 only this worked

19:17 (every? true? (map = s (iterate inc (first s)))

19:17 j-pb: yeah, I used range wrong

19:18 justin_smith: (every? true? (map = s (range (first s) Integer/MAX_VALUE)))

19:18 pvinis: ,(inc" Long/MAX_VALUE)

19:18 clojurebot: #<RuntimeException java.lang.RuntimeException: EOF while reading string>

19:18 justin_smith: pvinis: not inc", but inc'

19:19 irctc: Instead of printing output how do I save the output from this code to a separate variable outside the go block? (go (while true (println (<! c))))

19:19 j-pb: irctc: atom

19:19 irctc: j-pb: I am completely unfamiliar with atoms, xould you please explain?

19:20 pvinis: but j-pb and justin_smith, nice solutions. creative

19:20 j-pb: irctc: however, this will probably negate many of the advantages of core async, so data should be passed around through channels whenever possible

19:20 pvinis: i wrote them down so i can check them out again later

19:20 thank you :D

19:21 irctc: j-pb: well now I get data really fast just printed to stdout. Instead of that I want that data to be saved in a collection in some variable.

19:21 j-pb: irctc: what do you want to do? clojure doesn't really have variables, and assigning the value to something in the scope around the go block doesn't really make sense because of the while true

19:21 so you can later look at the values?

19:21 (def events (atom [])

19:21 irctc: Well, I just want to put the data returned from my async calls to a {}.

19:22 Yes.

19:22 j-pb: (go (while true (swap! events conj (<! c))))

19:22 that puts them into the events atom

19:22 but what do you want to do with that data?

19:23 I mean, putting it into the atom, doesn't nessecarily make it accessible

19:23 I mean, you need to get at it from some context right?

19:23 irctc: Well, I want to later process that data in other functions.

19:23 j-pb: pvinis: np, thanks for the nice riddle :D

19:24 irctc: why not pass that data to the processing functions via channels?

19:24 pvinis: :)

19:24 irctc: j-pb: How do I do that?

19:24 j-pb: irctc: alternatively you could do something like this if you just want to store the messages locally in the go loop

19:25 (go (loop [e (<! c)])))

19:25 urgh sorrry

19:26 (go (loop [e (<! c)

19:26 acc []]

19:26 (recur (<! c) (conj acc e))))

19:26 irctc: I know about the lets, and I tried that and it works, but outside the scope of the go block I can't access those bindings. I need to be able to access the results outside the go block.

19:26 j-pb: why?

19:26 clojurebot: why not?

19:27 j-pb: why not put the processing in other go blocks?

19:27 justin_smith: j-pb: if you exit the loop, the channel returned by the go block will be able to read whatever you returned from that loop

19:27 j-pb: the above is an example of a statefull goroutine btw

19:28 justin_smith: yeah sure, but if you have while true in there, then you never exit from it

19:28 justin_smith: j-pb: oh wait, you probably know that, and irctc was asking, never mind

19:28 irctc: Well, I have five calls to the same function with different data that need to happen simultaneously so that's why I'm using async. This processes the whole lot a lot faster. So far I can print the results but I want the results to be saved in a map so that I can use them later.

19:28 j-pb: irctc: honest suggestion, use futures

19:29 irctc: I need the while true to read the data as it is being fed into the channel.

19:29 j-pb: core async is great for coordination, but not that great for parralel computation

19:29 if you just want more performance, I'd suggest

19:29 pmap for example

19:29 or if you want to do something 5 times on the same data

19:29 justin_smith: irctc: looping infinitely is incompatible with returning a result

19:29 ~pmap

19:29 clojurebot: pmap is not what you want

19:30 irctc: So how do I create a loop that continually checks wether I have something in my channel that needs to be taken out?

19:30 justin_smith: irctc: loop while the channel is open, close the channel when done feeding it

19:30 j-pb: (let [r1 (future (expensive computation))

19:30 r2 (future (expensive computation2))

19:30 r3 (future (expensive computation3))

19:30 [@r1 @r2 @r3])

19:30 justin_smith: or use a special :finished value

19:30 j-pb: will do r1 r2 and r3 in parralel

19:32 unless you have a huge amount of coordination, core.async is usually not what you want

19:32 hell I just wrote a kafka inspirte persistent log for clojurescript so that I don't have to use the core.async sausage machine

19:33 irctc: so yeah, if you

19:34 irctc: j-pb: so what you're saying is that there is no way I can do this with core.async?

19:34 j-pb: 're new to clojure, learn about futures and pmap first, to speed things up

19:34 irctc: I'm not saying there is no way

19:34 I'm just saying it might not be the best option

19:34 what is your scenario?

19:34 you get data in?

19:35 and you want to do different things on it in parralel?

19:35 irctc: yes

19:36 j-pb: and what do you want to do with the results?, just keep them?

19:36 what do you want to do in parralel?

19:36 irctc: What is that website where I can quickly paste code to show you what I'm up to?

19:36 j-pb: gist

19:36 pastebin

19:38 irctc: http://pastebin.com/M4H0ypw6

19:38 That's my function.

19:39 j-pb: where does in-chan come from?

19:39 irctc: Now if instead of conj take-ipnut I just put println, it prints out the results really quickly. But as soon as I try to conj to take-input I get nil returned and take-input remains empty.

19:40 It's defined outside and it's allready filled with data to be processed.

19:40 j-pb: filled by what?

19:40 can you show me?

19:41 irctc: Sure it's a map of key-value pairs.

19:41 j-pb: no no :), not with what, by what ^^

19:41 how do you fill it

19:42 irctc: I have a function that generates the data when it's called.

19:42 j-pb: can you show me the code where you put it in in-chan :)

19:43 irctc: http://pastebin.com/DKSpSwr1

19:44 And stdin-reader is where the data is stored to be put in in-chan.

19:44 j-pb: and the content of stdin-reader is finite?

19:44 or an infinite stream?

19:44 irctc: Yes, it's finite.

19:44 j-pb: small enough to hold it in memory?

19:44 irctc: Yes.

19:45 j-pb: (pmap (fn [line] (create-ratings api-key line)) stdin-reader)

19:45 does exactly what you want

19:45 except that it automatically chooses the right amount of threads for maximum performance

19:46 and would generally faster than core.async I think because of less locking/sheduling overhead

19:48 on a side node, when you close the channel you can dump all it's contents into a collection with into

19:48 but don't do this

19:48 use pmap

19:49 irctc: j-pb: Thank you a thousand times!!!! :D

19:49 j-pb: most welcome :)

19:49 irctc: It does exactly what I needed it to do! :D

19:50 I really appreciate your help. :)

19:50 j-pb: no worries, glad I could :)

19:50 core.async is cool tech, but the most powerfull stuff is the simple things in the std lib :D

19:56 kenrestivo: i'm trying to use a library that uses JSR47 for logging, with timbre. how much pain and suffering will i have to endure to get that to happen?

20:02 pvinis: good night all

20:03 j-pb: night :)

20:11 irctc: Good night everyone!

20:15 MONODA: I'm writing a recursive protocol, how can I be sure that I am calling my new protocol rather than the protocol written for another datatype?

20:16 I'm getting a type error so i guess clojure doesnt know about my new implementation?

21:01 kenrestivo: no love for jsr47, eh?

21:04 hmm, i guess this jsr47 thing uses java.util.logging as a back-end. so now i just have to figure out how to grab those messages and get them into timbre, i guess? this java logging thing is... complected.

21:59 krabador: https://www.youtube.com/watch?v=CdPn1mCmqoE

Logging service provided by n01se.net