#clojure log - Dec 04 2015

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

1:01 allen_: hello

1:01 can someone help me load a java file into a clojure project

1:02 i keep getting class not found exception

2:03 sara: is anyone know how to connect mysql database with my clojure project using clojurescript and om?

2:39 Lovey: wow . hello

2:42 thatslif_: having trouble understanding this, any suggestions? #(reduce + (map (constantly 1) %))

2:56 opqdonut: thatslif_: that's a convoluted way of computing the length of the input

2:56 thatslif_: (reduce + foo) is the sum of all elements in list foo

2:57 thatslif_: (constantly 1) is a function that always returns 1: ((constantly 1) x) ==> 1

2:57 thatslif_: so (map (constantly 1) bar) gives you a list with the same number of elements as bar, but all of the elements are 1

2:58 thatslif_: oh awesome, thanks for the explanation!

3:32 bionj: i'm trying to un-interleave by an arbitrary number of steps. for 2 dimensions this works: ((juxt #(take-nth 2 %) #(take-nth 2 (rest %))) (range 10)). but i need n dimensions

3:32 any thoughts?

3:59 kungi: Is cider 0.10 connect to lein repl so much faster or does it just feel like it?

4:04 bbaz: hi

4:16 Trioxin: i think my IDEA might be messed up. I'm just now finally getting back to learning clojure. what's the procedure for loading a namespace into the repl again so I can call functions in lets say the core.clj file?

4:17 i tried running the iml, project.clj, and then the core file all in the repl but wasn't able to run the functions I'm after

4:17 i'm using cursive

4:18 nvm, switch namespace /facepalm

4:18 actually that didn't work

4:20 (myfunc somestring)

4:22 it's unable to resolve the function name

4:23 nvm I got it

5:41 somnasper: http://www.infoworld.com/article/2987529/java/insider-oracle-lost-interest-in-java.html

5:41 So, what does this mean for Clojure's future?

5:41 mavbozo: java platform is one of those platform that is too big to fail

5:42 lots of multi-nationals, mega corporations depend on java platform

5:42 somnasper: So, it's more likely they'll get bought out than successfully stop supporting it?

5:48 mavbozo: somnasper, more likely oracle gets more pressure from those big mega corps to continue support java

5:48 most probably by buying oracle shares

5:51 powered: or we'll just all bail to clojurescript

5:51 somnasper: Argh, Figwheel keeps freezing on "notifying browser that file changed"

5:51 It didn't do this before, and it's doing it on two different projects

5:53 Server's working, but shows "Page not found"

5:56 TEttinger: I think the JVM has been slowly dying for a while under Oracle. I would not be surprised if the JDK9 changes to modularity finally encourage a large-scale fork of the VM itself

5:56 (to remove any link to oracle)

5:56 (probably also to fix things they have neglected)

5:58 powered: I don't think java will break backwards compatibility

5:59 TEttinger: I think they did in 8, in a few tiny ways

6:01 oooh this is good

6:01 http://docs.oracle.com/javase/7/docs/api/java/awt/image/renderable/RenderContext.html

6:01 still in 8 http://docs.oracle.com/javase/8/docs/api/java/awt/image/renderable/RenderContext.html

6:02 concetenate eh?

6:02 were they hiring kids fresh out of middle school?

6:02 "spell check good bro"

6:03 powered: " It is here for backward compatibility with previous releases which misspelled the method name"

6:03 lol

9:07 memoize doesn't actually guarantee that the function is only called once per argument

9:07 how would I get such a setup?

9:08 actually nevermind that, I logged something double so there's no problem :)

9:21 jonathanj: how would i perform some function f on every key-value pair in a map recursively and transform the map by the return value

9:22 beaky: iterate?

9:22 jonathanj: clojure.walk/walk seems like what i would want, calling walk again from the inner function if the value is a map

9:22 beaky: ,(iterate (fn [[k v]] (+ k v)) {0 1 1 2 2 3})

9:23 clojurebot: #<UnsupportedOperationException java.lang.UnsupportedOperationException: nth not supported on this type: PersistentArrayMap>

9:23 beaky: oops

9:25 muhuk: ,(map (fn [[k v]] (+ k v)) {0 1 1 2 2 3)

9:25 clojurebot: #<RuntimeException java.lang.RuntimeException: Unmatched delimiter: )>

9:25 muhuk: ,(map (fn [[k v]] (+ k v)) {0 1 1 2 2 3})

9:25 clojurebot: (1 3 5)

9:29 jonathanj: i want to retain the structure, just transform the values recursively

9:30 MJB47_: ,(map (fn [[k v]] {k (+ k v)}) {0 1 1 2 2 3})

9:30 clojurebot: ({0 1} {1 3} {2 5})

9:30 MJB47_: ?

9:30 nvm

9:31 muhuk: (into {} (map (fn [[k v]] ... [new-k new-v]) coll)) actually

9:32 jonathanj: and the fn inside map may be the outer function (calling itself)

9:54 sdegutis: Hi there.

9:56 beaky: hello sdegutis

9:56 sdegutis: How are you.

9:58 beaky: im alright

11:29 puredanger: hello all, the 2015 Clojure community survey is now open - would be great to see your responses! http://blog.cognitect.com/blog/2015-clojure-community-survey

11:39 ARM9: not sure what the difference between 'slightly important' and 'somewhat important' is

11:40 both sound equally indecisive to me

11:49 xemdetia: ARM9, to me somewhat important > slightly important

11:52 ARM9: maybe the meaning is lost in translation, both words translate to pretty much the exact same meanings

11:53 would've been clearer to just use 'important' for the third option imo

11:53 puredanger: it's a fairly arbitrary scale :)

11:53 xemdetia: well then you should let the user define their own in a variety of emojis

11:55 ARM9: 4 👍 out of 5

11:56 jonathanj: the dictionary definition of "slightly" is "to a small degree", while the definition of "somewhat" is "to a moderate extent"

11:57 maybe they could have been worded in a way that makes their differences more apparent to the majority of readers but they do have different meanings

12:06 kwladyka: (defn bar [page-size elems & opts] ...) (defn foo [page-size & opts] (rotator-cms page-size 1 opts)) <- how to pass foo opts into bar opts :)

12:10 sdegutis: puredanger: your css is so post-modern that I had a really hard time finding the link to the survey itself :(

12:11 puredanger: sorry :)

12:11 squarespace junk

12:12 sdegutis: puredanger: ok :)

12:13 puredanger: also 1/4 of these questions have words and phrases i dont understand, and 1/2 of the questions are worded such that i cant answer it correctly given the choices

12:13 puredanger: such as?

12:13 kwladyka: ok i know, with apply :)

12:13 sdegutis: puredanger: in #7 what is the difference between trad-infra and public-clud?

12:13 puredanger: public cloud would be stuff like AWS

12:13 sdegutis: puredanger: such as: in #5, our app has parts that are customer facing and parts that are internal

12:13 puredanger: then whats trad-infra?

12:13 puredanger: trad-infra would be stuff like a box in your own data center

12:14 in #5, can't you select both?

12:14 sdegutis: puredanger: okay that makes a lot more sense; i didnt know those phrases before, some "e.g. [bla]" might help next to answers

12:14 puredanger: ok

12:14 sdegutis: puredanger: for #5 yes but thats probably not what you mean by the question: the internal parts are for devops and scheduling and stuff, but they only serve the user facing parts

12:15 puredanger: I would just check both

12:15 sdegutis: puredanger: and in #3 its difficult to say my "primary" language, because i used several of them for work and several of them for hobby outside work, all being used heavily

12:15 jonathanj: how would i associate a value with a key only when the key doesn't exist?

12:15 sdegutis: puredanger: ok

12:15 puredanger: then check multiple

12:15 that's why it's multi select

12:15 sdegutis: puredanger: ok just wanted to let you know in case you intended teh answers to mean different things than im meaning when i check them

12:16 puredanger: jonathanj: you can check if it exists first

12:16 sdegutis: puredanger: from these questions and how they're worded, i have a strong feeling that you're not gonna get accurate data from me and from a lot of people is what i mean according to the definitions at their face value

12:16 puredanger: sdegutis: I think it's impossible for questions to be worded in such a way that they are universally understood

12:16 sdegutis: puredanger: i.e. #5 is going to look like i use clojure for micro-services and stuff, when thats not really the case

12:17 puredanger: ok +1

12:17 puredanger: also im guessing #6 doesnt really apply to teams of 1 dev

12:17 puredanger: if something doesn't apply, skip it

12:17 only the first 2 questions are required

12:17 sdegutis: oh

12:17 ok

12:23 ecmike: puredanger: done, first two pages only though

12:23 puredanger: well it doesn't count till you get to the end :)

12:24 ecmike: I clicked next to the end, just didn't fill anything out after page 21

12:24 *2

12:27 puredanger: cool, thx!

13:35 Guest19_: hi! I was wondering if someone could help me write a function having trouble getting parity with

13:36 fuck changed name.

13:36 anywyas, does anyone have a good example of a 'dissoc-in' that handles vectors as well?

13:38 or i guess a dissoc that handles vectors.

13:38 momerath: you might check out Specter: https://github.com/nathanmarz/specter

13:38 WorldsEndless: Is there a more elegant way to perform this kind of lazy-seq/defrecord-delving? https://www.refheap.com/112348

13:40 I guess a related question: is "first" the best way to grab a scalar value out of a lazy seq?

13:42 Guest19_: @momerath what should i check out in Specter?

13:42 justin_smith: WorldsEndless: especially when experimenting in the repl, I find -> very helpful with things like that

13:43 so I'd start with (-> personal-info type) - see it's a lazy-seq, (-> personal-info first type) - see it's a hash, (-> personal-info first keys) - OK, we've got a :content key (-> personal-info first :content type) etc. etc. etc.

13:44 WorldsEndless: I find the linear chain of lookups with -> much easier to read and explore with, compared with mixed nesting like you have

13:46 beaky: hello

13:46 WorldsEndless: justin_smith: Yeah, usually I use the thread, too, but I'm havin gtrouble at the point I get to the (filter #()) portion, since macros can't be nested

13:46 justin_smith: WorldsEndless: check this out ---

13:46 ,'#(foo)

13:46 clojurebot: (fn* [] (foo))

13:47 justin_smith: fn does nest, and #() is just a shorthand for fn

13:47 WorldsEndless: gotcha

13:47 justin_smith: WorldsEndless: and if you want to switch away from ->, deep nesting only obfuscates, I'd use let bindings instead

13:48 hard to read code leads to hard to find bugs

13:48 WorldsEndless: justin_smith: I definitely want -> . It's just a matter of getting it right with the records and filters

13:48 justin_smith: WorldsEndless: sure, ->> nests inside ->

13:49 WorldsEndless: justin_smith: really? I'll have to think about that. It's making me dizzy.

13:49 justin_smith: (-> personal-info first :content (->> filter (fn [x] (= :PFNAME (:tag x)))) first :content first)

13:50 oh, wait

13:50 no, yeah, that should work

13:50 except filter needs parens around it, of course

13:51 Guest19_: can i get feedback on

13:51 https://gist.github.com/fzakaria/740c16e07fb3835d2285

13:51 seems to work in my case of using JSON pointers (to remove a certain element) in a nested container with maps + vectors

13:52 justin_smith: Guest19_: on line 7, I think you can get away with using into instead of vec and concat

13:52 ,(into (subvec [:a :b :c :d] 2 3) [:g :h :i])

13:52 clojurebot: [:c :g :h :i]

13:52 justin_smith: that saves a few operations

13:52 Guest19_: thanks

13:53 simplified

13:54 is there a lein plugin that will minimize my requires

13:54 to what im using

13:55 justin_smith: Guest19_: I think eastwood might help with unneeded required libs - if not that slamhound might help

13:56 Guest19_: thanks.

13:59 WorldsEndless: Well, it's still some of the more difficult clojure code I've had to read, but it's much better: https://www.refheap.com/112348

14:00 justin_smith: WorldsEndless: also, an alternative to (fn [x] (= :PFNAME (:tag x))) is (comp #{:PFNAME} :tag)

14:01 whether the latter is more straightforward might be controversial

14:01 WorldsEndless: Guess it might be time for me to learn (comp)

14:02 justin_smith: the function is simple - knowing how it can simplify code and make it more powerful is the tricky / subtle part

14:02 imho

14:02 it's sort of a functional programming nerd goto, replacing nested function calls with using comp to generate a function

14:03 rhg135: Very much so, it just obfuscates mine

14:04 Knowing when to use it is difficult

14:27 timmmm: ,q

14:27 clojurebot: #error {\n :cause "Unable to resolve symbol: q in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: q 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: q in this context"\n ...

14:28 beaky: hehe

14:40 jakedust: hi! say I want to validate that for a map, every value is also a key. is prismatic schema good for that?

14:40 I'd just to attach a predicate like (clojure.set/subset? (set (vals my-map)) (set (keys my-map))) to a schema

14:42 justin_smith: jakedust: well, you can express the fact that the map is made of keyword keys with keyword values directly in a schema definition

14:42 clojurebot: In Ordnung

14:43 justin_smith: {s/Keyword s/Keyword}

14:44 jakedust: nb. keywords are not only for map keys (of course) and are not the only type allowed as keys in maps

14:44 MJB47: i think he means more {:a :b :b :a} is valid but {:a :b :c :a} isnt

14:44 jakedust: yup, as MJB47 said

14:44 justin_smith: oh

14:45 that's different, sorry

14:45 jakedust: actually, I'd happy just being able to say that (vals map) is a subset of (keys map)

14:46 while using the nice machinery of prismatic schema

14:47 justin_smith: jakedust: yeah, clearly I misunderstood what you were trying to do, but it looks like that's a reasonable approach

15:11 beaky: how do i do imperative programming in clojure

15:11 with good old mutable variables and for (int i = 0; i < n; i++) loops

15:11 justin_smith: beaky: if you use mutable java data types, you can do everything to them in clojure that you can in java

15:12 ARM9: (dotimes [i n] foo)

15:12 muhuk: beaky: check out https://github.com/ztellman/proteus

15:36 kenrestivo: what's the general philosophy on dealing with a java lib that has lots of mutable state? use its state, duplicate its functionality outside of the lib using clojure reference types?

15:36 similar question regarding callbacks: deal with its callback hell? or wrap it in core.async channels and go loops?

15:38 muhuk: kenrestivo: depends on the functionality I guess

15:38 kenrestivo: yeah, maybe there's no right answer.

15:38 muhuk: kenrestivo: but generally the host functionality is embraced

15:39 if you're interested, you can take a look at ring jetty adapter's source for example

15:39 kenrestivo: that's a great idea, thanks.

15:39 muhuk: yw

15:40 another interesting case could be clojure.java.jdbc

15:41 kenrestivo: interesting is an apt word

15:42 i think in this case i'm going to go all out and write a core.async wrapper

15:42 this is an mqtt library. there's already a clojure wrapper that works ok but is kind of thin

15:43 there's a neat core.async wrapper for sockets that i found a while ago; i might use that for inspiration

15:43 com.gearswithingears/async-sockets <-- something like this for mqtt is what i'd really like, so i'll try writing it

15:45 better link https://github.com/bguthrie/async-sockets the existing wrapper is here https://github.com/clojurewerkz/machine_head

17:35 Frozenlo`: yogthos: is there a function to create a table of contents in your markdown-clj? I gave it a quick look but found nothing of the sort.

17:47 justin_smith: Frozenlo`: markdown can do TOC?

17:51 Frozenlo`: Markdown lets you make titles/subtitles/subsub...titles. A TOC could just take them a link to their anchor.

17:53 /s/take/make

17:59 alive876: hi, newbie from a tutorial, when i run "lein ring server-headless " i get "'ring' is not a task. Did you mean this? lein run "the main program is here web.clj http://pastebin.com/yJ1Wfr9m and this is project.clj http://pastebin.com/zQn1up7i

18:00 Frozenlo`: alive876: I think you are missing the lein-ring plugin.

18:01 Wait, that's not the project.clj

18:01 justin_smith: yeah, that's a namespace, not a project.clj

18:02 alive876: did you use lein new to make your project, or just copy that one file?

18:03 alive876: i used this "lein new heroku crisco" from the tutorial

18:03 justin_smith: alive876: and then did you cd into the created dir before starting lein?

18:04 alive876: yes

18:04 justin_smith: can you share your actual project.clj? because that file above is not a valid project.clj, it's a namespace defining an http server

18:05 alive876: ok

18:07 here is the project,clj, sorry about mixup http://pastebin.com/PZj7CywW

18:08 and this is tutorial http://ben.vandgrift.com/2014/04/24/a-clojure-datomic-web-app-tutorial.html

18:08 justin_smith: alive876: yeah, that project doesn't have the lein ring plugin, so the lein ring commands won't be available

18:09 I guess that's a bug in the template?

18:09 alive876: seems to be

18:09 there are those other ring deps in there

18:10 justin_smith: easiest fix is to add the lein-ring plugin under the :plugins key https://github.com/weavejester/lein-ring [lein-ring "0.9.7"]

18:10 right, but you need a lein plugin to add lein commands

18:10 if you don't want to use lein ring you can start ring manually, but lein-ring is convenient (especially for the lein ring uberwar task)

18:11 alive876: ok, much thanks

18:11 justin_smith: alive876: one of my complaints about lein is that you can't explicitly ask for a template version (as far as I know), which makes tutorials break :(

18:12 so the users who are least able to fix the problem are stuck with broken intro materials

18:12 alive876: yea, as a newbie is kind of discourging

18:13 but its nice to have you guys out there!

18:13 ecmike: but irc help is encouraging, no?

18:13 justin_smith: we try

18:14 alive876: its the greatest, thats atleast half of why i'm going with clojure

18:14 i mean that too

18:24 WorldsEndless: Can anyone see why the final line brings a "No matching field found" error? https://www.refheap.com/112349

18:24 Even autocomplete agrees with all commands, but the REPL won't take it.

18:28 Think I found the problem. Checking: clojure nil will be read as java "null", right?

18:37 alive876: at this point it tells me it wants :ring {:handler your.app/handler} , however i'm not sure what your.app is, the project name is "crisco" but i am aware that namespaces may come into play?

18:44 gfredericks: WorldsEndless: yes, nil and null are entirely the same

18:45 different names for the same thing

18:45 WorldsEndless: Do I need to do anything special to invoke a java final class in Clojure?

18:45 Using (Class.) isn't seeming to do it fo rme

18:45 gfredericks: what does invoking a class mean?

18:45 (Class.) will instantiate it with the no-arg constructor

18:46 WorldsEndless: I'm trying to get one of these guys: https://pdfbox.apache.org/docs/2.0.0-SNAPSHOT/javadocs/org/apache/pdfbox/io/MemoryUsageSetting.html

18:47 gfredericks: do you know how you would do it in java?

18:47 WorldsEndless: But I'm getting a "no matching ctor" error.

18:48 gfredericks: right, there is no public constructor it looks like

18:48 (so that shouldn't work in java either)

18:48 WorldsEndless: Yeah, thought I just wasn't finding it.

18:48 gfredericks: there are various static methods that return instances of the class

18:48 maybe one of those does what you want

18:49 e.g. (MemoryUsageSetting/setupTempFileOnly) would do something (dunno what)

18:49 WorldsEndless: Yeah, that's what I was wondering

18:49 Ok, I'll try that syntax

18:49 gfredericks: (works for any static method)

18:54 alive876: newbie here, in the ring plug-in , it mentions it needs this handler in project file :ring {handler hello-world.core/handler}, hello-world.core supposed to me the path to the core.clj file? tanks

19:00 gfredericks: alive876: under default leiningen settings, you would have src/hello_world/core.clj with a (defn handler ...) inside it

19:05 alive876: <gfredericks> thanks. i am not actually using that hello world, one i am instead trying to get this other example working refered to above, where i think the equivalent is this file, http://pastebin.com/zQn1up7i but i don't see any ring handlers defined

19:08 gfredericks: alive876: `app` is technically a ring handler, but there are features in wrap-app that aren't included there

19:08 wrap-app isn't a handler, it's a function that returns a handler

19:08 and I'm not sure how to make that work with lein-ring

19:09 alive876: so it seems another mistake in this template (?)

20:41 troydm: how do I override default toString() implementation for a deftype?

20:41 ah, nvm

21:14 https://www.refheap.com/112355

21:14 is there any way to improve this?

21:15 I mean instead of writing everytime a function for both t and f, to instead use something that would be more suitable?

21:16 I'm thinkin of omitting a# part and instead have it just and then write functions as (+ 3 a) etc

21:16 but not sure if it's good idea

21:16 michaelrose: anyone use vim + clojure + fireplace + eastwood?

21:17 troydm: michaelrose: I use but don't use eastwood

21:17 michaelrose: I'm not sure what that even is

21:17 michaelrose: I seem to have the first 3 working but have some trouble with the last, I just basically want it to highlight stupid errors if any while I'm learning

21:17 its a linter for syntastic

21:17 troydm: oic, nope never tried it

21:20 michaelrose: any decent alternatives?

21:22 troydm: michaelrose: not sure, never tried using linters, but you probably can use it from inside clojure code as a library probably

21:22 michaelrose: that does not appear to be so

21:22 troydm: michaelrose: or some plugin for lein

21:22 michaelrose: its both a plugin in lein and a vim plugin

21:23 troydm: michaelrose: use it as lein plugin then

21:23 michaelrose: not from vim but using command line

21:24 michaelrose: that kind of negates the usefulness

21:25 well its not so bad evaluating with fireplace gives an error and a line number

21:26 WickedShell: ,(float-array [1 2 3])

21:26 clojurebot: #object["[F" 0x2336417 "[F@2336417"]

21:26 WickedShell: https://clojuredocs.org/clojure.core/float-array leads me to believe I should get float[] back? not obj?

21:27 ,(type (float-array [1 2 3]))

21:27 clojurebot: [F

21:27 michaelrose: and I can still run it from the command line to check the whole project so thats good enough

21:54 WickedShell: Has anyone ever had a problem creating a java array? all the into-array or float-array etc don't seem to be given me an array back, at least in the REPL if I print I never see []'s and they don't seem quite right (ie type gives me F or LFloat)

22:33 TEttinger: WickedShell: that's one of those weirdnesses of the JVM

22:33 ,(type (int-array [1 2 3]))

22:33 clojurebot: [I

22:33 TEttinger: ,(type (long-array [1 2 3]))

22:33 clojurebot: [J

22:34 TEttinger: ,(type (boolean-array [true true false]))

22:34 clojurebot: [Z

22:34 WickedShell: TEttinger, yeah I've determined it seems to be working just that its not a response on type like I expected at all...

22:34 TEttinger: those are, with some caveats, essentially the types

22:34 you can type hint something as taking a long array with ^longs or with ^"[L"

22:35 err

22:35 you can type hint something as taking a long array with ^longs or with ^"[J"

22:35 WickedShell: I now wish I marked error's as higher on the state of clojure survey :P I've been tripping on that for a bit for now :P

22:35 TEttinger: 2D long array? [[J

22:35 WickedShell: is there a list somewhere of the various I J Z stuff?

22:35 TEttinger: yeah, I found a blogpost a while back...

22:46 WickedShell: http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/types.html#wp276

22:46 damn...

22:46 clojurebot: primitive arrays |are| http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/types.html#wp276

22:46 clojurebot: Alles klar

22:47 TEttinger: ~primitive arrays

22:47 clojurebot: primitive arrays are http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/types.html#wp276

22:47 WickedShell: hey thanks! now to bookmark that again as I spent waaay to long on that

22:48 TEttinger: same here! I can't believe it isn't in a more prominent place somewhere

Logging service provided by n01se.net