#clojure log - Jan 03 2016

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

0:38 jarsherine: Hi everyone

0:38 Good morning

0:55 MorTal1ty: does anybody know if there is an up to date land of lisp but in clojure

1:16 kenrestivo: um, nope it's not for me

1:17 Jan 02, 2016 10:10:36 PM org.apache.http.impl.execchain.RetryExec execute

1:17 INFO: I/O exception (java.net.SocketException) caught when processing request to {s}->https://clojars.org:443: Network is unreachable

1:18 ok, well it is now, just popped up

1:26 i'm pretty sure the mirrors function of lein doesn't actually fallback or mirror

2:40 kopasetik: "I haven’t yet seen a loop that can’t be decomposed into a combination of map, filter, reduce." - @dustingetz

2:40 Agree?

2:43 amalloy: not as stated. consider: int sum = 0, i = 0; while (i++ < 100) sum += i;

2:43 this is easily stated in clojure as (reduce + 0 (range 101)), but you didn't admit other functions like range

2:45 kopasetik: amalloy: Good call

2:45 amalloy: kopasetik: it's close, though, if you refine it to: loops that consume an input list

2:45 kopasetik: Basically, I'm wondering whether I'll be able to solve typical brainteaser interview questions using Clojure...

2:45 amalloy: then you get into the universality of folds

2:45 yes

2:46 well, i can. whether you can i can't vouch for

2:46 kopasetik: amalloy: Heh, I guess that's why I'm practicing

2:47 map, reduce, and filter are much less confusing than for loops

2:47 Nested for loops are the worst

2:49 TEttinger: kopasetik: no, hardly

2:50 for(byte i = 0; i < 50; i--)

2:50 unchecked java arithmetic wraparound!

2:55 for(byte x=-128,y=1; x<y; y<<1,x>>>1) {System.out.println(y);} //how many numbers will this print?

2:56 I like to think someone completely new entered the channel, saw that, and noped out of here

6:03 annotationsinclj: how do you write this in clj - public interface Foo { @MyAnnotation(hello="World") String foo(Bar input); }

6:04 ,(definterface Foo (^String foo [^Bar input] ))

6:04 clojurebot: sandbox.Foo

6:05 annotationsinclj: how about the annotation

7:25 taspat: Hi, after creating a basic lein project, cider-jack-in completes with no warnings. But doing C-c M-. I get "cannot find resource".

7:26 MJB47: try doing C-c C-k first

7:26 ?

7:27 in a clj file

7:27 taspat: MJB47: i tried that, but same issue remains

7:27 MJB47: what symbol are you trying to find?

7:28 a clj core one or one of your own?

7:28 taspat: println and .toUpperCase

7:29 MJB47: i assume you can send code to cider fine?

7:30 taspat: yes

7:30 MJB47: im afraid i dont know then :(

8:34 Guest63553: hi

8:36 :(

8:38 kwladyka: Is it possible to get RUM with rum/defc rum/defcs and macro < works in Intellij IDEA with Cursive? Especially i mean about indent, jump to definition, refactoring, show parameters etc. Or to configure is myself?

9:09 maxxcan: exit

9:30 taspat: hi again, I do M-. on clojure function println in a basic lein project. However, C-c M-. yet does not work (reporting that resource was not found). M-. does not work .toUpperCase (asks for member of class..), neither does C-c M-. work

9:30 here is my .lein/profiles.clj

9:30 https://gist.github.com/anonymous/f2ffc15f4531c7b73239

9:30 cider-jack-in executes with no errors

9:31 should I include some paths of jdk, clojure in profiles.clj file?

9:31 i searching on web for a solution but cannot find anything :/

9:33 kwladyka: taspat should you write it on #emacs or similar channel?

9:39 taspat but... i tried emacs yesterday with installation brew install emacs --HEAD --with-cocoa --with-gnutls --with-librsvg, and most of things works for me

9:40 but.... for me intellij is better

9:40 but :) did lessons with emacs learn me a lot how to use intellij better!

10:08 tcrawley: justin_smith: I've updated the wiki page with your workaround: https://github.com/clojars/clojars-web/wiki/Mirrors

11:30 justin_smith: tcrawley-away: cool

11:39 annotationsinclj left, but this is the answer https://gist.github.com/richhickey/377213

15:07 taspat: render-component gets 2 arguments, but in this case I case pass hello-world function in (), [] or without any parentheses. https://gist.github.com/anonymous/226f527e71988e3df170

15:07 how does this work?

15:07 ridcully: isnt there an opening ( missing on the first reagent call?

15:08 also [] is just a vector

15:08 ,[+ - / *]

15:08 clojurebot: [#object[clojure.core$_PLUS_ 0x53aa3856 "clojure.core$_PLUS_@53aa3856"] #object[clojure.core$_ 0x56e7d31d "clojure.core$_@56e7d31d"] #object[clojure.core$_SLASH_ 0x2bbebe4a "clojure.core$_SLASH_@2bbebe4a"] #object[clojure.core$_STAR_ 0x1d4af67e "clojure.core$_STAR_@1d4af67e"]]

15:10 justin_smith: taspat: passing the component inside [] is just redundant nesting

15:10 callign the component (hello-world) means that @app-state is only looked up once (when it mounts), and future changes won't be seen

15:10 passing it as hello-world will cause re-rendering with @app-state changes

15:11 taspat: my preference is to pass in app-state as an argument to the component

15:11 taspat: this makes testing cleaner, and makes the control/data flow more explicit

15:14 taspat: thanks justin_smith, where can i read about this more?

15:16 justin_smith: taspat: the official reagent intro is good

15:23 taspat: justin_smith: nice, I checked source code and the answer in render dom/render function

15:23 thanks again

15:28 kwladyka: Somebody know how to setup Intellij to works with rum functions rum/defc and rum/fecfs and also macro < ? I need functions like refactoring, show parameters, jump to source code etc.

15:32 rhg135: cfleming has mentioned adding a way to define the syntax for custom macros

15:33 Might be implemented now

15:44 kwladyka: mmm i will try find something tomorrow in google

16:48 aaelony: #geekstogo

19:47 slester: lein repl throwing "Could not locate main__init.class or main.clj on classpath" errors could mean what exactly? :(

19:48 justin_smith: slester: something is trying to (require 'main) and main.clj does not exist

19:48 or it's on the wrong place in the classpath

20:24 m4ck: hi peeps

20:25 I'm trying to distinguish refs and atoms. I understand refs to be useful for when you need to update multiple identities in tandem.

20:25 However, atoms would seem just as useful for that purpose too. Could anybody help make the distinction?

20:25 justin_smith: m4ck: you can't coordinate multiple atoms safely

20:26 m4ck: justin_smith: not even if they're being swap!'d in the same transaction?

20:26 justin_smith: m4ck: for example if you have a container a, and a conainer b, and you need to increment one while decrementing the other (classic banking scenario), there is no safe way to do this with atoms

20:26 m4ck: swap! is not safe in transactions

20:26 that's what the ! in swap! actually means

20:27 m4ck: I see!

20:27 justin_smith: m4ck: most things in clojure.core that end with ! are not safe inside transactions

20:27 m4ck: So why would you not use a ref everywhere?

20:27 justin_smith: m4ck: because you can store multiple values in one atom

20:28 because sometimes your application logic doesn't require an atomic change that touches multiple containers

20:29 m4ck: Multiple values in one atom?

20:29 justin_smith: yes

20:29 m4ck: https://clojuredocs.org/clojure.core/atom <- indicates otherwise (although I'm sure I'm misunderstanding somehow)

20:29 justin_smith: ,(def a {:a 0 :b [1 2 3]})

20:29 clojurebot: #'sandbox/a

20:29 m4ck: oh, in terms of a collection, ok

20:29 justin_smith: there are multiple values in that hash-map

20:30 right

20:30 m4ck: That is do-able with a ref though, right?

20:30 justin_smith: yes, but multiple values in one collections does not perform as well as using a ref for each value

20:31 refs tend to be more complex to use, but perform better, and be more flexible

20:31 m4ck: consider, if you had all customer accounts in one hash-map in an atom, how much it would retry swaps

20:31 m4ck: every time two customer orders overlapped in time, you would have to run retries

20:32 refs allow for a smarter design with less retries (because you can have finer granularity while still having atomic operations)

20:32 m4ck: Right, I get that now - I _think_ that clarifies everything

20:32 justin_smith: but yeah, for most stuff, if it's not a performance bottleneck, we do just usually put a bunch of stuff in a hash-map in an atom, because that's simpler / easier to set up

20:33 m4ck: also, always remember that if you have side effects inside swap! or transact calls, you can see very odd results

20:33 m4ck: yup, I know to steer clear of that :)

20:34 thanks for the help

20:34 justin_smith: m4ck: similarly, putting mutable objects inside an atom or ref (since retries won't work as designed)

20:34 np

22:02 devth: elegant way of turning [:a 1 :b 2] into {:a 1 :b 2} ?

22:02 of course i figured it out right after asking :)

22:02 ,(apply hash-map [:a 1 :b 2])

22:02 clojurebot: {:b 2, :a 1}

22:08 devth: ,(take-nth 1 [:a 1 :b 2])

22:08 clojurebot: (:a 1 :b 2)

22:08 devth: wat?

22:09 ,(take-nth 2 [:a 1 :b 2])

22:09 clojurebot: (:a :b)

22:09 devth: i want 1 and 2

22:09 justin_smith: ,(take-nth 2 (rest [:a 1 :b 2]))

22:09 clojurebot: (1 2)

22:09 devth: sure but why?

22:09 seems strange

22:09 justin_smith: because it takes the first item, and then drops n

22:10 I mean sure, it could drop n and then take the next

22:10 devth: ok. guess that makes sense.

22:10 justin_smith: s/n/n-1

22:13 pilne: ... is it strange that the ability to mix my two favorite languages (lisp and haskell) almost... at-will has made me come to really like the jvm?

22:14 justin_smith: haha, nice

22:14 devth: pilne: what's your haskell-on-jvm?

22:14 pilne: frege

22:15 devth: cool. haven't played with it yet.

22:15 good?

22:16 pilne: super close to haskell, a few quirks due to the jvm, but the authors are definitely handling it well (it seems very inspired by clojure in how it brings a lisp syntax to the jvm without feeling "obligated" to be "common lisp")

22:17 devth: sounds awesome

22:18 pilne: and a stated goal is to be a "dialect" of haskell

22:20 amalloy: frege compiles to java source code, really. that's an unusual approach

22:21 pilne: for running on the jvm?

22:21 amalloy: yeah

22:22 bytecode is more common

22:22 pilne: i can see that actually

22:23 devth: wonder what perf implications/limitations are like

22:25 pilne: i'm not sure, i'm currently at that phase where i feel a bit... handcuffed by haskell compared to a lisp, so i'd probably just be calling functions written in frege from clojure for now

22:29 i love me some lisp, but the modern ecosystem of CL just feels like it is slipping, and haskell seems to offer a lot of what i enjoy in something "on the metal"

22:30 clojure saved me from a lot of headaches (:

22:39 alrighty.. stupid work stupid early tomorrow, ciao for niao!

23:09 devth: ,(clojure.set/difference #{1 2 3} #{2})

23:09 clojurebot: #error {\n :cause "clojure.set"\n :via\n [{:type java.lang.ClassNotFoundException\n :message "clojure.set"\n :at [java.net.URLClassLoader$1 run "URLClassLoader.java" 366]}]\n :trace\n [[java.net.URLClassLoader$1 run "URLClassLoader.java" 366]\n [java.net.URLClassLoader$1 run "URLClassLoader.java" 355]\n [java.security.AccessController doPrivileged "AccessController.java" -2]\n [java.net.URL...

23:09 justin_smith: devth: you need to require clojure.set first

23:09 devth: clearest way to remove an item from a set?

23:09 justin_smith: ah

23:09 justin_smith: devth: if it's a single item, you can just use disj

23:10 ,(disj #{1 2 3} 2)

23:10 clojurebot: #{1 3}

23:10 devth: oh right. forgot about that. thanks

23:47 _theriffer_: whats the best way to merge a map into every occurrence of another map by its key in a deeply nested data structure (tree like)

Logging service provided by n01se.net