#clojure log - Apr 17 2015

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

0:06 Raynes: TEttinger: I'm always around, just occasionally too far gone to respond.

0:06 But I always get back to ya

0:06 I'm good like that.

0:59 Wow, the number of people in here has grown since I last poked around.

3:17 WickedShell: I suspect I am doing something really stupid but for the life of me I cannot terermine why this snippet of code fails http://pastebin.com/87hTKciH

3:18 if anyone can help point a new person on there way...

3:18 justin_smith: WickedShell: Buttton

3:18 WickedShell: justin_smith, huh?

3:19 justin_smith: ,(= 'Buttton 'Button)

3:19 clojurebot: false

3:19 WickedShell: oh ffs... thank you

3:19 justin_smith: np

3:19 WickedShell: ima go hide in a corner now, or maybe walk away from the keyboard...

3:19 justin_smith: haha

3:19 mavbozo: you'd better take a break

3:20 justin_smith: ,(symbol (str "Bu" (repeat (rand-int 8) \t) "on"))

3:20 clojurebot: Buclojure.lang.PersistentList$EmptyList@1on

3:20 brianpWins: created a project with lein, and started the repl but I have no idea how to intereact with my code

3:21 justin_smith: ,(symbol (str "Bu" (apply str (repeat (rand-int 8) \t)) "on"))

3:21 clojurebot: Buttttton

3:21 mavbozo: ~Button

3:21 clojurebot: I don't understand.

3:21 mavbozo: ~Buttton

3:21 clojurebot: Titim gan éirí ort.

3:21 * WickedShell le sigh

3:21 justin_smith: brianpWins: you can use require from the repl (require 'some.ns :reload)

3:21 WickedShell: sorry

3:22 WickedShell: justin_smith, s'all good :P

3:22 brianpWins: justin_smith: will try

3:22 justin_smith: brianpWins: and once the ns is required, you can call its functions of course, or switch to that ns, or maybe when you require it you can alias it, etc.

3:23 brianpWins: justin_smith: ah-hah! got it

3:25 justin_smith: also, you can use :reload-all instead of :reload, if you want recursive reloading

3:25 * mavbozo wondering whether hindley-milner type system prevents 'Buttton problem

3:25 justin_smith: mavbozo: it would do the same thing the clojure code did - tell him the symbol was not bound

3:26 mavbozo: I prefer to call it the banananana problem

3:27 ,(apply str "ba" (repeat (rand-int 8) "na"))

3:27 clojurebot: "bananananananana"

3:27 * mavbozo my stomach hurts

3:28 justin_smith: too much fruit?

3:29 * mavbozo stop it. hurts more..

3:29 mavbozo: justin_smith, now my throat gets hurt

3:31 maybe a old IDE feature will point out the banananana problem, like what eclipse does

3:31 justin_smith: or eastwood could

3:32 but the language will definitely tell you it's a problem (for vars) - I think eastwood can also point that issue out for keywords

3:33 mavbozo: maybe intellij's cursive has a feature for the repl where if I type a unbound symbol in the repl, the those symbol gets highlighted

3:34 cfleming: mavbozo: It does indeed - both in the REPL editor and the main one

3:35 mavbozo: (inc Cursive)

3:35 lazybot: ⇒ 2

3:42 sm0ke: so if i serialize a clojure function and deserialize and call it later i get unbound fn err

3:42 is there a way to solve this in a non ugly way

3:42 justin_smith: how are you serializing?

3:42 sm0ke: Just serialize java/kryo anything

3:43 justin_smith: sm0ke: there's a serializable function lib

3:43 sm0ke: yes, i want to avoid exactly that

3:43 justin_smith: https://github.com/technomancy/serializable-fn

3:43 you want to avoid serializable functions?

3:43 sm0ke: that library

3:43 justin_smith: because they aren't serializable out of the box

3:44 sm0ke: yes they are

3:44 functions extend serializable

3:44 justin_smith: I mean not in a way that is in any way useful

3:44 sm0ke: what do you mean?

3:45 justin_smith: the purpose of serialization is to get the thing back later in a usable form. Serializing a function "works" but not in a way that would get you back a function that works.

3:46 sm0ke: i am able to deserialize and call it just fine, if i hardcode the (require...) both remotely and locally

3:46 it even closes over local!

3:47 justin_smith: sm0ke: honestly it's news to me that it would work at all, but congrats on making it kind of work I guess

3:48 sm0ke: i did nothing, it just works!

3:48 i am not bullshitting you

3:48 slipset: The magic of clojure. It just works :)

3:48 sm0ke: wait a sec, ill give you a form

3:48 slipset: The problem with Java, it just doesn't

3:49 sm0ke: justin_smith: i think it works oob because clojure compiles functions and closures to class and objects

3:51 justin_smith: here try this (do (import 'org.apache.commons.lang.SerializationUtils) (def a 10) ((SerializationUtils/deserialize (SerializationUtils/serialize (partial + a))) 10))

3:52 brianpWins: I added [org.clojure/core.incubator "0.1.3"] as a dependency but can’t for the life of me figure out how to require it: (:require [clojure.core.incubator :refer [<<]])

3:53 sm0ke: brianpWins: i think you want :only

3:54 brianpWins: It can’t find the calss at all though: Exception in thread "main" java.lang.ClassNotFoundException: clojure.core.incubator

3:54 sm0ke: eh sorry even :refer should be fine

3:54 justin_smith: sm0ke: and if you serialized to a file, and then exited your repl, and reloaded from the file, would the deserialized partial work?

3:55 reloaded from a fresh repl, of course

3:55 sm0ke: justin_smith: yep, given you have all the classes and namespaces used while serializing

3:55 justin_smith: if I have all the classes and namespaces, why not just use a clojure readable form?

3:56 brianpWins: sm0ke: so is that the right ns to try and require?

3:56 sm0ke: for the given example it should just work as there is nothing outside of core

3:56 justin_smith: brianpWins: :require only works inside an ns form

3:57 you need require, and you need to quote the vector, outside an ns form

3:57 sm0ke: try with (print (seq (SerializationUtils/serialize (partial + a))))

3:57 justin_smith: I guess that's one definition of readable

3:58 brianpWins: justin_smith: that’s some terminology I do not understand (am noob).

3:58 (ns factorial-digit-sum.core \n :require [clojure.core.incubator :refer [<<]]))

3:58 justin_smith: inside (ns ...) you can do (:require [clojure.core.incubator :refer [<<]])

3:58 outside (ns ...) you need (require '[clojure.core.incubator :refer [<<]])

3:59 brianpWins: Exception in thread "main" java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Keyword

3:59 sm0ke: justin_smith: just checked works!

3:59 Now the only problem with this is, if i was using something like (partial myfn 10).. then myfn's namespace wont be automatically require'd

4:00 justin_smith: brianpWins: notice that in that ns form, you have no paren around :require

4:00 brianpWins: ahhhh

4:00 yeah i just caught that

4:00 okay loading works

4:00 but << is still not recognixed

4:00 Exception in thread "main" java.lang.IllegalAccessError: << does not exist,

4:00 mavbozo: brianpWins, no var inside that namespace

4:00 {dissoc-in #'clojure.core.incubator/dissoc-in, .?. #'clojure.core.incubator/.?., new-by-name #'clojure.core.incubator/new-by-name, -?>> #'clojure.core.incubator/-?>>, defmacro- #'clojure.core.incubator/defmacro-, -?> #'clojure.core.incubator/-?>, seqable? #'clojure.core.incubator/seqable?}

4:01 here's what's public inside that namespace

4:01 brianpWins: i don’t know what that means

4:02 justin_smith: sm0ke: right. And my point from the beginning was that this sort of serialization isn't actually explicitly supported. Good on you if it worked up to some point by accident I guess. I'll accept I was wrong if you can show that serialization of vars is supposed to work, but I don't really think it is.

4:02 mavbozo: they are public vars from clojure.core.incubator namespace

4:02 nuwanda_: brianpWins: it's in strint, not in the main incubator ns

4:02 TEttinger: what does << do?

4:02 brianpWins: ohhhhh i read string was deprecated and to use incubator directly =/

4:02 strint*

4:03 it’s for string interpolation

4:03 sm0ke: *there are no accidents*

4:03 mavbozo: TEttinger, cemerick wrote about that here http://cemerick.com/2009/12/04/string-interpolation-in-clojure/

4:03 justin_smith: sm0ke: clojure is full of things that work accidentally

4:03 ,(:+ 0 1)

4:03 clojurebot: 1

4:04 justin_smith: works great, until your first arg isn't 0, or you have more than two args

4:04 TEttinger: it's in clojure.core.strint

4:04 justin_smith: ,(:or nil :OK)

4:04 clojurebot: :OK

4:04 justin_smith: similar

4:04 TEttinger: so you need...

4:04 (require '[clojure.core.strint :refer [<<]])

4:05 or the equivalent for :require in ns

4:05 sm0ke: ,(keyword "a b c")

4:05 clojurebot: :a b c

4:05 justin_smith: right!

4:05 TEttinger: ,(:* 1 10)

4:05 clojurebot: 10

4:05 TEttinger: ,(:* 0 10)

4:05 clojurebot: 10

4:05 TEttinger: eh?

4:06 justin_smith: heh

4:06 sm0ke: thanks for noodling

4:06 mavbozo: ,((keyword ":a ok") 1 10)

4:06 clojurebot: 10

4:06 TEttinger: so it's looking up the key :* in a number, obviously not finding it, and getting the defualt?

4:06 justin_smith: TEttinger: right

4:06 TEttinger: more realistic is the :or

4:07 brianpWins: so how do I find what version of string to make a dependency

4:07 justin_smith: it even works if the first arg is always falsey

4:07 brianpWins: strint*

4:07 justin_smith: brianpWins: you could check clojars to see what is current if it's available there

4:07 TEttinger: brianpWins: https://github.com/clojure/core.incubator#installation

4:07 instructions are there

4:07 strint is in the same jar as incubator

4:08 brianpWins: that’s not very straight forward to a noob

4:08 TEttinger: oh

4:08 justin_smith: brianpWins: yes, packages don't directly map to namespaces and neither maps directly to jars

4:08 TEttinger: you should absolutely be using lein, first

4:08 brianpWins: am using lein

4:09 mavbozo: brianpWins, it's a "Proving ground for proposed new core fns".

4:09 TEttinger: then you would add that dependency into your project.clj file. it goes in a vector that's the value for the key :dependencies

4:09 brianpWins: Thanks for everyones patience with my noob questions

4:10 TEttinger: you should take a look at a detailed guide like braveclojure

4:10 $google braveclojure

4:10 lazybot: [Learn to Program the World's Most Bodacious Language with ...] http://www.braveclojure.com/

4:10 TEttinger: ha

4:10 that's it

4:10 brianpWins: will do

4:10 I breezed through a couple chapters of joy of closure

4:10 clojure

4:11 and took a stab at an eulerproblem last night,

4:11 TEttinger: apparently brave clojure is one of the better free resources for practical clojure learning

4:11 brianpWins: so just getting the hang of things

4:11 mavbozo: brianpWins, i learn the intricacies of :require, ns forms from this blog article http://blog.8thlight.com/colin-jones/2010/12/05/clojure-libs-and-namespaces-require-use-import-and-ns.html

4:12 TEttinger: yeah it can be a bit tricky at first, but it's fun once the tools fade into the background and you're writing insane macro generating macros or comparing your clojure code to equivalent but much more verbose java

4:13 that is my favorite thing in clojure. how outrageously tiny some code can be

4:14 certain things aren't super-concise, like anything dealing with native arrays (which you usually don't need, especially since a lot of the clojure data structures have gotten attention paid to their performance recently)

4:14 "recently", transients are recent for me since I didn't use them when they came out :)

4:15 reducers are another speeder-upper

4:15 brianpWins: yeah that’s what im liking so far

4:15 reletivley complex equations in a couple lines that are actually readable

4:15 TEttinger: lazy sequence stuff can be hard at first, but there are some times when using an infinite sequence is really convenient and clear

4:16 brianpWins: my distaste for haskell was complexitiy in a couple lines with to many optional syntaxes- completely un readable

4:16 TEttinger: yep

4:16 haskell can be clear, but it needs a fair amount of docs in the code to be able to read easily

4:21 one of the nicer things in clojure is not having to implement massive interfaces like I've had to do a bit in C#, and there it's just horrible. clojure(script) has some good design done into interop on all of its platforms.

4:23 reify and proxy are very powerful when you NEED to interoperate with java that expects specific stuff

4:25 this example would be, heh, a lot longer in java http://clojuredocs.org/clojure.core/proxy#example-542692cdc026201cdc326d5c

4:25 maybe not java 8

4:26 that takes a function as one of its arguments, and calls it when the component is clicked. I don't think that's terribly easy in java 7 or earlier, though it may be possible

4:26 slipset: TEttinger: should of course been done with core.async and a channel :)

4:26 clojurebot: Gabh mo leithscéal?

4:28 slipset: clojurebot: http://www.urbandictionary.com/define.php?term=gabh+mo+leithsc%C3%A9al

4:28 clojurebot: No entiendo

4:29 justin_smith: well that website is just rude

4:35 sm0ke: you want honest opinions on clojure go to #scala, all views here would be biased i guess

4:36 TEttinger: if you want my honest opinion on Scala, http://nurkiewicz.github.io/talks/2014/scalar/img/list-scala.png

4:37 not sure how this got here https://gist.github.com/anonymous/1406238

4:38 sm0ke: is it by steve yegge?

4:39 TEttinger: not sure, someone I know who tried Scala (like I did) and now rather strongly dislikes aspects of it posted it, it wasn't his either

4:40 sm0ke: ah its about the yammer switch from scala

4:40 TEttinger: it's rather well-written and basically syncs up perfectly with my experience

4:41 I also left #scala because the community was unhelpful more often than they were helpful

4:41 justin_smith: in what way?

4:42 sm0ke: they say the same about #clojure

4:42 someone even started a clojure beginner channel

4:42 TEttinger: there was one extremely vocal guy, don't recall the name, but he was extremely critical of scala and encouraged (loudly) anyone and everyone to switch to haskell

4:42 justin_smith: sm0ke: I don't think that was meant to reflect the helpfulness of this channel

4:43 TEttinger: haha, like bitemyapp / callen was here?

4:43 TEttinger: kinda, but even more vocal

4:43 he was a former language contributor

4:43 he apparently wrote the infamous kleene star thing

4:44 sm0ke: whats that?

4:45 TEttinger: ah, kleisli

4:45 http://scalaz.github.io/scalaz/scalaz-2.9.0-1-6.0.1/doc.sxr/scalaz/Kleisli.scala.html

4:45 variable naming like that apparently had a good reason

4:45 but it's still silly as hell

4:46 def ☆[M[_], A, B](f: A => M[B]): Kleisli[M, A, B] = kleisli(f)

4:46 justin_smith: TEttinger: my version would have more snowmen, hot beverages, and airplanes

4:46 TEttinger: haha

4:46 sm0ke: zomg that code "looks" so awesome

4:46 TEttinger: and no docs.

4:47 sm0ke: aesthetically scala is best

4:47 clojure looks like noodles on a plate

4:47 justin_smith: ☃☕✈

4:47 TEttinger: def traverse[F[_], AA <: A](f: F[AA])(implicit a: Applicative[M], t: Traverse[F]): M[F[B]] = f ↦ (Kleisli.this(_))

4:49 I have really found the same thing the yammer guy found from writing in Scala, then writing in other languages

4:49 justin_smith: ?

4:50 oh, that anonymous gist above

4:50 sm0ke: TEttinger: you mean to say every language is same

4:51 TEttinger: currently I have a number of projects in a number of languages, and usually clojure is the most concise. I spent a lot of time when I was working on a game in Scala trying to appease quirks of the language. Recently I wrote a large chunk of the functionality from that game in Java, and the java is about as long as the Scala

4:51 the scala's a fair bit more complex

4:51 it also likely performs poorly because it uses scala's iterator-based for

4:52 sm0ke: i have seen people are very religious about languages and would defend every shit feature in their language

4:52 TEttinger: (the java is index-based, the problem both solve is a mix of graph-like pathfinding code and array storage)

4:52 mnngfltg: sm0ke, pasta is tasty AND beautiful

4:53 TEttinger: technically all of the versions of this code I have written are ports of some very concise, rather slow clojure code

4:54 bja: sm0ke, once you achieve a certain understanding of an implementation, you can usually justify any particular feature

4:54 sm0ke: I honestly would code in visual foxpro if someone gives me more money

4:54 bja: in my experience, it's pretty rare to find a language feature that has absolutely no justification

4:55 slipset: I remember in about 1999/2000, one was adviced as to not create too many objects in Java, since creating objects was costly/slow

4:55 sm0ke: slipset: ha

4:55 is there a reference for this?

4:55 bja: reduce in python is pretty close

4:55 TEttinger: it's hard to make a direct comparison because the scala built up some extra features hard-coded into the pathfinding, which says a bit about my lack of experience in the language, and a bit about its inflexibility. the scala was very similar in length to C# that did the SAME thing. the java does more in some ways, less in others

4:56 slipset: sm0ke: nope, it's only my vague recollection of that time

4:56 justin_smith: slipset: it's still solid advice for super-tight loops (see eg. the disruptor)

4:56 slipset: http://www.javaworld.com/article/2075062/build-ci-sdlc/design-for-performance--part-2--reduce-object-creation.html

4:57 jonasen: clojure.java.jdbc question: Is there a way to *not* keywordize the keys in result sets from query?

4:57 TEttinger: anyway, I'll be happy to use that java pathfinding code from clojure now

4:57 slipset: justin_smith: probably, but the problem is that the average programmers take the advice for the super specific case and applies it everywhere.

4:57 justin_smith: slipset: yes, that is a problem

4:57 premature optimization and all that

4:58 slipset: Most programmers do not share the problems of Facebook/google/twitter

4:58 Most programmers work on applications which have no traffic

4:58 justin_smith: slipset: hell, those folks don't even need disruptor performance

4:58 slipset: Most programmers have no data

4:59 justin_smith: slipset: it's specifically hft

4:59 where being a few ms slower loses you millions of dollars

4:59 slipset: Yes, but most of us do not work in hft

4:59 allthough sometimes I wish I did.

4:59 justin_smith: heh

4:59 bja: jonasen, it seems to be hardcoded to map keyword

4:59 slipset: It would be nice working on code which needed to run fast

4:59 justin_smith: they have interesting performance problems

5:00 slipset: see also realtime dsp

5:00 sm0ke: slipset: make games

5:00 justin_smith: which can be fun for hobby stuff (software synths, real time visualization)

5:00 getting your latencies low can be interesting

5:00 sm0ke: slipset: btw, what do you code, which doesnt need to run fast?

5:00 bja: jonasen, you could ask for the resultset as arrays instead of maps

5:00 slipset: stupid crud apps for inhouse use

5:01 jonasen: bja: ok. clojure.walk/stringify-keys it is then. Kinda silly to first keywordize and then stringify

5:01 justin_smith: sm0ke: there's a difference between needing to be fast, and needing your latencies to be constrained

5:01 jonasen: bja: I'll look into that also, thanks!

5:01 slipset: I guess they need to be fast, but the problem with the fastness is very seldom in the code pr se.

5:01 bja: jonasen, it might be worthwhile to implement your own result-set-seq instead

5:01 justin_smith: eg. there are algorithms that are useless for low latency stuff that would have higher throughput, but they break your latency constraints

5:01 bja: so you don't incur the cost of transforming the keys twice

5:01 slipset: Often times a well placed index speeds things up

5:02 Or removing some network calls

5:02 sm0ke: caching

5:02 the whole youtube still runs on python and mysql

5:02 justin_smith: also, there's a difference between "this needs to be faster so we'll do better caching" and "this needs to be faster so we'll use an array of ints instead of using OO"

5:03 slipset: I guess my day job revolves around these rules: http://users.ece.utexas.edu/~adnan/pike.html

5:03 sm0ke: slow/fast is a infrastructure problem rather than programming

5:03 for most practial applications

5:03 slipset: (inc sm0ke)

5:03 lazybot: ⇒ 10

5:03 sm0ke: heh

5:04 bja: sm0ke, I actually wonder what percentage of what we experience as youtube isn't a complex network of services doing crap in the background

5:04 slipset: my biggest problem is figuring out what business wants to build, and secondly read a lot of code to figure out why it doesn't do what is required

5:05 mpenet: I actually know ppl using clj in hft context

5:05 bja: sure, the frontend is python and reading from mysql, but what about those recommendations and such

5:05 justin_smith: clojure breaks rules 3 and 4 frequently. Though the new smaller collections from ztellman help on that front.

5:05 mpenet: not everywhere tho (obviously)

5:06 slipset: justin_smith: I guess these rules apply to application devs, not to library/language devs

5:06 sm0ke: mpenet: as i said use clojure and have you hft datacenter isp near the trade center, or use C and operate from africa

5:06 hehe

5:06 justin_smith: slipset: the fact that clojure gets faster with ztellman's less complex small collection impl contraindicates that idea

5:06 mpenet: I guess it depends what you use clojure for

5:06 slipset: sm0ke: you need to have your datacenter isp _in_ the trade center

5:07 sm0ke: better

5:08 slipset: justin_smith: just curious, since I don't know ztellmans collection impl. Is that the thing that does one thing for small collections and another thing for bigger ones?

5:08 from the observation that a lot of collections in clojure are rather small?

5:09 mpenet: slipset: http://dev.clojure.org/jira/browse/CLJ-1517

5:09 justin_smith: slipset: right. And in practice most collections in clojure are small. And they get a perf boost from a simpler impl.

5:09 err, what you said while I was still typing :)

5:09 sm0ke: ugh it got pushed to 1.8?

5:10 justin_smith: it's a big change

5:10 sm0ke: should be available by 2016 i guess then

5:10 slipset: justin_smith:but one could argue that the collections will become even more complex, since they handle small and large collections differently

5:10 justin_smith: I hope

5:12 slipset: changing size becomes more complex, the impl behind the coll of a specific fixed size becomes simpler

5:12 if I understand correctly

5:12 slipset: :)

5:32 bja: any idea how one might embed a provided profile for dependencies in a top level lein profile. I tried something along the lines of (defproject :profiles {:foo {:provided {:dependencies [...]}}}). When I run `lein with-profile foo repl`, lein indicates that it's using both foo and provided profiles, but not seeming to pick up the deps in my embedded provided profile.

5:37 sm0ke: bja: that doesnt make sense to me

5:37 :provided is not a keyword for lein i think

5:37 you want a :foo profile and a :provided profile

5:39 i mean not a keyword inside a profile

5:39 bja: I know that can work. but I specifically want different things provided in different profiles

5:40 after looking at the leiningen source, it seems that it doesn't merge embedded :provided keys from profiles into the global :provided like I was hoping

5:40 sm0ke: yes, as i said it not recognized inside a profile

5:41 why dont you put them in a global :provided profile?

5:42 bja: because different profiles have different things provided

5:42 in particular, I'm building against multiple storm versions

5:42 and storm stupidly includes AOT'd versions of certain important clojure libraries in their distribution

5:43 so I have to deal with different versions of clj-time

5:43 also, different clojure versions

5:45 so in storm0.9.3 I want :provided {:dependencies [[org.clojure/clojure "1.5.1"]]} but in storm 0.11 I want :provided {:dependencies [[org.clojure/clojure "1.6.0"]]}

5:45 I think the solution is just to patch leiningen to merge the :provided key that I want

5:47 actually, https://github.com/technomancy/leiningen/blob/master/test_projects/sample-profile-meta/project.clj#L14

5:47 it looks like I can annotate the pom scope for dependencies. So I don't have to patch lein, I can just maintain a storm0.9.3-provided profile

5:47 which is acceptable

5:52 sm0ke: bja: hurmm this is why i did not like when leiningen stopped respecting :scope "provided"

5:53 in jar/uberjar tasks

6:03 bja: sm0ke, it doesn't respect ^{:pom-scope :provided} during uberjar creation?

6:04 sm0ke: that i dont know, but it does not respect [org.clojure/clojure "1.5.1" :scope "provided"]

6:04 bja: oh

6:05 sm0ke: it will put approprate entry in your pom.xml but will still include it in ubjerar

6:05 bja: it appears to respect :foo ^{:pom-scope :provided} [[org.clojure/clojure "1.5.1"]]}

6:05 based on just unzipping my uberjar

6:05 sm0ke: hurmm interesting

6:06 bja: err, :foo-profile ^{:pom-scope :provided} {:dependencies [[org.clojure/clojure "1.5.1"]]}

6:07 it looks like uberjar.clj only checks for the :provided scope of profiles. It won't walk individual dependencies to include/exclude jars

6:14 zot: hrm. using reader conditionals, found strange behavior — commented out line causes map parsing to break? https://gist.github.com/benfleis/8e98eaa456b770c408d7

6:14 (against 1.7.0-beta1)

6:14 removing the line makes problem go away

6:16 kaiyin: how do you reformat selected code in vim? I have fireplace and VimClojureStatic installed.

6:16 WickedShell: I'm somewhat familiar with Java/Swing but very new to clojure/seesaw, I have a change listener associated with a slider (which works just fine when I use prints to check it) however if I try and use a (config! to change the icon on one of my labels I get an AWT error about trying to convert my JLabel to a IFn, however it still changes the acual icon of the label... any ideas why I get the error in my event handler?

6:17 oddcully: kaiyin: `=`

6:18 kaiyin: cool.

6:26 TEttinger: WickedShell: I have a decent amount of experience in Seesaw, can you put some code on a pastebin or refheap?

6:28 WickedShell: Tettinger: I just restarted my REPL and that actually solved my problwm, apparently I had an extra set of parens somewhere (which I caught a long time ago, but apparently you can't simply rebind a new listener over the old one????)

6:28 TEttinger: ahhhhh

6:28 glad you caught it!

6:29 WickedShell: is that a common thing in seesaw? needing to restart the REPL so that changes to your running GUI will be reloaded?

6:31 broquaint: WickedShell: You can stay in the REPL but you do need to call pack! & show! to update your GUI.

6:31 IIRC

6:32 WickedShell: broquaint, ahhhh, yeah that makes a lot of sense actually, thanks

7:13 kaiyin: how do you destructure a vector like (x:xs) in haskell?

7:14 justin_smith: ,(let [[x & xs] (range 5)] xs)

7:14 clojurebot: (1 2 3 4)

7:14 kaiyin: cool.

7:14 justin_smith: that works in function args and loop bindings too

7:14 tsdh: I think there is a function (whats-my-name even? (range 10)) which returns [(0 2 4 6 8) (1 3 5 7 9)]? Do I remember correctly? If so, what's its name?

7:14 justin_smith: tsdh: group-by

7:14 well not quite

7:14 sorry

7:15 tsdh: group-by would give a hash map ##(group-by even? (range 10))

7:15 lazybot: ⇒ {true [0 2 4 6 8], false [1 3 5 7 9]}

7:16 tsdh: justin_smith: Better than nothing. But I think there's one doing exactly what I wrote and being lazy thereby.

7:17 justin_smith: ,((juxt filter remove) even? (range))

7:17 clojurebot: [(0 2 4 6 8 ...) (1 3 5 7 9 ...)]

7:17 hyPiRion: yah

7:17 tsdh: Ah, yes. That's possible!

7:17 justin_smith: or does (juxt filter remove) have a binding?

7:18 not too hard to type out I guess :)

7:18 tsdh: I remember again. juxt was what I used back then, and then amalloy_ and others here in this channel wrote better versions that didn't need to iterate the input seq twice.

7:19 justin_smith: so maybe it's a function in flatland/useful ...

7:20 tsdh: I think the suggested name was separate-with or something. But it's not in core I guess. Probably, it's only in IRC-log-0.0.1-SNAPSHOT.jar. ;-)

7:20 justin_smith: haha

7:20 tsdh: I mention useful because that's a lib amalloy contributes to extensively

7:21 tsdh: oh man, it would be funny to make a lib that lets you require and import from #clojure history

7:21 tsdh: I'll check it out.

7:21 justin_smith: Haha, yeah. Highly recommended for production use!

7:22 (defn conj [& args] (throw (RuntimeException. "Best wishes from tsdh, sucker!")))

7:25 justin_smith: You are right. amalloy_ put that function into flatland/useful. https://github.com/flatland/useful/blob/develop/src/flatland/useful/seq.clj#L26

7:26 justin_smith: well waddyakno

7:29 mavbozo: ,(RuntimeException. "yolo")

7:29 clojurebot: #error{:cause "yolo", :via [{:type java.lang.RuntimeException, :message "yolo", :at [sandbox$eval25 invoke "NO_SOURCE_FILE" -1]}], :trace [[sandbox$eval25 invoke "NO_SOURCE_FILE" -1] [clojure.lang.Compiler eval "Compiler.java" 6792] [clojure.lang.Compiler eval "Compiler.java" 6755] [clojure.core$eval invoke "core.clj" 3079] [clojure.core$eval3$fn__4$fn__14 invoke "NO_SOURCE_FILE" 0] ...]}

7:30 justin_smith: note that that created a new exception, but did not throw it

7:30 mavbozo: (ex-info "yolo")

7:30 ,(ex-info "yolo")

7:30 clojurebot: #error{:cause "Wrong number of args (1) passed to: core/ex-info", :via [{:type clojure.lang.ArityException, :message "Wrong number of args (1) passed to: core/ex-info", :at [clojure.lang.AFn throwArity "AFn.java" 429]}], :trace [[clojure.lang.AFn throwArity "AFn.java" 429] [clojure.lang.AFn invoke "AFn.java" 32] [sandbox$eval49 invoke "NO_SOURCE_FILE" 0] [clojure.lang.Compiler eval "Compiler.java"...

7:31 mavbozo: ,(doc ex-info)

7:31 clojurebot: "([msg map] [msg map cause]); Create an instance of ExceptionInfo, a RuntimeException subclass that carries a map of additional data."

7:31 mavbozo: ,(ex-info "yolo" {})

7:31 clojurebot: #error{:cause "yolo", :via [{:type clojure.lang.ExceptionInfo, :message "yolo", :at [clojure.core$ex_info invoke "core.clj" 4591]}], :trace [[clojure.core$ex_info invoke "core.clj" 4591] [sandbox$eval95 invoke "NO_SOURCE_FILE" 0] [clojure.lang.Compiler eval "Compiler.java" 6792] [clojure.lang.Compiler eval "Compiler.java" 6755] [clojure.core$eval invoke "core.clj" 3079] ...]}

7:31 slipset: was just discussing with a colleague who tinkers quite a bit with clojure

7:32 lxsameer: guys is there any websocket server for clojure ? ( without dependency to client code )

7:32 slipset: what do you do to pass info about the shape of data flowing around in a program

7:32 Seems to me like a clojure program starts out using maps, vectors and combinations thereof.

7:33 But after a while, and especially while debugging, it would be rather nice to know the shape of the params in (defn foo [bar baz] ...)

7:33 Should one start using defrecords and typehints, prismatic schema, core.typed or what?

7:34 Please don't say doc strings.

7:36 kaiyin: could anyone help with this? https://gist.github.com/kindlychung/691ffe277cf3bb99a44e

7:37 mavbozo: lxsameer, i don't quite understand "without dependency to client code".

7:38 lxsameer: mavbozo: I don't want it to force me to use a specific client code in my page

7:39 mpenet: lxsameer: https://github.com/mpenet/jet or aleph

7:40 mavbozo: lxsameer, i assume you have tried both aleph and http-kit and they forced you to use specific client code

7:40 mpenet: http-kit is barely maintained

7:41 lxsameer: thanks guys

7:51 profil: lxsameer: I am using aleph and there is no requirement of client code there

7:52 lxsameer: profil: cool,

7:53 profil: I want to create a webrtc connection I need aleph to manage peer signaling, is it worth to try aleph for this purpose

7:53 profil: lxsameer: yeah thats seems fine

7:53 lxsameer: cool

7:54 profil: lxsameer: on my client I am just wrapping javascript websocket with some clojurescript and core.async channels

7:55 lxsameer: profil: I never used clojurescript , my clients are android application and I want to use either clojure-android or simple javascript as clients

7:56 mavbozo: kaiyin, `primes` symbol inside `least-prime-divisor` is unbound

7:56 profil: lxsameer: oh okay, then I would just decide to use json and use javascript on the client side :)

7:57 lxsameer: profil: json ? through websocket or something ?

7:57 kaiyin: mavbozo: but primes is in the namespace.

7:58 mavbozo: kaiyin, but to bound the primes, you need to execute expression which contains `prime` function which depends on `least-prime-divisor` function

7:59 justin_smith: kaiyin: clojure doesn't allow out of order definitions, unless you use declare

7:59 mavbozo: kaiyin, also you have this ":else least-prime-divisor-from-primes ps n"

7:59 profil: lxsameer: yeah, the peer signaling data (SDP) needs to be sent somehow? Stringify the object to json and then send it over websocket

7:59 kaiyin: mavbozo: yeah, I noticed that, and have corrected it.

8:00 lxsameer: profil: ah yeah thanks, do you know any SDP lib for clojure or java ?

8:00 mavbozo: kaiyin, clojure's execution is top-down. you can not use definition not declared before.

8:00 profil: lxsameer: nope, never touched that part

8:00 mavbozo: kaiyin, i have to move some of your functions up

8:01 kaiyin: mavbozo: ok.

8:01 profil: lxsameer: are you supposed to touch the SDP sent from the users? if not then just pass it along like any other data

8:03 lxsameer: profil: thanks man

8:11 kaiyin: mavbozo: I don't think moving the functions works: https://gist.github.com/kindlychung/691ffe277cf3bb99a44e

8:12 ,(def myvec (into [2] [(first myvec)]))

8:12 clojurebot: #error{:cause "Don't know how to create ISeq from: clojure.lang.Var$Unbound", :via [{:type clojure.lang.Compiler$CompilerException, :message "java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Var$Unbound, compiling:(NO_SOURCE_FILE:0:0)", :at [clojure.lang.Compiler$InvokeExpr eval "Compiler.java" 3628]} {:type java.lang.IllegalArgumentException, :message "Don't kn...

8:12 justin_smith: kaiyin: that would only work with something lazy

8:12 vectors are never lazy

8:13 kaiyin: ,(def myvec (into (seq [2]) [(first myvec)]))

8:13 clojurebot: #error{:cause "Don't know how to create ISeq from: clojure.lang.Var$Unbound", :via [{:type clojure.lang.Compiler$CompilerException, :message "java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Var$Unbound, compiling:(NO_SOURCE_FILE:0:0)", :at [clojure.lang.Compiler$InvokeExpr eval "Compiler.java" 3628]} {:type java.lang.IllegalArgumentException, :message "Don't kn...

8:13 justin_smith: that's not lazy either

8:13 kaiyin: justin_smith: could you give a working example?

8:14 justin_smith: ,(def mylz (lazy-seq (cons 2 mylz)))

8:14 clojurebot: #'sandbox/mylz

8:14 justin_smith: ,mylz

8:14 clojurebot: (2 2 2 2 2 ...)

8:15 justin_smith: ,(nth mylz 1000)

8:15 clojurebot: 2

8:15 kaiyin: very cool.

8:16 justin_smith: kaiyin: for the most part clojure is not lazy, and you need lazy or delayed evaluation for that sort of definition to work

8:16 kaiyin: ok

8:19 mavbozo: (inc justin_smith) ;; showing usage of unbound symbol in lazy-seq

8:19 lazybot: ⇒ 244

8:20 kaiyin: I have got the prime searching function to work: http://codereview.stackexchange.com/questions/87180/prime-numbers-generator-in-clojure

8:21 mavbozo: kaiyin, cool

8:26 slipset: kaiyin use recur instead of calling least-prime-divisor-from-primes explisitly

8:26 kaiyin: slipset: yeah, I was thinking about that also, but need to brush up on the loop...recur syntax.

8:27 slipset: also, I guess you can use a multi arity fn for least-prime-divisor-from-primes so you don't need least-prime-divisor or vice versa

8:28 (defn least-prime-divisor ([n] ...) ([[p & ps] n] ...))

8:29 could imagine switching arg order in the second form...

8:55 kaiyin: c

8:56 can i insert latex equations in clojure doc string?

8:58 lalaland1125: kaiyin, You should be able to use Unicode literals for your doc string. That should be enough to provide the math formatting for equations.

8:59 The actual spacing and alignment might be a little off.

9:36 profil: I am making a version of a* and want to use a priority queue, any ideas of which lib to use?

9:41 puredanger: well, http://docs.oracle.com/javase/7/docs/api/java/util/PriorityQueue.html is in the box

9:48 profil: mutability :(

9:49 justin_smith: profil: wouldn't a sorted-set-by work?

9:49 (doc sorted-set-by)

9:49 clojurebot: "([comparator & keys]); Returns a new sorted set with supplied keys, using the supplied comparator. Any equal keys are handled as if by repeated uses of conj."

9:50 justin_smith: a* shouldn't care if duplicates are collapsed, right?

9:51 be careful about your sorting though - if two elements that should be equal in sorting are not identical, you'll want to use their full identity as part of what's compared

9:52 ,(sorted-set-by (juxt :a identity) {:a 0 :b 1} {:a 0 :b 2} {:a 22 :b 3} {:a -1 :b 0})

9:52 clojurebot: #error{:cause "Wrong number of args (2) passed to: core/identity", :via [{:type clojure.lang.ArityException, :message "Wrong number of args (2) passed to: core/identity", :at [clojure.lang.AFn throwArity "AFn.java" 429]}], :trace [[clojure.lang.AFn throwArity "AFn.java" 429] [clojure.lang.AFn invoke "AFn.java" 36] [clojure.core$juxt$fn__4489 invoke "core.clj" 2462] [clojure.lang.AFunction compare ...

9:52 justin_smith: err

9:53 profil: I'm just after O(logn) insert and constant pop/dequeu

9:53 puredanger: you need a heap right?

9:53 isn't there a clojure heap impl somewhere?

9:53 profil: yeah, thats usually how prio queues are implemented

9:53 in pure clojure? cool :D

9:54 I need to be able to set the comparator function

9:55 puredanger: googling "clojure heap" turned up a few things people have done

9:56 http://www.leonardoborges.com/writings/2013/02/03/purely-functional-data-structures-in-clojure-leftist-heaps/

9:56 profil: there is also clojure/data.priority-map

9:56 puredanger: ah, that's prob what I was thinking of

9:56 too many libs, too little brain

9:58 virmundi: hello. I’m trying to create a Ragtime implemention for ArangoDB. It appears that Ragtime presumes side-effecting connection creation implicity code execution for creation the db connection. If I want to have a db conn to Arango, I have to use an atom and then tie my files code to that atom.

9:58 is this right?

10:21 kaiyin: how do you load the current buffer into repl in fireplace?

10:30 why am i getting null point exception here? https://gist.github.com/kindlychung/4807b7cfe6ab9e1c5f0c

10:37 geirby: kaiyin: somehow null value got into gcd

10:37 kaiyin: I'll have a look

10:37 adereth: ,(let [[y & rest-ys] []] y)

10:37 clojurebot: nil

10:38 adereth: kaiyin: I think lines 47-48 are where the null gets introduced

10:39 kaiyin: adereth: i see, will try to fix it.

10:44 adereth: kaiyin: Even without that bug, I think relative-prime-with-rest? will always return false

10:45 lvh: Could anyone tell me how `lein test` actually selects tests? The docs suggest :default by default; my experimentation suggests otherwise. (lein test :default and just lein test doesn't run the same stuff). Here's my :test-selectors: https://github.com/lvh/icecap/blob/master/project.clj#L41-L42

10:45 oddcully: kaiyin: mark the code and do :Eval; read different ways up in `:help fireplace`

10:47 kaiyin: cool, thanks, oddcully

10:52 how can i fix the error 61: connection refused, in fireplace?

10:53 justin_smith: sounds like you aren't connected to a running repl

10:53 oddcully: or that what it thinks that should be the connection connects to something else

10:53 kaiyin: justin_smith: isn't it supposed to be automatically connected?

10:53 justin_smith: no, clojure uses a lot of ram, so none of the editors automatically makes a repl

10:53 oddcully: if you just want to have a lein repl and some clj opened then do a `:Connect nrepl://theurl`

10:54 or keep some `lein new scratchpad` around

10:56 kaiyin: justin_smith: oddcully: last time i opened gvim in the project dir, it automatically connects to the active repl that i opened in another terminal window.

10:56 oddcully: "in the project dir" might be the clue

10:57 kaiyin: oddcully: I am still in the project dir.

11:02 what other changes should i make if i have changed the project name in project.clj?

11:04 oddcully: kaiyin: no clue then. if you have one repl running and start vim afterwards (both in the project dir) it "usually works"

11:06 justin_smith: kaiyin: it's good if the group and project are reflected in the namespace / package structure

11:08 kaiyin: ok, i restarted the repl and everything works now.

11:10 Another problem, if I have a line like ;; (mod 5 3) and i select the sexp without the ;; before it, then :Eval, I got <namespace...> instead a 2, why?

11:10 this is in vim with fireplace.

11:12 oddcully: is this while marking the line or is your cursor inside the () ?

11:13 kaiyin: oddcully: not the whole line, just va(.

11:13 i.e., select everything between the parens, including the parens.

11:15 oddcully: only gives me the namespace if i shift-v it; other wise either Eval or cpp just ignore the line

11:18 kaiyin: oddcully: what addon manager do you use?

11:18 I use vundle.

11:19 virmundi: hello. I’m a bit stuck on implementing a idomatic set of rules. I have an input map like this {:action :create, :db “some-db”, :collection-name “a-collection”}. I want to put a structure together to that say if :action is :create and :db is set and :collection-name is set, then I want to execute a :create-collection fn. I figured that I would use multimethod and have the dispatch function return the routing keyword. My issu

11:19 with the dispatch function.

11:19 oddcully: good question actually... the one that uses ~/.vim/bundle

11:19 pathogen that is

11:21 geirby: how do I create a vector out of a few sequences?

11:22 wanna get a vector out of (range (int \A) (int \Z)) and (range (int \a) (int \z))

11:22 and probably something else

11:22 doing 'into' several times doesn't look good

11:23 oddcully: ,(doc concat)

11:23 clojurebot: "([] [x] [x y] [x y & zs]); Returns a lazy seq representing the concatenation of the elements in the supplied colls."

11:23 geirby: cheers

11:23 (inc oddcully)

11:23 lazybot: ⇒ 3

11:24 oddcully: cheers! (close to beertime now)

11:25 justin_smith: ,(reduce into [] [(map char (range (int \A) (inc (int \D)))) (map char (range (int \a) (inc (int \d))))])

11:25 clojurebot: [\A \B \C \D \a ...]

11:26 justin_smith: if you explicitly need a vector

11:26 geirby: of course, reduce

11:26 thanks

11:26 justin_smith: I use reduce like paula deen uses butter

11:27 geirby: actually, sequence would do just fine,

11:27 justin_smith: that's probably an out of date reference by now

11:27 in that case concat is simpler

11:29 rpaulo: justin_smith: out of date would probably be julia child

11:29 she also uses A LOT of butter

11:29 justin_smith: oh, TRUE

11:34 geirby: ,(->> [\A \Z \a \z \0 \9] (map int) (partition 2) (map (fn [[l h]] (range l h))) (apply concat) (map char))

11:34 clojurebot: (\A \B \C \D \E ...)

11:38 geirby: ahh, range is not enclusive

11:38 justin_smith: that's why I had inc on the upper bounds of mine

11:39 geirby: yep

11:54 mgaare_: anyone know why this is happening? (case (class (java.net.URI. "sup")) java.net.URI "uri" "not") ;; => "not"

11:56 mpenet: ,(doc case)

11:56 clojurebot: "([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...

11:56 mpenet: relevant part: "They must be compile-time literals"

11:58 there are tons of case+ case-eval etc macros that fix that

11:58 one google search away

11:58 mgaare_: a java class isn't a compile-time literal?

11:59 guess not, ok.

11:59 mpenet: http://cemerick.com/2010/08/03/enhancing-clojures-case-to-evaluate-dispatch-values/

11:59 mgaare_: tried a couple others.

11:59 thanks!

12:01 noncom: what is the best approach to make certain fns available from any ns in the project? (besides of referring it from everywhere)

12:01 potemkin?

12:07 justin_smith: monkeypatching clojure.core?

12:07 (don't do that)

12:08 noncom: hehe, yeah )

12:08 however, i do patch it in a couple of places, like get the global (start) fn available from anywhere

12:14 the-kenny: That sounds quite dirty

12:15 kaiyin: could anyone help with this? http://stackoverflow.com/questions/29704447/how-to-avoid-stackoverflow-in-clojure-recursive-function

12:15 the case looks hairy because loop...recur can only be used with tail calls.

12:20 sduckett: Adduser ian 0knaukim;

12:21 oddcully: hmm

12:25 broquaint: kaiyin: How are those recursive functions meant to terminate (it doesn't look like they do)?

12:25 kaiyin: broquaint: they are not to meant to end, i intended to get a lazy seq out of it.

12:25 broquaint: because there are infinite number of primes.

12:26 broquaint: Then you need to put lazy-set in the tail position - http://conj.io/store/v1/org.clojure/clojure/1.7.0-alpha4/clj/clojure.core/lazy-seq/

12:26 i.e within mark & sieve.

12:30 kaiyin: broquaint: i see.

12:30 patrickgombert: I'm seeing some weirdness with :volatile-mutable and deftype -- https://gist.github.com/patrickgombert/1bcb8a051aeb3e82d855

12:30 it fails to compile when I set! in a try..finally and return this

12:30 if I don't use try..finally or do not return this then it succeeds in compiling

12:32 dnolen: patrickgombert: "weirdness" is vauge, you should include a stack trace

12:34 puredanger: patrickgombert: that sounds like a bug - please file a jira http://dev.clojure.org/jira/browse/CLJ

12:34 eraserhd: Is there a clojure equivalent to "organize imports" available via vim-fireplace or stand-alone.

12:34 ?

12:34 oddcully: eraserhd: slamhound?

12:34 patrickgombert: dnolen: sorry, should have included that. I updated the gist. I get an IllegalArgumentException which says Cannot assign to non-muable: _oof

12:35 puredanger: will do

12:35 kaiyin: broquaint: I added the lazy-seq part, but now it hangs the whole nrepl session: https://gist.github.com/kindlychung/6c690044dcbbba0c464e

12:36 eraserhd: oddcully: yes!

12:39 dnolen: patrickgombert: trying dropping the leading `-` from that field name

12:39 patrickgombert: s/trying/try

12:40 patrickgombert: dnolen: seeing the same issue

12:40 dnolen: patrickgombert: ah k, yeah dunno then :)

12:41 patrickgombert: seeing it on 1.6.0 and 1.7.0-beta1

12:41 no worries, I'll file a bug

12:43 broquaint: kaiyin: I believe that's because you're feeding an infinite list to sieve which then tries to destructure it :)

12:43 If you just pass (range 10) f.ex then sieve returns quite snappily.

12:44 I think you'll need to take the first/rest approach like in the example in those docs I linked.

12:56 kaiyin: broquaint: that sieve also hangs indefinitely, :-)

12:57 and at last throws stackoverflow error.

13:24 virmundi: how do I pass multi arguments to a multimethod? I want to have a map and a database context. The dispatch function will use the map to figure out which function to call and db context hangs around for future use.

13:26 Bronsa: ,(defmulti foo (fn [m db] (:key m)))

13:27 clojurebot: #'sandbox/foo

13:27 Bronsa: ,(defmethod foo :foo [_ db] db)

13:27 clojurebot: #object[clojure.lang.MultiFn 0x48a88dc8 "clojure.lang.MultiFn@48a88dc8"]

13:27 Bronsa: ,(foo {:key :foo} 1)

13:27 clojurebot: 1

13:27 Bronsa: virmundi: ^

13:29 virmundi: could have sworn I tried that. Thanks

13:29 it makes sense.

13:30 TEttinger: (inc Bronsa)

13:30 lazybot: ⇒ 106

13:38 kaiyin: broquaint: In the end I managed to convert the non-tail call into a tail call, and added some code for edge cases: http://codereview.stackexchange.com/questions/87233/sieve-of-eratosthenes-in-clojure

13:38 and the function is now working, although I am not yet completely happy with it.

13:53 saik0: kaiyin: you might enjoy https://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf

13:57 she describes an unbounded sieve with a wheel optimization

13:57 TEttinger: infinite lazy sequence of primes, you say? why not BigInteger?

13:57 ,(take 50 (remove nil? (map #(if(.isProbablePrime(biginteger %)5) % nil)(range))) )

13:57 clojurebot: (2 3 5 7 11 ...)

13:57 TEttinger: &(take 500 (remove nil? (map #(if(.isProbablePrime(biginteger %)5) % nil)(range))) )

13:57 lazybot: ⇒ (2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373... https://www.refheap.com/99734

13:58 kaiyin: saik0: thanks.

13:58 TEttinger: oh that can be golfed...

14:01 saik0: TEttinger dont know about about isProbablePrime's impl, but the sieve in the paper is ~4x faster, by my very unscientific test

14:03 TEttinger: saik0, testing on the same machine?

14:03 lazybot and clojurebot run on different hardware

14:03 saik0: TEttinger on my machine, yes

14:03 TEttinger: &(take 500 (let [uno (biginteger 1)](remove nil? (map #(if(.isProbablePrime % 3) %)(iterate #(.add % uno) (biginteger))))) )

14:03 lazybot: clojure.lang.ArityException: Wrong number of args (0) passed to: core/biginteger

14:03 TEttinger: &(take 500 (let [uno (biginteger 1)](remove nil? (map #(if(.isProbablePrime % 3) %)(iterate #(.add % uno) (biginteger 2))))) )

14:03 lazybot: Execution Timed Out!

14:03 TEttinger: interesting

14:04 broquaint: kaiyin: Nice one :)

14:04 kaiyin: broquaint: thanks. :-)

14:04 saik0: TEttinger my impl is lacking the wheel sieve as well, let me add it

14:09 TEttinger: saik0, try with less probableprime precision:

14:09 ,(take 500 (remove nil? (map #(if(.isProbablePrime(biginteger %)3) % nil)(range))) )

14:09 clojurebot: (2 3 5 7 11 ...)

14:09 TEttinger: 2 is too low and results in false positives, I use 3 there and used 5 initially

14:11 timvisher: ,(format "%s&%s" "charnock" "whitefield")

14:11 clojurebot: "charnock&whitefield"

14:11 timvisher: bah...

14:12 ah... it's that it's going through mustache

14:13 anyone know off the top of their head how to put `&` in a mustache template (for a lein template)?

14:15 looks like maybe {{{}}} or {{&}}

14:16 glad to know my understanding of `format` isn't entirely broken :)

14:36 saik0: TEttinger, kaiyin: https://gist.github.com/saik0/ed01393d89e2fc613775 might not be too elegant/idiomatic, still learning

14:39 TEttinger: saik0: one thing that's non-idiomatic is using reversed order conj on seqs/lists. normally vectors are preferred, and they conj to the right end.

14:39 ([] (conj (primes (prime-cand)) 7 5 3 2)) ; this stuff

14:40 saik0: TEttinger I hail from Scheme. What's a vector ;)

14:40 (dont answer that)

14:40 TEttinger: what's our vector, victor?

14:41 we have clearance, clarence.

14:41 roger, roger.

14:42 clyfe: https://tbaldridge.pivotshare.com/media/testing-episode-1/22222/feature can't view, is it broken ?

14:42 TEttinger: works for me, clyfe

14:44 AeroNotix_: I have an implementation of a mutex. What's a good test to ensure that it's correct?

14:45 saik0: TEttinger will try that destructure the inifinite seq?

14:45 (conj [2 3 5 7] (primes (prime-cand)))

14:45 TEttinger: concat

14:46 saik0: I should finish joy of clojure before i write any more

14:46 thanks

14:46 TEttinger: ,(concat [2 3 5 7] (primes (prime-cand))) ; may be more idiomatic but may not perform better!

14:46 clojurebot: #error{:cause "Unable to resolve symbol: primes in this context", :via [{:type clojure.lang.Compiler$CompilerException, :message "java.lang.RuntimeException: Unable to resolve symbol: primes in this context, compiling:(NO_SOURCE_PATH:0:0)", :at [clojure.lang.Compiler analyze "Compiler.java" 6543]} {:type java.lang.RuntimeException, :message "Unable to resolve symbol: primes in this context", :at [...

14:46 TEttinger: right, shouldn't use the , when I haven't defined primes :)

14:47 saik0: TEttinger hust tried it here and it's not terminating

14:48 TEttinger: ah ok

14:48 I thought concat was lazy...

14:48 oh probably not with seqs

14:48 (doc concat)

14:49 clojurebot: "([] [x] [x y] [x y & zs]); Returns a lazy seq representing the concatenation of the elements in the supplied colls."

14:49 TEttinger: ,(take 500 (concat [0 0 0 0] (range)))

14:49 clojurebot: (0 0 0 0 0 ...)

14:49 TEttinger: &(take 500 (concat [0 0 0 0] (range)))

14:49 lazybot: ⇒ (0 0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 8... https://www.refheap.com/99740

14:49 TEttinger: well it is lazy....

14:50 saik0: TEttinger, ah, (conj [2 3 5 7] ... was still executing. oops!

14:52 clyfe: Core async pipline should return the "to" channel, to make it threading friendly

14:54 (->> (to-chan [1 2 3]) (pipeline 3 (chan 3) reticulate))

14:55 I wish they'd a t least open the github issue tracker

15:00 virmundi: can when-let be used with keys destructuring?

15:00 (when-let [{:keys [username password]} conn]

15:00 {:users [{:username username, :password password}]})

15:01 (def conn {:type :simple, :url http://arangodb:8529})

15:09 TEttinger: ,(def conn {:username "Bill", :password "Excellent!"})

15:09 clojurebot: #'sandbox/conn

15:10 TEttinger: ,(when-let [{:keys [username password]} conn] {:users [{:username username, :password password}]})

15:10 clojurebot: {:users [{:username "Bill", :password "Excellent!"}]}

15:10 TEttinger: virmundi: yes

15:16 amalloy: virmundi: yes, but it's not pattern-matching. it just tests whether conn is truthy; it doesn't check whether username or password exist before deciding whether to bind them and evaluate the body

16:19 kaiyin: could anyone help with this?

16:19 http://stackoverflow.com/questions/29708625/circular-definition-in-clojure

16:22 lodin: Twice now I have been bitten by (defrecord R [] P ...) not being the same as (defrecord R []) (extend-type R P ...) with regards to (isa? R P).

16:23 mavbozo: ,(take 7 (cycle [0 1 2]))

16:23 clojurebot: (0 1 2 0 1 ...)

16:24 mavbozo: kaiyin, ^ would be enough for that use case

16:25 kaiyin: mavbozo: yeah, but I am really looking for a general circular definition, i find it very cool.

16:25 lodin: kaiyin: You can use declare.

16:25 kaiyin: lodin: Could you elaborate?

16:26 lodin: What's the bot command for doc refs?

16:26 kaiyin: ,(doc declare)

16:26 clojurebot: "([& names]); defs the supplied var names with no bindings, useful for making forward declarations."

16:26 lodin: kaiyin: :-)

16:26 kaiyin: ok, I see what you mean now. :)

16:26 mavbozo: ,(declare f1 f2 f3)

16:26 clojurebot: #'sandbox/f3

16:26 mavbozo: kaiyin, works on my repl

16:27 kaiyin: cool!

16:28 darthdeus: hey guys, i'm playing around with channels, and it seems I managed to deadlock myself ... is there a way to see where that is happening?

16:28 kaiyin: indeed, very nice!

16:28 darthdeus: or maybe a different question would make more sense ... if I'm putting stuff on two separate channels, and then waiting on both to do assertions in tests, can I assert asynchronously?

16:41 noncom|2: what library currently is adviced to add some automation to the program, like execute some action after some time?

17:00 bcm`: I wrote a 10 line, one-off function for turning a list of maps into a csv-string. It doesn't belong in a library. Is there a useful place I can put it?

17:02 amalloy: bcm`: if it's useful and reusable, why wouldn't you put it in a library? alternatively you can print it out and tape it to your monitor; where else are you imagining putting it?

17:02 noonian: bcm`: if you want to use it in other projects probably best to make it a lib

17:02 amalloy: that said, turning a list of maps into csv is a problem that's been solved many times before. you could just use one of the existing libraries

17:03 pbx: bcm`, did you mean useful to yourself or to others?

17:08 profil: is there a similiar function to for which can be exited early and throw away the old sequence?

17:09 Or should I instead check the result from for and disregard the result in case my test holds?

17:11 noonian: profil: what do you want to return? I'm not sure what you mean when you say 'exit early' and 'throw away the old sequence'

17:12 justin_smith: profil: for is lazy, just use take-while or whatever and don't realize the part you don't want

17:13 profil: noonian: I am writing a grid neighbouring function which should return valid (walkable) neighbours. The goal node is of a type which is not walkable unless that is the goal, which means that I need to check for the goal node, and in that case I dont want any other neighbour

17:13 justin_smith: profil: if you want to explicitly cut things short early within sequence generation there is also the reduce / reduced combo, or self-calls inside lazy-seq

17:14 profil: see also the :while key in the extended args to for

17:17 noonian: yeah it sounds like reduce might be a better bet since it gives you more flexibility in terms of the type of thing you are building up and returning

17:21 profil: ah, I didnt know about the reduced function

17:22 jonathanj: ztellman: yay for aleph 0.4.0 (and all the other awesome libraries), great stuff

17:24 profil: ztellman: I have been looking for you! When using manifolds periodically function, my function is run 2 times after the stream is closed. Why is this?

17:28 mikerod: This line of clojure.lang.Compiler surprised me https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Compiler.java#L6784-L6787

17:28 In particular, ` ((Symbol) RT.first(form)).name.startsWith("def")))`

17:28 if a symbol starts with the prefix "def" it goes down another path

17:28 of analysis

17:29 I'm sure that may make sense for a typical usage of "def", but what if an external lib just happened to start with "def"

17:30 It is not clear to me how the analysis semantics changes when this path is bypassed. I see that it goes into a C.EVAL context instead of C.EXPRESSION and also goes downa possibly new path not the fn wrapped FnExpr route of other collections

17:31 I'm just curious of starting a function name with "def" could potentially lead to weird compiler issues. Like "(definitely-not-a-def :blah)"

17:32 Bronsa: mikerod: I've tried for quite some time to find a snippet that would crash because of that line, I'm now 95% sure it's harmless

17:32 mikerod: Bronsa: I'm glad I'm not alone in thinking that line looked suspicious

17:33 I haven't gone far tracking down the alternative path though. Glad to know it hasn't broke anything in your experiments though.

17:38 profil: noonian, justin_smith: thanks guys, I solved it using reduce and reduced, much nicer now than before =)

17:41 campeterson: Hey all, is there a better alternative to having a try/catch inside a ‘let’ binding?

17:41 61 (let [tx-result

17:41 62 (try

17:41 63 (/ 1 0)

17:41 64 (catch Exception e (str "caught exception: " (.getMessage e))))]

17:41 65 tx-result)

17:50 lodin: If I have (defprotocol P) (defrecord R [] P) then I can use (defmulti m type) (defmethod m (:on-interface P) [x] :P) to provide a default implementation, so (= :P (m (->R))), for records that implement P, but if I use (extend-type R P) instead I cannot. Any way around that?

17:53 tomjack: the fact that that works at all is an implementation detail you should not rely on

17:53 amalloy: lodin: don't think of protocols as types, because they're not? i don't know a way around it, because it is just a weird thing to be doing

17:53 yes, exactly what tomjack is saying also

17:54 tomjack: need to 'get around' the whole thing, and figure out a different way to express what you want, I guess

17:55 and/or want something different :)

17:58 mikerod: tomjack: are you saying :on-interface is a impl detail or the fact that inline protocol implementors implement an actual interface?

17:59 kaiyin: I have a sequence like this: [1, 2, 3, 4, 1, 2, 3 4, 1, 2, 3, 4, ...], how do i take out the repeated segment [1, 2, 3, 4]?

17:59 mikerod: Perhaps it is not always great, but I've trusted an inline implementation of a protocol to give me a class that is a subtype of the interface for the protocol

17:59 lodin: kaiyin: Are you doing 4clojure exercises or something? :-)

18:00 kaiyin: lodin: no, I am reading a number theory book and trying to implement some of the theorems in clojure. :)

18:00 mikerod: I guess if you want an interface to implement, use definterface instead?

18:00 or write it in Java

18:00 mgaare_: kaiyin: does the order need to remain the same?

18:01 amalloy: mikerod: yes, the generated interface is an implementation detail

18:01 :on-interface even more so

18:01 kaiyin: mgaare_: no, in this case that's not essential. But I would like to know a way to keep the order, too.

18:01 mgaare_: kaiyin: simplest thing, just look at clojure.core/set

18:02 ztellman: profil: hey, sorry, just saw this

18:02 TEttinger: ,(#(take-while (set (distinct %)) %) (cycle [1 2 3 4]))

18:02 clojurebot: #error{:cause "Java heap space", :via [{:type java.lang.OutOfMemoryError, :message "Java heap space", :at [clojure.lang.PersistentVector$ChunkedSeq next "PersistentVector.java" 414]}], :trace [[clojure.lang.PersistentVector$ChunkedSeq next "PersistentVector.java" 414] [clojure.lang.Cycle current "Cycle.java" 45] [clojure.lang.Cycle first "Cycle.java" 52] [clojure.lang.RT nthFrom "RT.java" 928] [cl...

18:02 TEttinger: heh

18:02 amalloy: mgaare_: i don't think that is likely to produce a useful answer

18:02 kaiyin: mgaare_: I am not sure, the sequence is lazy and infinite.

18:02 mgaare_: oh, I missed the ellipsis

18:02 right you are

18:02 ztellman: profil: basically, the way a source knows the sink it's feeding into is closed is by trying to write into it

18:03 amalloy: even if it were finite, sets don't have ordering guarantees

18:03 ztellman: and each layer of indirection will add additional "lag" between the sink you have and the original source

18:03 TEttinger: the other thing is that the sequence could be 1, 2, 3, 4 repeated 99999 times and then a 5 in there, once

18:03 mgaare_: yes, I was going after the "ordering is not essential" part

18:04 ztellman: profil: is this causing some issues for you? I could potentially make it more eager, but this is the level of guarantee that you get elsewhere

18:04 amalloy: kaiyin: actually "take out the repeated segment" is a very vague question. i don't understand what you want to do

18:06 profil: ztellman: what do you mean, "each layer of indirection"? I solved this by doing "#(when-not (s/closed? s) ..." so no worries :)

18:06 kaiyin: amalloy: TEttinger: the first element is guaranteed to be repeated, and after that periodicity is also guaranteed.

18:06 TEttinger: what about 11100101010011011110010101001101

18:06 kaiyin: i.e. if you have [1, 2, 3, 4, 1, ...], then the next element must be 2, and then 3, and so on.

18:06 amalloy: kaiyin: but you still can't know how long the period is. suppose i give you [1 2 1 2 1 2 ...]

18:07 mikerod: amalloy: that's interesting. News to me I suppose. I tend to not use them for their types anyways though.

18:07 kaiyin: amalloy: in that case, i need to take out [1, 2]

18:07 amalloy: so you're saying that there can be no repetition of elements inside the repeated section? like [1 1 2 1 1 2 1 1 2] is not possible

18:07 mikerod: since, like you guys suggested - its not the purpose

18:07 tomjack: mikerod: consider e.g. cljs

18:07 kaiyin: amalloy: no, that's not possible.

18:07 amalloy: okay, in that case it is a soluble, indeed easy, problem

18:07 ztellman: profil: oh, nm, I had misremembered the implementation, this is just how I'm interacting with the ScheduledThreadPoolExecutor

18:08 profil: I should be doing that check myself

18:08 kaiyin: if you see [1, 1...], then you can be sure you have [1, 1, 1, 1...]

18:08 ztellman: but that'll have to go into 0.1.1 :)

18:08 amalloy: so your problem isn't actually about repeating sections at all

18:08 mikerod: tomjack: yeah, that came to mind

18:08 tomjack: not that everything jvm-specific is an implementation detail, but...

18:08 amalloy: it's about finding the prefix of a sequence up until you see its first item again

18:09 kaiyin: amalloy: i think i know how to do it now. ;)

18:09 TEttinger: ,(reduce #(if (contains? %1 %2) (reduced %1) (conj %1 %2)) [] (cycle [1 2 3 4]))

18:09 clojurebot: [1 2 3 4]

18:09 amalloy: (fn [coll] (let [[x & xs]] (cons x (take-while #(not= % x) xs))))

18:09 (fn [[x & xs]] (cons x (take-while #(not= % x) xs)))

18:09 tomjack: ,(reduce #(if (contains? %1 %2) (reduced %1) (conj %1 %2)) [] (cycle [10 11 12]))

18:09 clojurebot: [10 11 12 10 11 ...]

18:10 tomjack: (bad use of contains?)

18:10 TEttinger: yep

18:10 amalloy: tomjack: yes

18:10 TEttinger: (inc amalloy)

18:10 lazybot: ⇒ 258

18:11 profil: ztellman: ahh okay, great!

18:11 ztellman: profil: thanks for the heads up, feel free to post in the aleph mailing list or email me directly if I'm not on here

18:12 profil: ztellman: should have done that a few weeks ago :) but I heard that you usually hang out here so I waited for you to pop up

18:13 ztellman: profil: I'm on here when I don't forget to open my IRC client, which is usually the case

18:13 profil: oh get a persistent shell you!

18:14 otherwise, great work with aleph and manifold

18:19 kaiyin: does Math/pow coerce an integer into a double?

18:20 ,(Math/pow 2 3)

18:20 clojurebot: 8.0

18:20 kaiyin: how to avoid that?

18:22 lodin: kaiyin: Don't know if it is good, but you could do (defn pow [x n] (apply * (repeat n x))).

18:22 kaiyin: ok, there is no existing implementation of integer power?

18:23 lodin: kaiyin: Maybe, don't know.

18:23 tomjack: one is (.pow (biginteger 2) 3)

18:23 kaiyin: ok

18:24 tomjack: :/

18:24 amalloy: integer power is easy, though. (apply * (repeat n x))

18:25 kaiyin: yeah.

18:25 lodin: amalloy: I got distracted before... I thought defrecord implementing an interface was a feature. Any idea why this behavior is included, and defrecord not expand to a extend-type?

18:26 amalloy: performance

18:26 interfaces are way faster

19:18 lodin: (inc amalloy)

19:18 lazybot: ⇒ 259

20:22 hiredman: is there a jira issue for not being able to set! deftype fields in fns that are created in a scope where you can set! the fields?

20:23 ztellman: hiredman: I think that's firmly in CinC territory as far as the roadmap goes

20:23 at least it was the last time I raised it

20:25 hiredman: I am looking to link to such an issue because http://dev.clojure.org/jira/browse/CLJ-1708 is a combination of that and the issues I already linked to in it

21:05 amalloy: hiredman: what would be the solution to that? create a synthetic setter method like javac does for inner class shenanigans?

21:13 lodin: Am I the only one that intuitively want to write {:a a} in map destructuring instead of {a :a}?

21:14 hiredman: amalloy: I dunno

21:17 scottj: lodin: I don't think you are. I made a data reader tag to do that. so I can right (let [#uteal/invert {:a a} map] ..) and it works

21:17 dnolen: lodin: takes some getting used to, but it can't be that way because of :keys & :or etc.

21:17 scottj: lodin: what I like about that format is you can take a return map from an api example and remove the parts you're not interested and come up with variable names for the parts you are interested in and it just works

21:18 lodin: dnolen: Yes, I realize that's the issue.

21:18 dnolen: lodin: if you're not renaming, there's not reason to prefer that form over :keys anyway

21:23 lodin: dnolen: I think I would be fine with {a b} be what is now {:keys [a b]} and use {[:a a] [:b b]} for what is now {a :a b :b} (so {a b} would actually expand to {[:a a] [:b b]}).

21:24 Hmm. Maybe that would be confusing when you nest destructuring.

21:24 amalloy: yes. you can't do that because of nesting

21:24 lodin: amalloy: You can nest, like {[:a [x y]]} if :a contains a tuple.

21:27 When I wrote {a b} is meant a and b to be symbols; having {[...]} wouldn't make sense since the map isn't ordered.

21:27 s/is/I/

21:28 amalloy: lodin: you know none of this is going to change, right? you can dream aloud if it's fun for you, but there is no way destructuring is going to change

21:28 lodin: The reason I'm asking is because I'm writing a macro. :-)

21:29 amalloy: also, {[:a a]} is not even a thing you can legally write, because it's a map with a key and no value

21:29 the reader will reject it before you get to macroexpansion

21:29 lodin: It's for a special case, so I'm not trying to replace regular let destructuring, btw.

21:30 amalloy: Ah, that's a good point. I don't have the outer {} though so I'm fine for my application.

21:31 I guess the takeaway from the comments above is that it is probably fine to deviate from let syntax for my macro.

22:13 einfach: hi

22:14 I am a professional clojure developer and looking for remote work, however small.

22:32 iamjarvo: (defn text->my-method [] ) saw this in code earlier. can someone please explain whats happening? difficult to google for

22:35 badfish129: Hi, why can't I do this, (defn testfn [] (println "hello")), (def fns `(testfn otherfn)), ((first fns)) => this yields an ArityException...

22:39 iamjarvo: badfish129 testfn doesn't accept arguments as far as i can tell

22:40 badfish129: iamjarvo: yeah I was just trying to make it print hello, this works though (def fns [testfn otherfn]), ((first fns))

22:41 nuwanda__: badfish129: you need to resolve the symbol

22:41 the error it gives you is not that you're passing a wrong arity to the function

22:41 it's that you're trying to call a symbol with arity 0

22:42 badfish129: so I have to unquote it? sorry for these stupid questions I'm a complete noob

22:42 nuwanda__: ((resolve(first fns))), something like this should work

22:47 badfish129: cool thanks!

22:50 nuwanda__: np :)

22:52 badfish129: what if I'm doing this with records, I have (defprotocol P (testfn [this])), (defrecord A [] P (testfn [this] 1)), (def types [A]), (def inst (->(first types)), (.testfn inst) => I get a IllegalArgumentException because the record isn't actually being instantiated and its trying to find the method testfn on the class java.lang.Class

22:55 do i have to store the constructors themselves in the list (def types [->A, ->B]) and then call them?

22:56 nuwanda__: don't think I can be of much use here, I have no experience with records, other than reading about it when I first started using clojure

22:57 noonian: badfish129: what are you trying to do? sorry i missed the beginning of your question

22:58 badfish129: noonlan: the bigger picture is I have a protocol Parser, and a bunch of records that implement the protocol for different types of parsers, LetterParser, EmailParser etc.

22:58 noonian: I want to write a function that will take in an input, choose the appropriate parser, instantiate it, and then call the parse method on it

23:00 noonian: yeah a record contructor is just a function, you can stick it in a vector

23:00 badfish129: noonian: cool, do you think that would be the cleanest way?

23:02 noonian: if you already have a function that takes the input and figures out what type it is 'letter', 'email' etc. you might use multimethods to do the dispatch

23:03 but something like a dispatch table is perfectly fine also

23:03 badfish129: noonian: I considered the multi method approach, but then I would have to write a new method everytime I add a parser, this way I'll just have to add the constructor to the list

23:04 noonian, nuwanda_: thanks for the help!

23:04 noonian: badfish129: true, but multimethods have the advantage that its an open system, so you could add another parser from another project without altering your parser project

23:06 also, the map version of a record constructor is often easier to use so you don't have to worry about the order of the fields

23:06 map->A instead of ->A

Logging service provided by n01se.net