#clojure logs

2016-01-09

00:26BRODUSi'll try my question again since its quieted down, can derefing an atom ever throw an error? in the source the print method for atoms is same for other types that implement IDeref and they wrap the deref operation in a try/catch. I think this is only pertinent for Futures whose value isn't known yet, but I wondered if anyone else could confirm
00:26BRODUSheres the method: https://github.com/clojure/clojure/blob/bc186508ab98514780efbbddb002bf6fd2938aee/src/clj/clojure/core_print.clj#L387-L408
00:28amalloyderef on an atom can't throw an exception. it could theoretically throw an error like StackOverflowError if you happened to be at the end of your allocated stack already, but that's really just a problem in the calling code
00:29amalloy*printing* an atom could throw a StackOverflowError, if the data in the atom is circular, or if the atom points to itself
00:29amalloy,(let [a (atom nil)] (reset! a a) (deref a) nil) ;; no error from dereffing
00:29clojurebotnil
00:30amalloy,(let [a (atom nil)] (reset! a a) (deref a)) ;; but if you try to print that...
00:30clojurebot#object[clojure.lang.Atom 0x65e6d2ae {:status :ready, :val #object[clojure.lang.Atom 0x65e6d2ae {:status :ready, :val #object[clojure.lang.Atom 0x65e6d2ae {:status :ready, :val #object[clojure.lang.Atom 0x65e6d2ae {:status :ready, :val #object[clojure.lang.Atom 0x65e6d2ae {:status :ready, :val #object[clojure.lang.Atom 0x65e6d2ae {:status :ready, :val #object[clojure.lang.Atom 0x65e6d2ae {:status ...
00:30BRODUS,(println (atom "1234"))
00:30clojurebot#object[clojure.lang.Atom 0x5478a746 {:status :ready, :val 1234}]\n
00:30amalloywell, okay, clojurebot is configured so that that doesn't error, but most programs aren't
00:30BRODUSits weird they include the status field for atoms
00:31BRODUSits not useful
00:31BRODUSit looks like it will always be 'ready'
00:32justin_smithBRODUS: I think it's for all things that can be dereffed (many of which have a non-ready state)
00:32justin_smith,(promise)
00:32clojurebot#object[clojure.core$promise$reify__6999 0x38c25d61 {:status :pending, :val nil}]
00:32BRODUSright, but its still not unnecessary
00:33BRODUSi mean, its unnecessary
00:34justin_smith,(Object.)
00:34clojurebot#object[java.lang.Object 0x53202231 "java.lang.Object@53202231"]
00:34justin_smiththat hex number is not neccessary either
00:34justin_smithit's just part of the printed representation
00:36BRODUShmm, the hex code coudl be necessary if you were trying to see if objects were the same instance
00:36justin_smithBRODUS: identical? will tell you that
00:36justin_smithjust like realized? tells you if a derefable is ready
00:36justin_smithbut it's in the printed form too
00:37justin_smithin both cases
00:38BRODUSyeah but if you were just looking at logs the hex code is needed for that differentiation
00:38justin_smiththe info is useful, it's concise, it's cheap to provide it, so why not print it when printing the object?
00:38justin_smithBRODUS: sure, and when I print a dereffable, it's nice to know if it's realized
00:38justin_smithBRODUS: what makes you think knowing if a dereffable is realized is not useful?
00:39BRODUSi never said that, i just think its confusing for atoms
01:16TristeFigureHi. I'm having a little problem. I'm reading a .clj file path using the *file* dyn var, but what I get is a string representing the path of the file relative to its "source-path". For instance *file*'s value is myproject/core.clj and what I want to is an absolute path or at least a relative path that encompasses the src folder, e.g. src/myproject/core.clj. So basically I need to get the current "source-path" value (i
01:16TristeFigurenot necessarily in src, it can be in /test or in any other custom-set directory). I'm not sure how I could achieve something like this. There is a *source-path* var in the standard library but it seems it only contains the current file name+extension. Any idea ?
01:34neoncontrailsTristeFigure: sounds like what you want is a file server. Clojure doesn't make this particularly easy, but have a look at Compojure: https://github.com/weavejester/compojure
01:40neoncontrailsThe idea is actually pretty simple though. You're basically just defining those strings that are the local path as the key, and returning the file as a value for those keys
01:40elvis4526Hello. I'm experiencing a OutOfMemoryError inside a relatively big clojure web app. Any tips on how to diagnose this ?
01:41elvis4526I know for the leak to happen, the app need to run for an extended period of time. Usually 2-3 weeks non-stop and more
01:43neoncontrailselvis4526: heh I'm working on a similar problem. Haven't solved it yet, but maybe we could help each other out
01:44neoncontrailsIt's running server-side?
01:44justin_smithelvis4526: you can profile clojure apps with visualvm or yourkit
01:46neoncontrailsI always forget Clojure has back-end capabilities. That might be a better solution than client-side cljs for my problem, hmm...
01:49elvis4526neoncontrails: Yep it is.
01:50elvis4526justin_smith: I tried the memory sampler in justin_smith, however i'm not quite sure what the results are supposed to mean
02:10elvis4526Storing Ring requests inside an Atom isn't really a good idea right ?
06:38lokiencan someone explain a fn pattern to me? I'm staring at it for half an hour now and I still don't know how it works
06:39BRODUSlokien: what do you mean?
06:40lokienBRODUS: I'll lpaste it
06:43lokienhttp://lpaste.net/2716934979316613120
06:44lokienBRODUS: I mean that function it's used with reductions
06:44BRODUSyou're confused about how 'move' works ?
06:45lokienyeah
06:46lokienparticularly that anon function
06:50m1dnight_I keep getting this "when-let decleration should be a vector" error but it doesnt specify a proper file where it occurs
06:50m1dnight_ive grepped all my when-let lines in my entire project and they all seem fine..
06:50m1dnight_any tips on how to debug?
06:50BRODUS,({go-right left go-left up go-up down go-down} \<)
06:50clojurebot#<RuntimeException java.lang.RuntimeException: Map literal must contain an even number of forms>
06:51BRODUS,(clojure.string/split "<<>>" #"")
06:51clojurebot["" "<" "<" ">" ">"]
06:51BRODUS,({right go-right left go-left up go-up down go-down} "<")
06:51clojurebot#error {\n :cause "Unable to resolve symbol: right in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: right in this context, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6688]}\n {:type java.lang.RuntimeException\n :message "Unable to resolve symbol: right in this...
06:52lokienBRODUS: I can clarify what it does
06:52lokienI just don't know how it does it
06:52BRODUSi'm just trying to work from the sexp with the hash map outwards
06:52lokienkay
06:53BRODUSoh ok
06:53BRODUSi didn't realize the keys would be evaluated in the hash map
06:54BRODUSafter evaluation the hash map looks like {"<" go-left ">" go-right ...} and so on
06:54BRODUSeach motion points to a function
06:55lokienuhm, ya
06:55TMA({...} word) returns a function. that function is passed position which is a two-element vector
06:55lokienso.. we extract a function from a map and use it on position?
06:55lokienI think I understand now
06:55BRODUSyeah
06:56lokienwelp, thanks
09:43ely-seIs there a function like load-file that takes a URL instead of a String?
09:45domgetterely-se: (eval (slurp url)) ? (this may be a very bad thing to do)
09:46BRODUSooh, i didn't know slurp took a url
09:47ely-sedomgetter: it was an XY question, actually. I want to execute clj files that are resources. It seems load does that
09:52ely-sethanks :)
10:44justin_smithyou would need a read-string between slurp and eval
10:55domgetterAnyone know a good resource to learn what the term "middleware" means?
10:57AimHereWouldn't wikipedia give you a rough overview?
10:59domgetterThe description on wikipedia applies to any library I use. Are all libraries middleware?
11:05domgetterHere is my question in context: https://github.com/dakrone/clj-http/blob/master/src/clj_http/client.clj
11:05domgetterThere are "middleware" functions in that file, but the wikipedia page talks about gluing programs together
11:05domgetterso why is the word being used two completely different ways?
11:06domgetterThat's a bad rhetorical question. I guess what I should ask is, can the wikipedia page help me come to an understanding of the use of the term "middleware" in that client.clj file?
11:07justin_smithdomgetter: a middleware is a function that takes a function as an argument and returns a new augmented function
11:08justin_smithdomgetter: in a ring app, you have your handler which serves a request, and pass that to various middleware, like the one that takes a request, and returns a request which tracks a user session, for example
11:08justin_smithor one that takes a request, and returns a request where the request parameters are not mapped to keywords in a hash-map instead of being a raw string
11:08justin_smithetc.
11:08justin_smiths/not/now
11:08domgetterjustin_smith: if I did that with channels, would the things which take stuff of off channels and process them be considered middleware?
11:09justin_smithno - but if you had a function that took a channel, and returned a new channel that did some special new thing for every event on the channel, that would be a middleware
11:09domgetterlike a channel with a transducer on it?
11:10justin_smithexactly, the transducer there acts as a middleware
11:10justin_smithit wraps x, returns a new thing you can use as if it was x, but has a new feature
11:10justin_smithor a modified behavior
11:11justin_smithdomgetter: in functional programming we often use composition of middleware in cases where OO programs would use inheritence
11:12domgetterand by composition here you mean functional composition?
11:12domgetteror possibly a more general notion of combining?
11:13justin_smithfunctional composition (though here it is technically function application, middleware application acts like a composition of functions)
11:14justin_smithdomgetter: the general shape is (fn middleware-f [f] (fn [x] (post-process (f (pre-process x)))) - you can optionally pre-process x before f sees it, then you optionally post-process the result before it is returned
11:14justin_smithand you take f and return a new function with that pre/post processing
11:14domgetterokay. That all makes sense. I'll ruminate on that for a while, thank you
11:31favetelinguisnot sure how to ask since i have limited understanding but im reading about piplines in core async and would like to do somethings like this "ch-in -> stateful-pipeline -> out, that is having the pipline remember what has been processed before, now my questions is if this is possible using only channels and transducers or if i have to put a stateful go-loop into the pipleine dealing with the state?
11:33favetelinguisthen it would be like "ch-in -> ch-with-transducer1 -> go-loop with state -> some-more-transducer -> out-ch"
11:34favetelinguismy thinking is that if i need state i might just as well use a transducer in the go-loop instead of putting then on pipeline channels...
11:35BRODUSwell transducers can be stateful
11:36domgetter(take 4) returns a stateful transducer: https://github.com/clojure/clojure/blob/clojure-1.7.0/src/clj/clojure/core.clj#L2738
11:37domgetterDo you have to use volatile! to do stateful transducing?
11:48favetelinguisfound some slide about using volatile! to store state in transducers, should fit my needs, thanks
14:03lokienHow to get every second element of a vector?
14:05Bronsalokien: take-nth
14:05lokienBronsa: thanks
14:56lvhdomgetter: no, but it makes a lot of sense because it's more performant than many of the alternatives
14:57lokienHow to take n first letters from a string? Is there a prettier way than (str (take n string))?
14:57lvhdomgetter: a stateful transducer can do whatever it wants, including store some state in java/JS
14:57lvhlokien: you could try some string methods
14:57lvhthere's also subs
14:57lvhlokien: (subs s start end)
14:58lokienlvh: clojure.string? nothing useful (or I can't search properly)
14:58lvhlokien: subs is in core
14:58lokienlvh: subs is a thing I was looking for, thank you
15:02tuddmanI have http://clojure.org/cheatsheet bookmarked. has str functions. plus, well, everything else.
15:03MJB47there also this version: http://jafingerhut.github.io/cheatsheet/clojuredocs/cheatsheet-tiptip-no-cdocs-summary.html
15:03MJB47which has better search imo
15:03MJB47though ctrl-f is a thing
15:04tdammersctrl-f is my bread and butter
15:04tdammersor rather, /
15:04tdammersunless a website chooses to break it
15:05lokienum, thanks
15:05lokienI'll bookmark it too
16:31lokienWhat can we do for large number readability? Something like 2_000_000
16:34MJB47if its only 0's
16:34MJB47then 2e6 is an option
16:36lokienwhat if it's not only 0's?
16:49gfredericks2e6 is bad since it gives you a float
16:50gfredericksI don't think there's anything basic for this
16:50gfredericks,(type 2e6)
16:50clojurebotjava.lang.Double
16:55ridcullymake it a const and never look at it again?
17:15lokienHow to check if an item appears twice in a row in a string (or a seq)?
17:15lokien"somestring" -> false ; "someestring" -> true
17:18justin_smith,(some (partial apply =) ((comp (partial apply map list) (juxt identity rest)) "somestring"))
17:18clojurebotnil
17:18justin_smith,(some (partial apply =) ((comp (partial apply map list) (juxt identity rest)) "someestring"))
17:18clojurebottrue
17:18justin_smiththat probably isn't the best way to do it, but it was fun
17:19MJB47i was gonna use loop/recur
17:19MJB47idk whats simpler
17:19lokienuh, now I'll spend another 3 days trying to figure out how your function works, justin_smith
17:20lokienbut thanks
17:20gfredericks,(defn repchar? [s] (->> s (partition 2 1) (some #(apply = %))))
17:20clojurebot#'sandbox/repchar?
17:20gfredericks,(repchar? "somestring")
17:20clojurebotnil
17:20gfredericks,(repchar? "someestring")
17:20clojurebottrue
17:20lokien:o
17:20lokienjustin_smith depositioned
17:21justin_smithgfredericks: wrote the same function, he just gave you the readable version
17:21gfredericks~justin_smith is the unreadable version of gfredericks
17:21clojurebotIk begrijp
17:22TMAjustin_smith: that's not certain. while yours is transparent, gfredericks' is somewhat opaque [at least or me]
17:22MJB47i find gfredericks much easier to read and understand
17:23lokienI find both of them confusing :^(
17:23gfredericksI find things in my pockets sometimes
17:23lokienlucky you
17:24lokienif they aren't snakes, of course
17:25gfredericksugh pocket snakes are the worst
17:25lokienstill better than NPEs, duh
17:26gfredericksNullPocketException
17:26justin_smith (try (frob x) (catch PocketSnake S ...))
17:29lokienI'm curious.. justin_smith, why do you only use one liners here? no defns, always anonymous functions
17:30justin_smithlokien: that is much simpler in irc
17:30justin_smithalso, it's easier to put a one liner in a function, than it is to take one out of one
17:30justin_smithlokien: and also "one liner" - clojurebot only accepts a line at a time
17:30lokienjustin_smith: much harder to put it into code
17:31lokienjustin_smith: but you still could write them with defn
17:31MJB47i feel like that just adds uneeded bloat
17:31justin_smithexactly
17:31MJB47they are implicit when needed
17:32justin_smithwhy send two things to clojurebot when you can show what's needed with one
17:32MJB47everyone knows how defn works
17:32MJB47so why not
17:32lokienmaybe it's easier to fit if one has more complex functions, my are like 10 lines or less
17:32lokienMJB47: I think you're right
17:45justin_smithalso, clojurebot erases all def and defns once every 15 minutes or so, so using def / defn isn't reliable
17:49TEttingerdown to under 256 characters, btw, if you just use this to generate a single name of some elder god or great old one or whatever
17:50TEttinger,(let[a #(apply str(flatten %))p partition R rand-nth n #(a(R(mapcat p[1 2 3]%&)))v #(n"aioeu""iaaiaa")](a[(n"STKNYPKLGVZ""GlThShNyFtCh""ZvrCthShrMycTch")(for[_" "][(v)(n"lpstnkgxzv"(concat[(R["h""gl""gr""nd"])(v)]"rnthggghtsltrkkhshng")"ghnlok")])]))
17:50clojurebot"Zerkiarn"
17:50TEttingeryou were discussing illegibility?
17:52TEttingerah, lokien left, but for strings I'd use (partial re-find #"(.)\1")
17:52justin_smithoh, good point
17:53TEttinger,((partial re-find #"(.)\1") "somestring")
17:53clojurebotnil
17:53TEttinger,((partial re-find #"(.)\1") "someestring")
17:53clojurebot["ee" "e"]
17:53MJB47if its only a string then yer thats the best way
17:53MJB47but he asked for seq as well iirc
17:53TEttingersurprised gfredericks, lord of the regex, didn't point that one out though
17:53MJB47oh i didnt read up
17:53MJB47my bad
17:57TEttinger,((partial reduce #(if (= %1 %2) (reduced true) %2)) "someestring")
17:57clojurebottrue
17:57TEttinger,((partial reduce #(if (= %1 %2) (reduced true) %2)) "somestring")
17:57clojurebot\g
17:58TEttingerhm, should be nil then
17:58justin_smith,((comp true? (partial reduce #(if (= %1 %2) (reduced true) %2))) "somestring")
17:58clojurebotfalse
17:59justin_smith,((comp true? (partial reduce #(if (= %1 %2) (reduced true) %2))) "someestring")
17:59clojurebottrue
17:59TEttinger,((comp not (partial reduce #(if (= %1 %2) (reduced nil) %2))) "someestring")
17:59clojurebottrue
17:59TEttinger,((comp not (partial reduce #(if (= %1 %2) (reduced nil) %2))) "somestring")
17:59clojurebotfalse
18:00TEttingerthe only case this fails is with justin_smith
18:00TEttingerthe only case this fails is with justin_smith's and a collection that contains true, or mine and a collection that contains nil
18:01TEttingermine also fails if the collection contains false
18:01justin_smith,((comp boolean #{::doubled} (partial reduce #(if (= %1 %2) (reduced ::doubled) %2))) "someestring")
18:01clojurebottrue
18:02justin_smithinstead of ::doubled you could use a gensym
18:06ToBeReplacedjust a FYI to community; i haven't written clojure in about a year, i tried to add cider-nrepl 0.9.1 to my lein plugins, and there seems to be no way to start a REPL once i do that if i have :pedantic? :abort set
18:06ToBeReplacedthis gives me a sour taste and makes me less likely to want to pick it up again commercially
18:07ToBeReplaced0.10.1 sorry
18:08TEttingerI don't use cider, lots of people in here do
18:09TEttingerjustin_smith: there's a neat property here too. the collection can't contain itself as an element can it?
18:09TEttinger,(map (fn [coll] (= coll (reduce #(if (= %1 %2) (reduced coll) %2) coll))) ["someestring" "somestring"])
18:09clojurebot(true false)
18:09ToBeReplacedyeah, maybe the tech has moved and i should be looking at different tooling; the issue is they ask for different versions of org.clojure/tools.nrepl (and no way to exclude what lein asks for)
18:10TEttingerthey?
18:10TEttingercider?
18:10clojurebotcider is Cider is unstable and broken right now, most things don't work. Use the last stable version of nrepl.el for now.
18:10TEttingerhaha
18:10TEttingerthanks clojurebot
18:10TEttingernot sure if that's still true
18:10ToBeReplacedhaha, "they" referred to lein vs. cider-nrepl
18:11justin_smith,(def a (promise))
18:11clojurebot#'sandbox/a
18:11justin_smith,(deliver a (delay [@a]))
18:11clojurebot#error {\n :cause "Unable to resolve symbol: a in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: a in this context, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6688]}\n {:type java.lang.RuntimeException\n :message "Unable to resolve symbol: a in this context"\n ...
18:12justin_smith,(def a (promise))
18:12clojurebot#'sandbox/a
18:12justin_smith,(deliver a (delay [@a]))
18:12clojurebot#object[clojure.core$promise$reify__6999 0x307cdb5b {:status :ready, :val #object[clojure.lang.Delay 0x6ae97dd4 {:status :pending, :val nil}]}]
18:12TEttingerwhat's this?
18:12justin_smith(= @a @(first @a))
18:12justin_smith,(= @a @(first @a))
18:12clojurebot#error {\n :cause "Don't know how to create ISeq from: clojure.lang.Delay"\n :via\n [{:type java.lang.IllegalArgumentException\n :message "Don't know how to create ISeq from: clojure.lang.Delay"\n :at [clojure.lang.RT seqFrom "RT.java" 542]}]\n :trace\n [[clojure.lang.RT seqFrom "RT.java" 542]\n [clojure.lang.RT seq "RT.java" 523]\n [clojure.lang.RT first "RT.java" 668]\n [clojure.core$firs...
18:12justin_smith:P
18:12justin_smith,(= @@a @@(first @@a))
18:12clojurebot#error {\n :cause "clojure.lang.PersistentVector cannot be cast to java.util.concurrent.Future"\n :via\n [{:type java.lang.ClassCastException\n :message "clojure.lang.PersistentVector cannot be cast to java.util.concurrent.Future"\n :at [clojure.core$deref_future invokeStatic "core.clj" 2205]}]\n :trace\n [[clojure.core$deref_future invokeStatic "core.clj" 2205]\n [clojure.core$deref invokeSt...
18:12justin_smithergh
18:13justin_smiththere must be a way!@
18:13TEttinger@
19:11tolstoyToBeReplaced: Did you resolve your issue? All I do is add tools.nrepl to the :dev profile and It Works.
19:51ToBeReplacedtolstoy: i did not resolve; is that true with :pedantic? :abort
19:52tolstoyHm. I've never head of :pedantic?; Is that a lein thing?
19:52tolstoyI do run "lein deps :tree" all the time.
19:52slesternot exactly clojure related, but just curious how you all come up with side projects to work on
19:53slesterI've just been fiddling with 4clojure and advent of code and I can't really think up a good project to test my chops
19:53ToBeReplacedyes, it's a feature to puke when dependency ranges are detected
19:54tolstoyToBeReplaced: I just added it to my project, and "lein deps :tree" still works. What does that key prevent?
19:54tolstoyToBeReplaced: I actually never put stuff in ~/.lein/profiles.clj. I just keep it all in the project file. Maybe that's it?
19:54ToBeReplacedtolstoy: can confirm that adding tools.nrepl to :dev profile instead of :user profile makes a difference
19:55tolstoyAh, good!
19:55ToBeReplacedif i add to :dev in the project.clj, it accepts; fails if i add to :user in a profiles.clj
19:55ToBeReplacedmagic ;)
19:55tolstoyIs it possible to add a :dev profile to profiles.clj?
19:56ianhedoesitslester: I think a reasonable approach to start with is to just make things that already exist. thinking of truly unique and novel ideas isn't something that's easy (or something that everyone can do)
19:56tolstoyslester: For a long time, my side projects were side projects for work. Not sanctioned, just stuff it would be cool to use. In other words, that's where I found problems to solve.
19:57slesterianhedoesit, tolstoy, good advice!
19:57ToBeReplacedtolstoy: you can, yes... you're not meant to due to collisions
19:57tolstoyslester: Wouldn't it be cool to have drag/drop configuration for security scans? ;; That would get me into OM, etc.
19:58tolstoyToBeReplaced: Ah. The reason I abandoned profiles.clj is that I wanted things to be explicit and for old projects to be self-consistent.
19:58ToBeReplacedit's a little weird because it *should* be in :user not :dev since it's meant to be for any project i work on... really i should just issue a PR to leiningen to update it's version of tools.nrepl
19:58ToBeReplacedyeah; i totally get that... better for repeatability of the dev environment if your whole team uses the same environment as well
19:58tolstoyToBeReplaced: When working with others, no one cared because they didn't use Emacs, or didn't use the plugins (like lein ancient, etc). In other words, no impact on anyone else.
19:59ToBeReplacedmakes sense
20:00tolstoyI figured that if anyone cared, I could just maintain a local project.clj and never commit it, or something.
20:00tolstoyANYWAY, I think Cider is really good these days.
20:00tolstoyI really like the C-c C-p to pop-up an evaluation of an expression into a read-only buffer.
20:03tolstoyAnd I set the toggle so that buffer is pretty-printed.
20:04tolstoyVery light-tableish. ;)