#clojure logs

2015-04-17

00:06RaynesTEttinger: I'm always around, just occasionally too far gone to respond.
00:06RaynesBut I always get back to ya
00:06RaynesI'm good like that.
00:59RaynesWow, the number of people in here has grown since I last poked around.
03:17WickedShellI 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
03:18WickedShellif anyone can help point a new person on there way...
03:18justin_smithWickedShell: Buttton
03:18WickedShelljustin_smith, huh?
03:19justin_smith,(= 'Buttton 'Button)
03:19clojurebotfalse
03:19WickedShelloh ffs... thank you
03:19justin_smithnp
03:19WickedShellima go hide in a corner now, or maybe walk away from the keyboard...
03:19justin_smithhaha
03:19mavbozoyou'd better take a break
03:20justin_smith,(symbol (str "Bu" (repeat (rand-int 8) \t) "on"))
03:20clojurebotBuclojure.lang.PersistentList$EmptyList@1on
03:20brianpWinscreated a project with lein, and started the repl but I have no idea how to intereact with my code
03:21justin_smith,(symbol (str "Bu" (apply str (repeat (rand-int 8) \t)) "on"))
03:21clojurebotButtttton
03:21mavbozo~Button
03:21clojurebotI don't understand.
03:21mavbozo~Buttton
03:21clojurebotTitim gan éirí ort.
03:21justin_smithbrianpWins: you can use require from the repl (require 'some.ns :reload)
03:21justin_smithWickedShell: sorry
03:22WickedShelljustin_smith, s'all good :P
03:22brianpWinsjustin_smith: will try
03:22justin_smithbrianpWins: 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.
03:23brianpWinsjustin_smith: ah-hah! got it
03:25justin_smithalso, you can use :reload-all instead of :reload, if you want recursive reloading
03:25justin_smithmavbozo: it would do the same thing the clojure code did - tell him the symbol was not bound
03:26justin_smithmavbozo: I prefer to call it the banananana problem
03:27justin_smith,(apply str "ba" (repeat (rand-int 8) "na"))
03:27clojurebot"bananananananana"
03:28justin_smithtoo much fruit?
03:29mavbozojustin_smith, now my throat gets hurt
03:31mavbozomaybe a old IDE feature will point out the banananana problem, like what eclipse does
03:31justin_smithor eastwood could
03:32justin_smithbut the language will definitely tell you it's a problem (for vars) - I think eastwood can also point that issue out for keywords
03:33mavbozomaybe intellij's cursive has a feature for the repl where if I type a unbound symbol in the repl, the those symbol gets highlighted
03:34cflemingmavbozo: It does indeed - both in the REPL editor and the main one
03:35mavbozo(inc Cursive)
03:35lazybot⇒ 2
03:42sm0keso if i serialize a clojure function and deserialize and call it later i get unbound fn err
03:42sm0keis there a way to solve this in a non ugly way
03:42justin_smithhow are you serializing?
03:42sm0keJust serialize java/kryo anything
03:43justin_smithsm0ke: there's a serializable function lib
03:43sm0keyes, i want to avoid exactly that
03:43justin_smithhttps://github.com/technomancy/serializable-fn
03:43justin_smithyou want to avoid serializable functions?
03:43sm0kethat library
03:43justin_smithbecause they aren't serializable out of the box
03:44sm0keyes they are
03:44sm0kefunctions extend serializable
03:44justin_smithI mean not in a way that is in any way useful
03:44sm0kewhat do you mean?
03:45justin_smiththe 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.
03:46sm0kei am able to deserialize and call it just fine, if i hardcode the (require...) both remotely and locally
03:46sm0keit even closes over local!
03:47justin_smithsm0ke: honestly it's news to me that it would work at all, but congrats on making it kind of work I guess
03:48sm0kei did nothing, it just works!
03:48sm0kei am not bullshitting you
03:48slipsetThe magic of clojure. It just works :)
03:48sm0kewait a sec, ill give you a form
03:48slipsetThe problem with Java, it just doesn't
03:49sm0kejustin_smith: i think it works oob because clojure compiles functions and closures to class and objects
03:51sm0kejustin_smith: here try this (do (import 'org.apache.commons.lang.SerializationUtils) (def a 10) ((SerializationUtils/deserialize (SerializationUtils/serialize (partial + a))) 10))
03:52brianpWinsI 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 [<<]])
03:53sm0kebrianpWins: i think you want :only
03:54brianpWinsIt can’t find the calss at all though: Exception in thread "main" java.lang.ClassNotFoundException: clojure.core.incubator
03:54sm0keeh sorry even :refer should be fine
03:54justin_smithsm0ke: and if you serialized to a file, and then exited your repl, and reloaded from the file, would the deserialized partial work?
03:55justin_smithreloaded from a fresh repl, of course
03:55sm0kejustin_smith: yep, given you have all the classes and namespaces used while serializing
03:55justin_smithif I have all the classes and namespaces, why not just use a clojure readable form?
03:56brianpWinssm0ke: so is that the right ns to try and require?
03:56sm0kefor the given example it should just work as there is nothing outside of core
03:56justin_smithbrianpWins: :require only works inside an ns form
03:57justin_smithyou need require, and you need to quote the vector, outside an ns form
03:57sm0ketry with (print (seq (SerializationUtils/serialize (partial + a))))
03:57justin_smithI guess that's one definition of readable
03:58brianpWinsjustin_smith: that’s some terminology I do not understand (am noob).
03:58brianpWins(ns factorial-digit-sum.core \n :require [clojure.core.incubator :refer [<<]]))
03:58justin_smithinside (ns ...) you can do (:require [clojure.core.incubator :refer [<<]])
03:58justin_smithoutside (ns ...) you need (require '[clojure.core.incubator :refer [<<]])
03:59brianpWinsException in thread "main" java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Keyword
03:59sm0kejustin_smith: just checked works!
03:59sm0keNow the only problem with this is, if i was using something like (partial myfn 10).. then myfn's namespace wont be automatically require'd
04:00justin_smithbrianpWins: notice that in that ns form, you have no paren around :require
04:00brianpWinsahhhh
04:00brianpWinsyeah i just caught that
04:00brianpWinsokay loading works
04:00brianpWinsbut << is still not recognixed
04:00brianpWinsException in thread "main" java.lang.IllegalAccessError: << does not exist,
04:00mavbozobrianpWins, no var inside that namespace
04:00mavbozo{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?}
04:01mavbozohere's what's public inside that namespace
04:01brianpWinsi don’t know what that means
04:02justin_smithsm0ke: 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.
04:02mavbozothey are public vars from clojure.core.incubator namespace
04:02nuwanda_brianpWins: it's in strint, not in the main incubator ns
04:02TEttingerwhat does << do?
04:02brianpWinsohhhhh i read string was deprecated and to use incubator directly =/
04:02brianpWinsstrint*
04:03brianpWinsit’s for string interpolation
04:03sm0ke*there are no accidents*
04:03mavbozoTEttinger, cemerick wrote about that here http://cemerick.com/2009/12/04/string-interpolation-in-clojure/
04:03justin_smithsm0ke: clojure is full of things that work accidentally
04:03justin_smith,(:+ 0 1)
04:03clojurebot1
04:04justin_smithworks great, until your first arg isn't 0, or you have more than two args
04:04TEttingerit's in clojure.core.strint
04:04justin_smith,(:or nil :OK)
04:04clojurebot:OK
04:04justin_smithsimilar
04:04TEttingerso you need...
04:04TEttinger(require '[clojure.core.strint :refer [<<]])
04:05TEttingeror the equivalent for :require in ns
04:05sm0ke,(keyword "a b c")
04:05clojurebot:a b c
04:05justin_smithright!
04:05TEttinger,(:* 1 10)
04:05clojurebot10
04:05TEttinger,(:* 0 10)
04:05clojurebot10
04:05TEttingereh?
04:06justin_smithheh
04:06sm0kethanks for noodling
04:06mavbozo,((keyword ":a ok") 1 10)
04:06clojurebot10
04:06TEttingerso it's looking up the key :* in a number, obviously not finding it, and getting the defualt?
04:06justin_smithTEttinger: right
04:06justin_smithTEttinger: more realistic is the :or
04:07brianpWinsso how do I find what version of string to make a dependency
04:07justin_smithit even works if the first arg is always falsey
04:07brianpWinsstrint*
04:07justin_smithbrianpWins: you could check clojars to see what is current if it's available there
04:07TEttingerbrianpWins: https://github.com/clojure/core.incubator#installation
04:07TEttingerinstructions are there
04:07TEttingerstrint is in the same jar as incubator
04:08brianpWinsthat’s not very straight forward to a noob
04:08TEttingeroh
04:08justin_smithbrianpWins: yes, packages don't directly map to namespaces and neither maps directly to jars
04:08TEttingeryou should absolutely be using lein, first
04:08brianpWinsam using lein
04:09mavbozobrianpWins, it's a "Proving ground for proposed new core fns".
04:09TEttingerthen you would add that dependency into your project.clj file. it goes in a vector that's the value for the key :dependencies
04:09brianpWinsThanks for everyones patience with my noob questions
04:10TEttingeryou should take a look at a detailed guide like braveclojure
04:10TEttinger$google braveclojure
04:10lazybot[Learn to Program the World's Most Bodacious Language with ...] http://www.braveclojure.com/
04:10TEttingerha
04:10TEttingerthat's it
04:10brianpWinswill do
04:10brianpWinsI breezed through a couple chapters of joy of closure
04:10brianpWinsclojure
04:11brianpWinsand took a stab at an eulerproblem last night,
04:11TEttingerapparently brave clojure is one of the better free resources for practical clojure learning
04:11brianpWinsso just getting the hang of things
04:11mavbozobrianpWins, 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
04:12TEttingeryeah 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
04:13TEttingerthat is my favorite thing in clojure. how outrageously tiny some code can be
04:14TEttingercertain 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)
04:14TEttinger"recently", transients are recent for me since I didn't use them when they came out :)
04:15TEttingerreducers are another speeder-upper
04:15brianpWinsyeah that’s what im liking so far
04:15brianpWinsreletivley complex equations in a couple lines that are actually readable
04:15TEttingerlazy sequence stuff can be hard at first, but there are some times when using an infinite sequence is really convenient and clear
04:16brianpWinsmy distaste for haskell was complexitiy in a couple lines with to many optional syntaxes- completely un readable
04:16TEttingeryep
04:16TEttingerhaskell can be clear, but it needs a fair amount of docs in the code to be able to read easily
04:21TEttingerone 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.
04:23TEttingerreify and proxy are very powerful when you NEED to interoperate with java that expects specific stuff
04:25TEttingerthis example would be, heh, a lot longer in java http://clojuredocs.org/clojure.core/proxy#example-542692cdc026201cdc326d5c
04:25TEttingermaybe not java 8
04:26TEttingerthat 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
04:26slipsetTEttinger: should of course been done with core.async and a channel :)
04:26clojurebotGabh mo leithscéal?
04:28slipsetclojurebot: http://www.urbandictionary.com/define.php?term=gabh+mo+leithsc%C3%A9al
04:28clojurebotNo entiendo
04:29justin_smithwell that website is just rude
04:35sm0keyou want honest opinions on clojure go to #scala, all views here would be biased i guess
04:36TEttingerif you want my honest opinion on Scala, http://nurkiewicz.github.io/talks/2014/scalar/img/list-scala.png
04:37TEttingernot sure how this got here https://gist.github.com/anonymous/1406238
04:38sm0keis it by steve yegge?
04:39TEttingernot 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
04:40sm0keah its about the yammer switch from scala
04:40TEttingerit's rather well-written and basically syncs up perfectly with my experience
04:41TEttingerI also left #scala because the community was unhelpful more often than they were helpful
04:41justin_smithin what way?
04:42sm0kethey say the same about #clojure
04:42sm0kesomeone even started a clojure beginner channel
04:42TEttingerthere 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
04:42justin_smithsm0ke: I don't think that was meant to reflect the helpfulness of this channel
04:43justin_smithTEttinger: haha, like bitemyapp / callen was here?
04:43TEttingerkinda, but even more vocal
04:43TEttingerhe was a former language contributor
04:43TEttingerhe apparently wrote the infamous kleene star thing
04:44sm0kewhats that?
04:45TEttingerah, kleisli
04:45TEttingerhttp://scalaz.github.io/scalaz/scalaz-2.9.0-1-6.0.1/doc.sxr/scalaz/Kleisli.scala.html
04:45TEttingervariable naming like that apparently had a good reason
04:45TEttingerbut it's still silly as hell
04:46TEttinger def ☆[M[_], A, B](f: A => M[B]): Kleisli[M, A, B] = kleisli(f)
04:46justin_smithTEttinger: my version would have more snowmen, hot beverages, and airplanes
04:46TEttingerhaha
04:46sm0kezomg that code "looks" so awesome
04:46TEttingerand no docs.
04:47sm0keaesthetically scala is best
04:47sm0keclojure looks like noodles on a plate
04:47justin_smith☃☕✈
04:47TEttingerdef traverse[F[_], AA <: A](f: F[AA])(implicit a: Applicative[M], t: Traverse[F]): M[F[B]] = f ↦ (Kleisli.this(_))
04:49TEttingerI have really found the same thing the yammer guy found from writing in Scala, then writing in other languages
04:49justin_smith?
04:50justin_smithoh, that anonymous gist above
04:50sm0keTEttinger: you mean to say every language is same
04:51TEttingercurrently 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
04:51TEttingerthe scala's a fair bit more complex
04:51TEttingerit also likely performs poorly because it uses scala's iterator-based for
04:52sm0kei have seen people are very religious about languages and would defend every shit feature in their language
04:52TEttinger(the java is index-based, the problem both solve is a mix of graph-like pathfinding code and array storage)
04:52mnngfltgsm0ke, pasta is tasty AND beautiful
04:53TEttingertechnically all of the versions of this code I have written are ports of some very concise, rather slow clojure code
04:54bjasm0ke, once you achieve a certain understanding of an implementation, you can usually justify any particular feature
04:54sm0keI honestly would code in visual foxpro if someone gives me more money
04:54bjain my experience, it's pretty rare to find a language feature that has absolutely no justification
04:55slipsetI remember in about 1999/2000, one was adviced as to not create too many objects in Java, since creating objects was costly/slow
04:55sm0keslipset: ha
04:55sm0keis there a reference for this?
04:55bjareduce in python is pretty close
04:55TEttingerit'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
04:56slipsetsm0ke: nope, it's only my vague recollection of that time
04:56justin_smithslipset: it's still solid advice for super-tight loops (see eg. the disruptor)
04:56slipsethttp://www.javaworld.com/article/2075062/build-ci-sdlc/design-for-performance--part-2--reduce-object-creation.html
04:57jonasenclojure.java.jdbc question: Is there a way to *not* keywordize the keys in result sets from query?
04:57TEttingeranyway, I'll be happy to use that java pathfinding code from clojure now
04:57slipsetjustin_smith: probably, but the problem is that the average programmers take the advice for the super specific case and applies it everywhere.
04:57justin_smithslipset: yes, that is a problem
04:57justin_smithpremature optimization and all that
04:58slipsetMost programmers do not share the problems of Facebook/google/twitter
04:58slipsetMost programmers work on applications which have no traffic
04:58justin_smithslipset: hell, those folks don't even need disruptor performance
04:58slipsetMost programmers have no data
04:59justin_smithslipset: it's specifically hft
04:59justin_smithwhere being a few ms slower loses you millions of dollars
04:59slipsetYes, but most of us do not work in hft
04:59slipsetallthough sometimes I wish I did.
04:59justin_smithheh
04:59bjajonasen, it seems to be hardcoded to map keyword
04:59slipsetIt would be nice working on code which needed to run fast
04:59justin_smiththey have interesting performance problems
05:00justin_smithslipset: see also realtime dsp
05:00sm0keslipset: make games
05:00justin_smithwhich can be fun for hobby stuff (software synths, real time visualization)
05:00justin_smithgetting your latencies low can be interesting
05:00sm0keslipset: btw, what do you code, which doesnt need to run fast?
05:00bjajonasen, you could ask for the resultset as arrays instead of maps
05:00slipsetstupid crud apps for inhouse use
05:01jonasenbja: ok. clojure.walk/stringify-keys it is then. Kinda silly to first keywordize and then stringify
05:01justin_smithsm0ke: there's a difference between needing to be fast, and needing your latencies to be constrained
05:01jonasenbja: I'll look into that also, thanks!
05:01slipsetI guess they need to be fast, but the problem with the fastness is very seldom in the code pr se.
05:01bjajonasen, it might be worthwhile to implement your own result-set-seq instead
05:01justin_smitheg. there are algorithms that are useless for low latency stuff that would have higher throughput, but they break your latency constraints
05:01bjaso you don't incur the cost of transforming the keys twice
05:01slipsetOften times a well placed index speeds things up
05:02slipsetOr removing some network calls
05:02sm0kecaching
05:02sm0kethe whole youtube still runs on python and mysql
05:02justin_smithalso, 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"
05:03slipsetI guess my day job revolves around these rules: http://users.ece.utexas.edu/~adnan/pike.html
05:03sm0keslow/fast is a infrastructure problem rather than programming
05:03sm0kefor most practial applications
05:03slipset(inc sm0ke)
05:03lazybot⇒ 10
05:03sm0keheh
05:04bjasm0ke, I actually wonder what percentage of what we experience as youtube isn't a complex network of services doing crap in the background
05:04slipsetmy 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
05:05mpenetI actually know ppl using clj in hft context
05:05bjasure, the frontend is python and reading from mysql, but what about those recommendations and such
05:05justin_smithclojure breaks rules 3 and 4 frequently. Though the new smaller collections from ztellman help on that front.
05:05mpenetnot everywhere tho (obviously)
05:06slipsetjustin_smith: I guess these rules apply to application devs, not to library/language devs
05:06sm0kempenet: as i said use clojure and have you hft datacenter isp near the trade center, or use C and operate from africa
05:06sm0kehehe
05:06justin_smithslipset: the fact that clojure gets faster with ztellman's less complex small collection impl contraindicates that idea
05:06mpenetI guess it depends what you use clojure for
05:06slipsetsm0ke: you need to have your datacenter isp _in_ the trade center
05:07sm0kebetter
05:08slipsetjustin_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?
05:08slipsetfrom the observation that a lot of collections in clojure are rather small?
05:09mpenetslipset: http://dev.clojure.org/jira/browse/CLJ-1517
05:09justin_smithslipset: right. And in practice most collections in clojure are small. And they get a perf boost from a simpler impl.
05:09justin_smitherr, what you said while I was still typing :)
05:09sm0keugh it got pushed to 1.8?
05:10justin_smithit's a big change
05:10sm0keshould be available by 2016 i guess then
05:10slipsetjustin_smith:but one could argue that the collections will become even more complex, since they handle small and large collections differently
05:10justin_smithI hope
05:12justin_smithslipset: changing size becomes more complex, the impl behind the coll of a specific fixed size becomes simpler
05:12justin_smithif I understand correctly
05:12slipset:)
05:32bjaany 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.
05:37sm0kebja: that doesnt make sense to me
05:37sm0ke:provided is not a keyword for lein i think
05:37sm0keyou want a :foo profile and a :provided profile
05:39sm0kei mean not a keyword inside a profile
05:39bjaI know that can work. but I specifically want different things provided in different profiles
05:40bjaafter 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
05:40sm0keyes, as i said it not recognized inside a profile
05:41sm0kewhy dont you put them in a global :provided profile?
05:42bjabecause different profiles have different things provided
05:42bjain particular, I'm building against multiple storm versions
05:42bjaand storm stupidly includes AOT'd versions of certain important clojure libraries in their distribution
05:43bjaso I have to deal with different versions of clj-time
05:43bjaalso, different clojure versions
05:45bjaso 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"]]}
05:45bjaI think the solution is just to patch leiningen to merge the :provided key that I want
05:47bjaactually, https://github.com/technomancy/leiningen/blob/master/test_projects/sample-profile-meta/project.clj#L14
05:47bjait 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
05:47bjawhich is acceptable
05:52sm0kebja: hurmm this is why i did not like when leiningen stopped respecting :scope "provided"
05:53sm0kein jar/uberjar tasks
06:03bjasm0ke, it doesn't respect ^{:pom-scope :provided} during uberjar creation?
06:04sm0kethat i dont know, but it does not respect [org.clojure/clojure "1.5.1" :scope "provided"]
06:04bjaoh
06:05sm0keit will put approprate entry in your pom.xml but will still include it in ubjerar
06:05bjait appears to respect :foo ^{:pom-scope :provided} [[org.clojure/clojure "1.5.1"]]}
06:05bjabased on just unzipping my uberjar
06:05sm0kehurmm interesting
06:06bjaerr, :foo-profile ^{:pom-scope :provided} {:dependencies [[org.clojure/clojure "1.5.1"]]}
06:07bjait looks like uberjar.clj only checks for the :provided scope of profiles. It won't walk individual dependencies to include/exclude jars
06:14zothrm. using reader conditionals, found strange behavior — commented out line causes map parsing to break? https://gist.github.com/benfleis/8e98eaa456b770c408d7
06:14zot(against 1.7.0-beta1)
06:14zotremoving the line makes problem go away
06:16kaiyinhow do you reformat selected code in vim? I have fireplace and VimClojureStatic installed.
06:16WickedShellI'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?
06:17oddcullykaiyin: `=`
06:18kaiyincool.
06:26TEttingerWickedShell: I have a decent amount of experience in Seesaw, can you put some code on a pastebin or refheap?
06:28WickedShellTettinger: 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????)
06:28TEttingerahhhhh
06:28TEttingerglad you caught it!
06:29WickedShellis that a common thing in seesaw? needing to restart the REPL so that changes to your running GUI will be reloaded?
06:31broquaintWickedShell: You can stay in the REPL but you do need to call pack! & show! to update your GUI.
06:31broquaintIIRC
06:32WickedShellbroquaint, ahhhh, yeah that makes a lot of sense actually, thanks
07:13kaiyinhow do you destructure a vector like (x:xs) in haskell?
07:14justin_smith,(let [[x & xs] (range 5)] xs)
07:14clojurebot(1 2 3 4)
07:14kaiyincool.
07:14justin_smiththat works in function args and loop bindings too
07:14tsdhI 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?
07:14justin_smithtsdh: group-by
07:14justin_smithwell not quite
07:14justin_smithsorry
07:15justin_smithtsdh: group-by would give a hash map ##(group-by even? (range 10))
07:15lazybot⇒ {true [0 2 4 6 8], false [1 3 5 7 9]}
07:16tsdhjustin_smith: Better than nothing. But I think there's one doing exactly what I wrote and being lazy thereby.
07:17justin_smith,((juxt filter remove) even? (range))
07:17clojurebot[(0 2 4 6 8 ...) (1 3 5 7 9 ...)]
07:17hyPiRionyah
07:17tsdhAh, yes. That's possible!
07:17justin_smithor does (juxt filter remove) have a binding?
07:18justin_smithnot too hard to type out I guess :)
07:18tsdhI 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.
07:19justin_smithso maybe it's a function in flatland/useful ...
07:20tsdhI 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. ;-)
07:20justin_smithhaha
07:20justin_smithtsdh: I mention useful because that's a lib amalloy contributes to extensively
07:21justin_smithtsdh: oh man, it would be funny to make a lib that lets you require and import from #clojure history
07:21tsdhI'll check it out.
07:21tsdhjustin_smith: Haha, yeah. Highly recommended for production use!
07:22tsdh(defn conj [& args] (throw (RuntimeException. "Best wishes from tsdh, sucker!")))
07:25tsdhjustin_smith: You are right. amalloy_ put that function into flatland/useful. https://github.com/flatland/useful/blob/develop/src/flatland/useful/seq.clj#L26
07:26justin_smithwell waddyakno
07:29mavbozo,(RuntimeException. "yolo")
07:29clojurebot#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] ...]}
07:30justin_smithnote that that created a new exception, but did not throw it
07:30mavbozo(ex-info "yolo")
07:30mavbozo,(ex-info "yolo")
07:30clojurebot#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"...
07:31mavbozo,(doc ex-info)
07:31clojurebot"([msg map] [msg map cause]); Create an instance of ExceptionInfo, a RuntimeException subclass that carries a map of additional data."
07:31mavbozo,(ex-info "yolo" {})
07:31clojurebot#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] ...]}
07:31slipsetwas just discussing with a colleague who tinkers quite a bit with clojure
07:32lxsameerguys is there any websocket server for clojure ? ( without dependency to client code )
07:32slipsetwhat do you do to pass info about the shape of data flowing around in a program
07:32slipsetSeems to me like a clojure program starts out using maps, vectors and combinations thereof.
07:33slipsetBut after a while, and especially while debugging, it would be rather nice to know the shape of the params in (defn foo [bar baz] ...)
07:33slipsetShould one start using defrecords and typehints, prismatic schema, core.typed or what?
07:34slipsetPlease don't say doc strings.
07:36kaiyincould anyone help with this? https://gist.github.com/kindlychung/691ffe277cf3bb99a44e
07:37mavbozolxsameer, i don't quite understand "without dependency to client code".
07:38lxsameermavbozo: I don't want it to force me to use a specific client code in my page
07:39mpenetlxsameer: https://github.com/mpenet/jet or aleph
07:40mavbozolxsameer, i assume you have tried both aleph and http-kit and they forced you to use specific client code
07:40mpenethttp-kit is barely maintained
07:41lxsameerthanks guys
07:51profillxsameer: I am using aleph and there is no requirement of client code there
07:52lxsameerprofil: cool,
07:53lxsameerprofil: I want to create a webrtc connection I need aleph to manage peer signaling, is it worth to try aleph for this purpose
07:53profillxsameer: yeah thats seems fine
07:53lxsameercool
07:54profillxsameer: on my client I am just wrapping javascript websocket with some clojurescript and core.async channels
07:55lxsameerprofil: I never used clojurescript , my clients are android application and I want to use either clojure-android or simple javascript as clients
07:56mavbozokaiyin, `primes` symbol inside `least-prime-divisor` is unbound
07:56profillxsameer: oh okay, then I would just decide to use json and use javascript on the client side :)
07:57lxsameerprofil: json ? through websocket or something ?
07:57kaiyinmavbozo: but primes is in the namespace.
07:58mavbozokaiyin, but to bound the primes, you need to execute expression which contains `prime` function which depends on `least-prime-divisor` function
07:59justin_smithkaiyin: clojure doesn't allow out of order definitions, unless you use declare
07:59mavbozokaiyin, also you have this ":else least-prime-divisor-from-primes ps n"
07:59profillxsameer: yeah, the peer signaling data (SDP) needs to be sent somehow? Stringify the object to json and then send it over websocket
07:59kaiyinmavbozo: yeah, I noticed that, and have corrected it.
08:00lxsameerprofil: ah yeah thanks, do you know any SDP lib for clojure or java ?
08:00mavbozokaiyin, clojure's execution is top-down. you can not use definition not declared before.
08:00profillxsameer: nope, never touched that part
08:00mavbozokaiyin, i have to move some of your functions up
08:01kaiyinmavbozo: ok.
08:01profillxsameer: are you supposed to touch the SDP sent from the users? if not then just pass it along like any other data
08:03lxsameerprofil: thanks man
08:11kaiyinmavbozo: I don't think moving the functions works: https://gist.github.com/kindlychung/691ffe277cf3bb99a44e
08:12kaiyin,(def myvec (into [2] [(first myvec)]))
08:12clojurebot#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...
08:12justin_smithkaiyin: that would only work with something lazy
08:12justin_smithvectors are never lazy
08:13kaiyin,(def myvec (into (seq [2]) [(first myvec)]))
08:13clojurebot#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...
08:13justin_smiththat's not lazy either
08:13kaiyinjustin_smith: could you give a working example?
08:14justin_smith,(def mylz (lazy-seq (cons 2 mylz)))
08:14clojurebot#'sandbox/mylz
08:14justin_smith,mylz
08:14clojurebot(2 2 2 2 2 ...)
08:15justin_smith,(nth mylz 1000)
08:15clojurebot2
08:15kaiyinvery cool.
08:16justin_smithkaiyin: for the most part clojure is not lazy, and you need lazy or delayed evaluation for that sort of definition to work
08:16kaiyinok
08:19mavbozo(inc justin_smith) ;; showing usage of unbound symbol in lazy-seq
08:19lazybot⇒ 244
08:20kaiyinI have got the prime searching function to work: http://codereview.stackexchange.com/questions/87180/prime-numbers-generator-in-clojure
08:21mavbozokaiyin, cool
08:26slipsetkaiyin use recur instead of calling least-prime-divisor-from-primes explisitly
08:26kaiyinslipset: yeah, I was thinking about that also, but need to brush up on the loop...recur syntax.
08:27slipsetalso, 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
08:28slipset(defn least-prime-divisor ([n] ...) ([[p & ps] n] ...))
08:29slipsetcould imagine switching arg order in the second form...
08:55kaiyinc
08:56kaiyincan i insert latex equations in clojure doc string?
08:58lalaland1125kaiyin, You should be able to use Unicode literals for your doc string. That should be enough to provide the math formatting for equations.
08:59lalaland1125The actual spacing and alignment might be a little off.
09:36profilI am making a version of a* and want to use a priority queue, any ideas of which lib to use?
09:41puredangerwell, http://docs.oracle.com/javase/7/docs/api/java/util/PriorityQueue.html is in the box
09:48profilmutability :(
09:49justin_smithprofil: wouldn't a sorted-set-by work?
09:49justin_smith(doc sorted-set-by)
09:49clojurebot"([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."
09:50justin_smitha* shouldn't care if duplicates are collapsed, right?
09:51justin_smithbe 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
09:52justin_smith,(sorted-set-by (juxt :a identity) {:a 0 :b 1} {:a 0 :b 2} {:a 22 :b 3} {:a -1 :b 0})
09:52clojurebot#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 ...
09:52justin_smitherr
09:53profilI'm just after O(logn) insert and constant pop/dequeu
09:53puredangeryou need a heap right?
09:53puredangerisn't there a clojure heap impl somewhere?
09:53profilyeah, thats usually how prio queues are implemented
09:53profilin pure clojure? cool :D
09:54profilI need to be able to set the comparator function
09:55puredangergoogling "clojure heap" turned up a few things people have done
09:56puredangerhttp://www.leonardoborges.com/writings/2013/02/03/purely-functional-data-structures-in-clojure-leftist-heaps/
09:56profilthere is also clojure/data.priority-map
09:56puredangerah, that's prob what I was thinking of
09:56puredangertoo many libs, too little brain
09:58virmundihello. 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.
09:58virmundiis this right?
10:21kaiyinhow do you load the current buffer into repl in fireplace?
10:30kaiyinwhy am i getting null point exception here? https://gist.github.com/kindlychung/4807b7cfe6ab9e1c5f0c
10:37geirbykaiyin: somehow null value got into gcd
10:37geirbykaiyin: I'll have a look
10:37adereth,(let [[y & rest-ys] []] y)
10:37clojurebotnil
10:38aderethkaiyin: I think lines 47-48 are where the null gets introduced
10:39kaiyinadereth: i see, will try to fix it.
10:44aderethkaiyin: Even without that bug, I think relative-prime-with-rest? will always return false
10:45lvhCould 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:45oddcullykaiyin: mark the code and do :Eval; read different ways up in `:help fireplace`
10:47kaiyincool, thanks, oddcully
10:52kaiyinhow can i fix the error 61: connection refused, in fireplace?
10:53justin_smithsounds like you aren't connected to a running repl
10:53oddcullyor that what it thinks that should be the connection connects to something else
10:53kaiyinjustin_smith: isn't it supposed to be automatically connected?
10:53justin_smithno, clojure uses a lot of ram, so none of the editors automatically makes a repl
10:53oddcullyif you just want to have a lein repl and some clj opened then do a `:Connect nrepl://theurl`
10:54oddcullyor keep some `lein new scratchpad` around
10:56kaiyinjustin_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:56oddcully"in the project dir" might be the clue
10:57kaiyinoddcully: I am still in the project dir.
11:02kaiyinwhat other changes should i make if i have changed the project name in project.clj?
11:04oddcullykaiyin: no clue then. if you have one repl running and start vim afterwards (both in the project dir) it "usually works"
11:06justin_smithkaiyin: it's good if the group and project are reflected in the namespace / package structure
11:08kaiyinok, i restarted the repl and everything works now.
11:10kaiyinAnother 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:10kaiyinthis is in vim with fireplace.
11:12oddcullyis this while marking the line or is your cursor inside the () ?
11:13kaiyinoddcully: not the whole line, just va(.
11:13kaiyini.e., select everything between the parens, including the parens.
11:15oddcullyonly gives me the namespace if i shift-v it; other wise either Eval or cpp just ignore the line
11:18kaiyinoddcully: what addon manager do you use?
11:18kaiyinI use vundle.
11:19virmundihello. 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:19virmundiwith the dispatch function.
11:19oddcullygood question actually... the one that uses ~/.vim/bundle
11:19oddcullypathogen that is
11:21geirbyhow do I create a vector out of a few sequences?
11:22geirbywanna get a vector out of (range (int \A) (int \Z)) and (range (int \a) (int \z))
11:22geirbyand probably something else
11:22geirbydoing 'into' several times doesn't look good
11:23oddcully,(doc concat)
11:23clojurebot"([] [x] [x y] [x y & zs]); Returns a lazy seq representing the concatenation of the elements in the supplied colls."
11:23geirbycheers
11:23geirby(inc oddcully)
11:23lazybot⇒ 3
11:24oddcullycheers! (close to beertime now)
11:25justin_smith,(reduce into [] [(map char (range (int \A) (inc (int \D)))) (map char (range (int \a) (inc (int \d))))])
11:25clojurebot[\A \B \C \D \a ...]
11:26justin_smithif you explicitly need a vector
11:26geirbyof course, reduce
11:26geirbythanks
11:26justin_smithI use reduce like paula deen uses butter
11:27geirbyactually, sequence would do just fine,
11:27justin_smiththat's probably an out of date reference by now
11:27justin_smithin that case concat is simpler
11:29rpaulojustin_smith: out of date would probably be julia child
11:29rpauloshe also uses A LOT of butter
11:29justin_smithoh, TRUE
11:34geirby,(->> [\A \Z \a \z \0 \9] (map int) (partition 2) (map (fn [[l h]] (range l h))) (apply concat) (map char))
11:34clojurebot(\A \B \C \D \E ...)
11:38geirbyahh, range is not enclusive
11:38justin_smiththat's why I had inc on the upper bounds of mine
11:39geirbyyep
11:54mgaare_anyone know why this is happening? (case (class (java.net.URI. "sup")) java.net.URI "uri" "not") ;; => "not"
11:56mpenet,(doc case)
11:56clojurebot"([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:56mpenetrelevant part: "They must be compile-time literals"
11:58mpenetthere are tons of case+ case-eval etc macros that fix that
11:58mpenetone google search away
11:58mgaare_a java class isn't a compile-time literal?
11:59mgaare_guess not, ok.
11:59mpenethttp://cemerick.com/2010/08/03/enhancing-clojures-case-to-evaluate-dispatch-values/
11:59mgaare_tried a couple others.
11:59mgaare_thanks!
12:01noncomwhat is the best approach to make certain fns available from any ns in the project? (besides of referring it from everywhere)
12:01noncompotemkin?
12:07justin_smithmonkeypatching clojure.core?
12:07justin_smith(don't do that)
12:08noncomhehe, yeah )
12:08noncomhowever, i do patch it in a couple of places, like get the global (start) fn available from anywhere
12:14the-kennyThat sounds quite dirty
12:15kaiyincould anyone help with this? http://stackoverflow.com/questions/29704447/how-to-avoid-stackoverflow-in-clojure-recursive-function
12:15kaiyinthe case looks hairy because loop...recur can only be used with tail calls.
12:20sduckettAdduser ian 0knaukim;
12:21oddcullyhmm
12:25broquaintkaiyin: How are those recursive functions meant to terminate (it doesn't look like they do)?
12:25kaiyinbroquaint: they are not to meant to end, i intended to get a lazy seq out of it.
12:25kaiyinbroquaint: because there are infinite number of primes.
12:26broquaintThen 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:26broquainti.e within mark & sieve.
12:30kaiyinbroquaint: i see.
12:30patrickgombertI'm seeing some weirdness with :volatile-mutable and deftype -- https://gist.github.com/patrickgombert/1bcb8a051aeb3e82d855
12:30patrickgombertit fails to compile when I set! in a try..finally and return this
12:30patrickgombertif I don't use try..finally or do not return this then it succeeds in compiling
12:32dnolenpatrickgombert: "weirdness" is vauge, you should include a stack trace
12:34puredangerpatrickgombert: that sounds like a bug - please file a jira http://dev.clojure.org/jira/browse/CLJ
12:34eraserhdIs there a clojure equivalent to "organize imports" available via vim-fireplace or stand-alone.
12:34eraserhd?
12:34oddcullyeraserhd: slamhound?
12:34patrickgombertdnolen: sorry, should have included that. I updated the gist. I get an IllegalArgumentException which says Cannot assign to non-muable: _oof
12:35patrickgombertpuredanger: will do
12:35kaiyinbroquaint: I added the lazy-seq part, but now it hangs the whole nrepl session: https://gist.github.com/kindlychung/6c690044dcbbba0c464e
12:36eraserhdoddcully: yes!
12:39dnolenpatrickgombert: trying dropping the leading `-` from that field name
12:39dnolenpatrickgombert: s/trying/try
12:40patrickgombertdnolen: seeing the same issue
12:40dnolenpatrickgombert: ah k, yeah dunno then :)
12:41patrickgombertseeing it on 1.6.0 and 1.7.0-beta1
12:41patrickgombertno worries, I'll file a bug
12:43broquaintkaiyin: I believe that's because you're feeding an infinite list to sieve which then tries to destructure it :)
12:43broquaintIf you just pass (range 10) f.ex then sieve returns quite snappily.
12:44broquaintI think you'll need to take the first/rest approach like in the example in those docs I linked.
12:56kaiyinbroquaint: that sieve also hangs indefinitely, :-)
12:57kaiyinand at last throws stackoverflow error.
13:24virmundihow 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:26Bronsa,(defmulti foo (fn [m db] (:key m)))
13:27clojurebot#'sandbox/foo
13:27Bronsa,(defmethod foo :foo [_ db] db)
13:27clojurebot#object[clojure.lang.MultiFn 0x48a88dc8 "clojure.lang.MultiFn@48a88dc8"]
13:27Bronsa,(foo {:key :foo} 1)
13:27clojurebot1
13:27Bronsavirmundi: ^
13:29virmundicould have sworn I tried that. Thanks
13:29virmundiit makes sense.
13:30TEttinger(inc Bronsa)
13:30lazybot⇒ 106
13:38kaiyinbroquaint: 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:38kaiyinand the function is now working, although I am not yet completely happy with it.
13:53saik0kaiyin: you might enjoy https://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf
13:57saik0she describes an unbounded sieve with a wheel optimization
13:57TEttingerinfinite lazy sequence of primes, you say? why not BigInteger?
13:57TEttinger,(take 50 (remove nil? (map #(if(.isProbablePrime(biginteger %)5) % nil)(range))) )
13:57clojurebot(2 3 5 7 11 ...)
13:57TEttinger&(take 500 (remove nil? (map #(if(.isProbablePrime(biginteger %)5) % nil)(range))) )
13:57lazybot⇒ (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:58kaiyinsaik0: thanks.
13:58TEttingeroh that can be golfed...
14:01saik0TEttinger dont know about about isProbablePrime's impl, but the sieve in the paper is ~4x faster, by my very unscientific test
14:03TEttingersaik0, testing on the same machine?
14:03TEttingerlazybot and clojurebot run on different hardware
14:03saik0TEttinger on my machine, yes
14:03TEttinger&(take 500 (let [uno (biginteger 1)](remove nil? (map #(if(.isProbablePrime % 3) %)(iterate #(.add % uno) (biginteger))))) )
14:03lazybotclojure.lang.ArityException: Wrong number of args (0) passed to: core/biginteger
14:03TEttinger&(take 500 (let [uno (biginteger 1)](remove nil? (map #(if(.isProbablePrime % 3) %)(iterate #(.add % uno) (biginteger 2))))) )
14:03lazybotExecution Timed Out!
14:03TEttingerinteresting
14:04broquaintkaiyin: Nice one :)
14:04kaiyinbroquaint: thanks. :-)
14:04saik0TEttinger my impl is lacking the wheel sieve as well, let me add it
14:09TEttingersaik0, try with less probableprime precision:
14:09TEttinger,(take 500 (remove nil? (map #(if(.isProbablePrime(biginteger %)3) % nil)(range))) )
14:09clojurebot(2 3 5 7 11 ...)
14:09TEttinger2 is too low and results in false positives, I use 3 there and used 5 initially
14:11timvisher,(format "%s&%s" "charnock" "whitefield")
14:11clojurebot"charnock&whitefield"
14:11timvisherbah...
14:12timvisherah... it's that it's going through mustache
14:13timvisheranyone know off the top of their head how to put `&` in a mustache template (for a lein template)?
14:15timvisherlooks like maybe {{{}}} or {{&}}
14:16timvisherglad to know my understanding of `format` isn't entirely broken :)
14:36saik0TEttinger, kaiyin: https://gist.github.com/saik0/ed01393d89e2fc613775 might not be too elegant/idiomatic, still learning
14:39TEttingersaik0: 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:39TEttinger ([] (conj (primes (prime-cand)) 7 5 3 2)) ; this stuff
14:40saik0TEttinger I hail from Scheme. What's a vector ;)
14:40saik0(dont answer that)
14:40TEttingerwhat's our vector, victor?
14:41TEttingerwe have clearance, clarence.
14:41TEttingerroger, roger.
14:42clyfehttps://tbaldridge.pivotshare.com/media/testing-episode-1/22222/feature can't view, is it broken ?
14:42TEttingerworks for me, clyfe
14:44AeroNotix_I have an implementation of a mutex. What's a good test to ensure that it's correct?
14:45saik0TEttinger will try that destructure the inifinite seq?
14:45saik0(conj [2 3 5 7] (primes (prime-cand)))
14:45TEttingerconcat
14:46saik0I should finish joy of clojure before i write any more
14:46saik0thanks
14:46TEttinger,(concat [2 3 5 7] (primes (prime-cand))) ; may be more idiomatic but may not perform better!
14:46clojurebot#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:46TEttingerright, shouldn't use the , when I haven't defined primes :)
14:47saik0TEttinger hust tried it here and it's not terminating
14:48TEttingerah ok
14:48TEttingerI thought concat was lazy...
14:48TEttingeroh probably not with seqs
14:48TEttinger(doc concat)
14:49clojurebot"([] [x] [x y] [x y & zs]); Returns a lazy seq representing the concatenation of the elements in the supplied colls."
14:49TEttinger,(take 500 (concat [0 0 0 0] (range)))
14:49clojurebot(0 0 0 0 0 ...)
14:49TEttinger&(take 500 (concat [0 0 0 0] (range)))
14:49lazybot⇒ (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:49TEttingerwell it is lazy....
14:50saik0TEttinger, ah, (conj [2 3 5 7] ... was still executing. oops!
14:52clyfeCore async pipline should return the "to" channel, to make it threading friendly
14:54clyfe(->> (to-chan [1 2 3]) (pipeline 3 (chan 3) reticulate))
14:55clyfeI wish they'd a t least open the github issue tracker
15:00virmundican when-let be used with keys destructuring?
15:00virmundi(when-let [{:keys [username password]} conn]
15:00virmundi {:users [{:username username, :password password}]})
15:01virmundi(def conn {:type :simple, :url http://arangodb:8529})
15:09TEttinger,(def conn {:username "Bill", :password "Excellent!"})
15:09clojurebot#'sandbox/conn
15:10TEttinger,(when-let [{:keys [username password]} conn] {:users [{:username username, :password password}]})
15:10clojurebot{:users [{:username "Bill", :password "Excellent!"}]}
15:10TEttingervirmundi: yes
15:16amalloyvirmundi: 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:19kaiyincould anyone help with this?
16:19kaiyinhttp://stackoverflow.com/questions/29708625/circular-definition-in-clojure
16:22lodinTwice 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:23mavbozo,(take 7 (cycle [0 1 2]))
16:23clojurebot(0 1 2 0 1 ...)
16:24mavbozokaiyin, ^ would be enough for that use case
16:25kaiyinmavbozo: yeah, but I am really looking for a general circular definition, i find it very cool.
16:25lodinkaiyin: You can use declare.
16:25kaiyinlodin: Could you elaborate?
16:26lodinWhat's the bot command for doc refs?
16:26kaiyin,(doc declare)
16:26clojurebot"([& names]); defs the supplied var names with no bindings, useful for making forward declarations."
16:26lodinkaiyin: :-)
16:26kaiyinok, I see what you mean now. :)
16:26mavbozo,(declare f1 f2 f3)
16:26clojurebot#'sandbox/f3
16:26mavbozokaiyin, works on my repl
16:27kaiyincool!
16:28darthdeushey 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:28kaiyinindeed, very nice!
16:28darthdeusor 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:41noncom|2what library currently is adviced to add some automation to the program, like execute some action after some time?
17:00bcm`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:02amalloybcm`: 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:02noonianbcm`: if you want to use it in other projects probably best to make it a lib
17:02amalloythat 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:03pbxbcm`, did you mean useful to yourself or to others?
17:08profilis there a similiar function to for which can be exited early and throw away the old sequence?
17:09profilOr should I instead check the result from for and disregard the result in case my test holds?
17:11noonianprofil: 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:12justin_smithprofil: for is lazy, just use take-while or whatever and don't realize the part you don't want
17:13profilnoonian: 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:13justin_smithprofil: 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:14justin_smithprofil: see also the :while key in the extended args to for
17:17noonianyeah 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:21profilah, I didnt know about the reduced function
17:22jonathanjztellman: yay for aleph 0.4.0 (and all the other awesome libraries), great stuff
17:24profilztellman: 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:28mikerodThis line of clojure.lang.Compiler surprised me https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Compiler.java#L6784-L6787
17:28mikerodIn particular, ` ((Symbol) RT.first(form)).name.startsWith("def")))`
17:28mikerodif a symbol starts with the prefix "def" it goes down another path
17:28mikerodof analysis
17:29mikerodI'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:30mikerodIt 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:31mikerodI'm just curious of starting a function name with "def" could potentially lead to weird compiler issues. Like "(definitely-not-a-def :blah)"
17:32Bronsamikerod: 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:32mikerodBronsa: I'm glad I'm not alone in thinking that line looked suspicious
17:33mikerodI haven't gone far tracking down the alternative path though. Glad to know it hasn't broke anything in your experiments though.
17:38profilnoonian, justin_smith: thanks guys, I solved it using reduce and reduced, much nicer now than before =)
17:41campetersonHey all, is there a better alternative to having a try/catch inside a ‘let’ binding?
17:41campeterson 61 (let [tx-result
17:41campeterson 62 (try
17:41campeterson 63 (/ 1 0)
17:41campeterson 64 (catch Exception e (str "caught exception: " (.getMessage e))))]
17:41campeterson 65 tx-result)
17:50lodinIf 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:53tomjackthe fact that that works at all is an implementation detail you should not rely on
17:53amalloylodin: 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:53amalloyyes, exactly what tomjack is saying also
17:54tomjackneed to 'get around' the whole thing, and figure out a different way to express what you want, I guess
17:55tomjackand/or want something different :)
17:58mikerodtomjack: are you saying :on-interface is a impl detail or the fact that inline protocol implementors implement an actual interface?
17:59kaiyin 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:59mikerodPerhaps 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:59lodinkaiyin: Are you doing 4clojure exercises or something? :-)
18:00kaiyinlodin: no, I am reading a number theory book and trying to implement some of the theorems in clojure. :)
18:00mikerodI guess if you want an interface to implement, use definterface instead?
18:00mikerodor write it in Java
18:00mgaare_kaiyin: does the order need to remain the same?
18:01amalloymikerod: yes, the generated interface is an implementation detail
18:01amalloy:on-interface even more so
18:01kaiyinmgaare_: no, in this case that's not essential. But I would like to know a way to keep the order, too.
18:01mgaare_kaiyin: simplest thing, just look at clojure.core/set
18:02ztellmanprofil: hey, sorry, just saw this
18:02TEttinger,(#(take-while (set (distinct %)) %) (cycle [1 2 3 4]))
18:02clojurebot#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:02TEttingerheh
18:02amalloymgaare_: i don't think that is likely to produce a useful answer
18:02kaiyinmgaare_: I am not sure, the sequence is lazy and infinite.
18:02mgaare_oh, I missed the ellipsis
18:02mgaare_right you are
18:02ztellmanprofil: basically, the way a source knows the sink it's feeding into is closed is by trying to write into it
18:03amalloyeven if it were finite, sets don't have ordering guarantees
18:03ztellmanand each layer of indirection will add additional "lag" between the sink you have and the original source
18:03TEttingerthe other thing is that the sequence could be 1, 2, 3, 4 repeated 99999 times and then a 5 in there, once
18:03mgaare_yes, I was going after the "ordering is not essential" part
18:04ztellmanprofil: 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:04amalloykaiyin: actually "take out the repeated segment" is a very vague question. i don't understand what you want to do
18:06profilztellman: what do you mean, "each layer of indirection"? I solved this by doing "#(when-not (s/closed? s) ..." so no worries :)
18:06kaiyinamalloy: TEttinger: the first element is guaranteed to be repeated, and after that periodicity is also guaranteed.
18:06TEttingerwhat about 11100101010011011110010101001101
18:06kaiyini.e. if you have [1, 2, 3, 4, 1, ...], then the next element must be 2, and then 3, and so on.
18:06amalloykaiyin: but you still can't know how long the period is. suppose i give you [1 2 1 2 1 2 ...]
18:07mikerodamalloy: that's interesting. News to me I suppose. I tend to not use them for their types anyways though.
18:07kaiyinamalloy: in that case, i need to take out [1, 2]
18:07amalloyso 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:07mikerodsince, like you guys suggested - its not the purpose
18:07tomjackmikerod: consider e.g. cljs
18:07kaiyinamalloy: no, that's not possible.
18:07amalloyokay, in that case it is a soluble, indeed easy, problem
18:07ztellmanprofil: oh, nm, I had misremembered the implementation, this is just how I'm interacting with the ScheduledThreadPoolExecutor
18:08ztellmanprofil: I should be doing that check myself
18:08kaiyinif you see [1, 1...], then you can be sure you have [1, 1, 1, 1...]
18:08ztellmanbut that'll have to go into 0.1.1 :)
18:08amalloyso your problem isn't actually about repeating sections at all
18:08mikerodtomjack: yeah, that came to mind
18:08tomjacknot that everything jvm-specific is an implementation detail, but...
18:08amalloyit's about finding the prefix of a sequence up until you see its first item again
18:09kaiyinamalloy: i think i know how to do it now. ;)
18:09TEttinger,(reduce #(if (contains? %1 %2) (reduced %1) (conj %1 %2)) [] (cycle [1 2 3 4]))
18:09clojurebot[1 2 3 4]
18:09amalloy(fn [coll] (let [[x & xs]] (cons x (take-while #(not= % x) xs))))
18:09amalloy(fn [[x & xs]] (cons x (take-while #(not= % x) xs)))
18:09tomjack,(reduce #(if (contains? %1 %2) (reduced %1) (conj %1 %2)) [] (cycle [10 11 12]))
18:09clojurebot[10 11 12 10 11 ...]
18:10tomjack(bad use of contains?)
18:10TEttingeryep
18:10amalloytomjack: yes
18:10TEttinger(inc amalloy)
18:10lazybot⇒ 258
18:11profilztellman: ahh okay, great!
18:11ztellmanprofil: 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:12profilztellman: 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:13ztellmanprofil: I'm on here when I don't forget to open my IRC client, which is usually the case
18:13profiloh get a persistent shell you!
18:14profilotherwise, great work with aleph and manifold
18:19kaiyindoes Math/pow coerce an integer into a double?
18:20kaiyin,(Math/pow 2 3)
18:20clojurebot8.0
18:20kaiyinhow to avoid that?
18:22lodinkaiyin: Don't know if it is good, but you could do (defn pow [x n] (apply * (repeat n x))).
18:22kaiyinok, there is no existing implementation of integer power?
18:23lodinkaiyin: Maybe, don't know.
18:23tomjackone is (.pow (biginteger 2) 3)
18:23kaiyinok
18:24tomjack:/
18:24amalloyinteger power is easy, though. (apply * (repeat n x))
18:25kaiyinyeah.
18:25lodinamalloy: 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:26amalloyperformance
18:26amalloyinterfaces are way faster
19:18lodin(inc amalloy)
19:18lazybot⇒ 259
20:22hiredmanis 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:23ztellmanhiredman: I think that's firmly in CinC territory as far as the roadmap goes
20:23ztellmanat least it was the last time I raised it
20:25hiredmanI 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:05amalloyhiredman: what would be the solution to that? create a synthetic setter method like javac does for inner class shenanigans?
21:13lodinAm I the only one that intuitively want to write {:a a} in map destructuring instead of {a :a}?
21:14hiredmanamalloy: I dunno
21:17scottjlodin: 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:17dnolenlodin: takes some getting used to, but it can't be that way because of :keys & :or etc.
21:17scottjlodin: 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:18lodindnolen: Yes, I realize that's the issue.
21:18dnolenlodin: if you're not renaming, there's not reason to prefer that form over :keys anyway
21:23lodindnolen: 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:24lodinHmm. Maybe that would be confusing when you nest destructuring.
21:24amalloyyes. you can't do that because of nesting
21:24lodinamalloy: You can nest, like {[:a [x y]]} if :a contains a tuple.
21:27lodinWhen I wrote {a b} is meant a and b to be symbols; having {[...]} wouldn't make sense since the map isn't ordered.
21:27lodins/is/I/
21:28amalloylodin: 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:28lodinThe reason I'm asking is because I'm writing a macro. :-)
21:29amalloyalso, {[:a a]} is not even a thing you can legally write, because it's a map with a key and no value
21:29amalloythe reader will reject it before you get to macroexpansion
21:29lodinIt's for a special case, so I'm not trying to replace regular let destructuring, btw.
21:30lodinamalloy: Ah, that's a good point. I don't have the outer {} though so I'm fine for my application.
21:31lodinI guess the takeaway from the comments above is that it is probably fine to deviate from let syntax for my macro.
22:13einfachhi
22:14einfachI am a professional clojure developer and looking for remote work, however small.
22:32iamjarvo(defn text->my-method [] ) saw this in code earlier. can someone please explain whats happening? difficult to google for
22:35badfish129Hi, why can't I do this, (defn testfn [] (println "hello")), (def fns `(testfn otherfn)), ((first fns)) => this yields an ArityException...
22:39iamjarvobadfish129 testfn doesn't accept arguments as far as i can tell
22:40badfish129iamjarvo: yeah I was just trying to make it print hello, this works though (def fns [testfn otherfn]), ((first fns))
22:41nuwanda__badfish129: you need to resolve the symbol
22:41nuwanda__the error it gives you is not that you're passing a wrong arity to the function
22:41nuwanda__it's that you're trying to call a symbol with arity 0
22:42badfish129so I have to unquote it? sorry for these stupid questions I'm a complete noob
22:42nuwanda__((resolve(first fns))), something like this should work
22:47badfish129cool thanks!
22:50nuwanda__np :)
22:52badfish129what 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:55badfish129do i have to store the constructors themselves in the list (def types [->A, ->B]) and then call them?
22:56nuwanda__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:57noonianbadfish129: what are you trying to do? sorry i missed the beginning of your question
22:58badfish129noonlan: 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:58badfish129noonian: 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:00noonianyeah a record contructor is just a function, you can stick it in a vector
23:00badfish129noonian: cool, do you think that would be the cleanest way?
23:02noonianif 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:03noonianbut something like a dispatch table is perfectly fine also
23:03badfish129noonian: 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:04badfish129noonian, nuwanda_: thanks for the help!
23:04noonianbadfish129: 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:06noonianalso, 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:06noonianmap->A instead of ->A