#clojure logs

2015-06-28

07:05mmeixjust found https://atom.io ... looks interesting. Unfortunately can't get the nrepl package to do anything so far ...( https://atom.io/packages/nrepl ) - anyone tried this?
07:11kwladykammeix, light table could be also great but it looks like author abandon this project? who know what will happen with atom.io... i don't like immature projects anymore :)
07:24mmeixLight Table I'm just using now
07:34ifiesHello #clojure! I'm trying to insert something into a vector at a certain position. I want to transform [\a \c] into [\a \b \c]. I'm trying with (assoc [\a \c] 1 \b), but that only 'changes' the \c into a \b (returning [\a \b]). In Javascript I would (have to) write something like `myArr = ['a', 'c'] ; myArr.splice(1,0,'b') ; return myArr;`. Is it not possible to to this in a Clojure vector?
07:51rritochifies: There are many ways of doing it, one way which isn't too painful is (reduce into [(subvec myvec 0 idx) [invalue] (subvec myvec idx)])
07:52rritochifies: Where myvec is the starting vector, invalue is what your trying to insert, and idx is where you want to insert at.
07:55profilis it possible to merge two core.async channels' output and input? I want to combine the input from channel 1 with the output from channel 2. If I take from my combined channel, it should take from channel 1, and if I put it should put to channel 2.
07:56profilDoes this exist or do I have to use reify to get what I want?
08:06kwladykahttps://www.refheap.com/104534 <- which function should i use to solve that?
08:06kwladykain most elegant way :)
08:08rritochprofil: How is that any different than pipe? I think I just misunderstand your question.
08:09rritochprofil: http://clojure.github.io/core.async/#clojure.core.async/pipe
08:12profilrritoch: Internally I have read-ch and write-ch. read-ch is written to when data is incoming on a websocket connection, write-ch is used to send data over the websocket. I want to combine read-ch and write-ch into ch so that when i do (<! ch) it runs (<! read-ch) and when I do (>! ch) it runs (>! write-ch)
08:15profilrritoch: I am thinking about solving it like this, https://www.refheap.com/104535
08:15profilops, it should be a WritePort in there aswell
08:17rritochprofil: You know, that is a difficult challenge in any language. I think your going to end up using reify because you need your socket using one API, and your socket user using a different API. At least that's how I've solved it in other languages. Like users call read/write but the socket listener/writer calls readLow/writeLow
08:32profilrritoch: I did it like this, https://www.refheap.com/104536
08:32profiljust need to test it :)
08:35rritochAnyhow, I'm heading out, I just wanted to let clojure dev's know that the Java docs are apparently not so accurate. >> https://github.com/openjdk-mirror/jdk/blob/jdk7/jdk7/master/src/share/classes/java/lang/Double.java#L507-L522 Last I saw clojure source it was using valueOf boxing for optimization purposes, but it turns out that the optimization claimed by the documentation doesn't exist
08:35rritochAt least not in openjdk.
08:36rritochIt was recently pointed out to me when someone asked why I was using the valueOf method.
08:36Bronsarritoch: the documentation doesn't guarantee the optimization to exist
08:37rritochBronsa: Sure, but it's VERY misleading, since calling the constructor directly should technically be faster on any implementation that doesn't have it optimized.
08:39rritochBronsa: It should at least have a cache of 0.0 since it is the most common value... anyhow. It doesn't, so optimizing based on the documentation seems to be futile.
08:40rritochI've been running into similar issues with tomcat, where the documentation says one thing, and the code does something completely different.
08:41Bronsarritoch: http://code.metager.de/source/xref/openjdk/jdk8/hotspot/src/share/vm/ci/ciMethod.cpp#1305
08:45Bronsarritoch: so it might not be cached but it seems to be used for certain unboxing optimizations
08:47ifiesrritoch: Thank you! That is just what I needed. I didn't know the subvec function, thanks for showing me! Imho the code you wrote should be in clojure.core...
08:47Bronsarritoch: hotspot will take care of inlining the /valueOf method call when necessary anyway so there's really no point in thinking about it
08:47rritochifies: lol, thanks. Been down that route before though, I'd rather pull out my own teeth with pliers than make another code submission to clojure.
08:49rritochBronsa: Well it is certainly interesting. I've run into many cases where opimizing large amounts of doubles is important, such as video processing.
08:55drwindnolen: FYI playing with cljs-bootstrap to give me ASTs for arbitrary files, want to use it in my experimental structural cljs editor: https://github.com/darwin/quark/blob/master/cljs/src/base/quark/cogs/editor/analyzer.cljs
08:56drwinlooking forward to have some equivalent of 'analyze-file', right now it gives me only very basic ASTs, no requires work for me
08:56dnolendrwin: cool!
08:57rritochBronsa: My big question thats unanswerd regarding array optimization and isn't really documented as far as I can tell is how much memory does an object pointer use in a typical implementation. If the object pointer is 64 bits, and your cached double is 64 bits, than the object pointer and the native value use the same amount of ram so there's really no potential for optimization via caching values
08:57dnolendrwin: not sure about supplying analyze-file as it will look differently everywhere
08:57dnolenio, file resolution, etc. there not a good way to make this work consistently across all JS targets
08:58dnolenand I'm not really interested in it myself.
08:58dnolensince once you have a bootstrapped thing you can go sort it out on your own.
08:58rritochBronsa: But if the underlying system is using 32 bit object pointers, than caching double objects in an array should use less ram.
08:58drwindnolen: I'm happy to reimplement it for my editor-use-case, just wanted to ask if analyzer can work if I implement it, I'm not fully aware of the state of analyzing in cljs
08:59dnolendrwin: what do you mean "state of analyzing in cljs"?
09:00TMArritoch: sun-jdk has X-bit object pointers in their X-bit versions. I assume openjdk and other JVMs do the same
09:01drwinI understand that you are in the process of adapting compiler infrastructure to be bootstrapped in js, my code will be cljs-only, so I need to analyzer to work without clojure. I'm not sure if it is possible at this point
09:02drwinI could rewrite analyze-file and friends (dependency resolution using nodejs fs apis, etc.), but I'm not sure if don't hit wall because some parts of clojurescript analyzer are not yet ported to cljs
09:02TMArritoch: as a rule of thumb: a 64-bit JVM instance takes approximately double the amount of RAM for the same program as the 32-bit ones
09:03drwinI'm not interested in emitting at this point, just analyze
09:04dnolendrwin: bootstrapping isn't involving changing anything about the analyzer and the compiler
09:04dnolenit is the exact same compiler, exact same analyzer
09:04dnolendrwin: everything works
09:04rritochTMA: Thanks. That is very helpful, it implies that caching is only useful when the amount of cached data > architecture size, so caching complex numbers or Big* numbers would save ram, but anything smaller than architecture size is better as native values.
09:04dnolenthe only place things get tricky are the bits that need I/O
09:04Bronsadnolen: cljs-bootstrap -- no need for your t.r fork. the CLJS-1303 branch in t.r should work
09:05dnolenanalyzing dependencies right now, loading files
09:06drwindnolen: ok, I'm happy to hear, so in theory if I dive into it I could be able to get ASTs from any cljs file
09:06dnolendrwin: my test case is analyzing the entire standard library
09:06dnolenso that better work :)
09:07dnolenBronsa: noted, I couldn't remember which branch it was
09:08drwindnolen: when I eval more complex code I'm getting: "Cannot use 'in' operator to search for 'defn' in null", didn't investigate it yet, will have to first try to understand how namespaces are resolved and recorded in the compiler env
09:10dnolendrwin: right the way you have to deal w/ macros at the moment is a bit manual not generalized
09:10dnolenI would hold off unless you're brave enough to dig into how the analyzer/compiler works and how the bootstrapped thing has to be different accordingly in certain areas.
09:13drwinshould I store their defs in related.namespace.name$macros? I saw some new switch logic
09:13drwinI have to start somewhere, I'm gonna try, in the worst case I'll just fail :)
09:16dnolendrwin: yes we rewrite macro namespaces so that macro nses and runtime nses can appear to reuse symbol names.
09:25rritochIs it possible to disable the clojure security manager? Unlocking some of the final values in clojure's core via reflection would be a way that I could run clojure customizations without needing to run an actual fork of clojure.
09:27rritochAlternativly I was thinking of just loading clojure with a custom classloader that strips all finals which would open up unlimited customization potential, but for my purposes right now just unlocking finals would be enough.
09:28Bronsarritoch: what is clojure's security manager?
09:32mmeix(not to disturb the high-level discussion: do we have a bot in #clojure-beginners, for demonstration purposes? like this:
09:32mmeix, (filter even? (range 7))
09:32clojurebot(0 2 4 6)
09:33mmeix(maybe with another start symbol?)
09:33rritochBronsa: I honestly don't know, I haven't dug that far into the issue. I just know that clojure's security manager yells at me if I try to access finals.
09:33ImportanJoe,((comp (partial apply +) reverse (partial filter even?)) (range 7))
09:33clojurebot12
09:35rritochBronsa: Nevermind. I guess I was just doing it wrong
09:36ImportanJoe,((comp (partial apply + reverse filter even?) (range 7))
09:36clojurebot#<RuntimeException java.lang.RuntimeException: EOF while reading>
09:36ImportanJoe,(comp (partial apply + reverse filter even?) (range 7))
09:36clojurebot#object[clojure.core$comp$fn__4493 0x660bbc9a "clojure.core$comp$fn__4493@660bbc9a"]
09:36rritochBronsa: THis worked... (let [x (.getDeclaredField String "value") y "foo"] (.setAccessible x true) (.set x y (.get x "bar")) y) so I just need to be more careful with the types when accessing finals.
09:52rritochBronsa: Actually, I was able to fire the security manager
09:53rritochBronsa: With (let [x (.getDeclaredField clojure.lang.Namespace "namespaces") y (java.util.concurrent.ConcurrentHashMap.) (.setAccessible x true) (.set x nil y))
09:54rritochBronsa: There was a ] after the ConcurrentHashMap.)
09:55rritochBronsa: But I think this may still be a typing issue, since I didn't create a ConcurrentHashMap<Symbol, Namespace> but I only created a regular ConcurrentHashMap
09:59rritochBronsa: That one literal "final" in that one file is the only reason I stopped using clojure. If I can't isolate namespaces in a way that's compatible with OSGI, I can't use clojure.
10:00rritochClojure is going to have lots of fun with Java 9 which is likely to include OSGI features.
10:07rritochBut then again, maven is probably going to have equal troubles when people have dependencies provided by modules. I haven't yet tried the new features because the documentation is sparce, but I'm fairly sure java 9 is going to break half my libraries.
10:07rritochsparce=sparse
11:08sharmsIf I am destructuring a map, is there a form which lets me add a prefix to those keys? ex { :mfg "something" :version "1" } - I want to do a let [{:keys [:mfg :version]} something] and instead of mfg, I want to alter it to say something/mfg
11:09justin_smithsharms: don't use :keys then
11:09sharmswell there are like 12 fields, so I dont want just a giant let statement
11:09justin_smith,(let [{some-a :a some-b :b} {:a 0 :b 1}] some-b)
11:09clojurebot1
11:09justin_smithalso, you can't create a binding in a let that has a / in the middle
11:10sharmsthey would all be keywords like :newprefix/mapkey
11:10sharmsI am just trying to insert a map into datomic with the proper namespace
11:10justin_smith,(let [{:keys [a]} {:whatever/a 0}] a)
11:10clojurebotnil
11:10justin_smithhmm
11:10clojurebotExcuse me?
11:10crockethi
11:11justin_smith,(let [{:keys [whatever/a]} {:whatever/a 0}] a)
11:11clojurebot0
11:11crocketIf a transaction refers to a ref named 'hobbit', does the transaction obtain the snapshot of hobbit as of the start of transaction or the first read of hobbit in the transaction?
11:12sharmsat the end of that statement, 'a', I want :newprefix/a to be that
11:12justin_smithsharms: so you want to generate a new keyword, not bind the keyword's value?
11:12sharmsI want the value which was in the map bound to it
11:13justin_smithyou can't bind values to keywords, closest you can get is use them as keys with the val attached
11:13sharms(defn add-hardware [hardware]
11:13sharms @ (d/transact conn [{:db/id (d/tempid :db.part/user)
11:13sharms :hardware/mfg (:mfg hardware)
11:13sharms :hardware/model (:model hardware)
11:13sharms :hardware/version (:version hardware)}]))
11:13sharmsthat is basically what I am trying to do
11:13justin_smithsharms: don't do that
11:13justin_smithuse a pastebin
11:14crocketjustin_smith, ^^
11:14sharmsbut hardware has like 12+ fields, so I didnt know if there was an easy way to remap it all to :hardware
11:14justin_smithsharms: OK, this has nothing at all to do with destructuring then, you just want to rename a bunch of keywords in a hashmap
11:15mmeixcouldn't you use something like {:hardware {:model ... :version ...}} ?
11:15justin_smith,(into {} (map (fn [[k v]] [(keyword "hardware" (name k)) v]) {:a 0 :b 1 :c 2})
11:15clojurebot#<RuntimeException java.lang.RuntimeException: EOF while reading>
11:15justin_smith,(into {} (map (fn [[k v]] [(keyword "hardware" (name k)) v]) {:a 0 :b 1 :c 2}))
11:15clojurebot{:hardware/a 0, :hardware/b 1, :hardware/c 2}
11:15crocketWhat is the read point of a transaction?
11:16crocketdocumentation at Clojure.org states "All reads of Refs will see a consistent snapshot of the ‘Ref world’ as of the starting point of the transaction (its ‘read point’)."
11:16justin_smith^^ sharms that's what you want (probably with a select-keys then merge)
11:16justin_smithcrocket: the transaction locks the refs
11:16sharmsmmeix - tried that and it only has the keywords present, but nothing bound to them
11:16justin_smithcrocket: other parts of your code have to wait until the transaction is done
11:16crocketat the start of a transaction? or at the first read of a ref in a transaction?
11:17sharmsjustin_smith: thanks I will give that a shot
11:17crocketI want to know when a ref is locked in a ref.
11:17crocketat the start of a transaction or at the first read of a transaction.
11:17justin_smithcrocket: the transaction locks all refs and agents that it accesses
11:17justin_smithat the start
11:18justin_smithcrocket: the compiler makes a note of all refs and agents that are accessed when compiling the transaction form
11:18crocketIf a transaction locks all refs and agents in the beginning in advance, it means the transaction knows which refs and agents it accesses in advance. Right?
11:18crocketVery cool
11:18justin_smithright, because it compiles the form
11:18justin_smithclojure is not an interpreted language (though you can fake it with things like trampoline)
11:19crocketThanks
11:20sharmsjustin_smith: that did work thanks, that really helped with respect to understanding destructuring vs manipulation of a map
11:21crocketIs it ok to apply commute and then alter to a ref in a transaction?
11:22crocketWill it lead to infinite retries?
11:22justin_smithoh, wait - do transactions lock or retry?
11:23justin_smithcrocket: I was wrong http://clojure.org/refs#Refs%20and%20Transactions this is the real info
11:24crocket??
11:24clojurebot? is suddenly
11:25crocketok
11:25justin_smithcrocket: transactions do not lock, they retry, it doesn't matter how many alterations or commutes are inside your transaction, the retry happens iff any of those refs changed outside the transaction while you were working
11:25crocketIf I apply commute and then alter to a ref in a transaction, I encounter an exception.
11:25justin_smithcrocket: interesting, you should be able to do both
11:25crocketI can't alter a ref after applying commute to a ref.
11:26crocketClojure programming says "The unique semantic of alter is that, when the transaction is to be committed, the value of the ref outside of the transaction must be the same as it was prior to the first in-transaction application of alter. Otherwise, the transaction is restarted from the beginning with the new observed values of the refs involved."
11:27crocketThus, commute should be able to break alter...
11:28justin_smithcrocket: when the transaction is commited
11:28justin_smithif both are inside the transaction, the commit hasn't happened yet
11:29crocketI think "clojure programming" got it wrong.
11:29justin_smithcrocket: no, it's correct. It's talking about inside the transaction vs. outside, both modification happen inside the transaction, that should work
11:30crocketjustin_smith, Anyway, I can't alter after commute.
11:30crocketAlter wants to be the first one to alter a ref.
11:31crocketIf you apply alter, commute, and alter in the exact same order to a ref, you encounter an exception.
11:31crocket"can't set after commute"
11:32crocketcan't alter after commute
11:34justin_smithinteresting, yeah, commute does something weird there...
11:34justin_smithbut that's not because of the out-of-transaction value changing
11:35crocketjustin_smith, Are you sure the value of every ref is snapshot at the start of a transaction?
11:35justin_smithcrocket: absolutely, that's what drives retries
11:36crocketok...
11:39justin_smithcrocket: it compiles the transaction form, captures the values of all refs accessed, then runs the transaction (but none of its changes are visible outside the transaction yet). If none of the refs changed in value in the meantime, all the changes to the refs are applied atomically
11:39crocketjustin_smith, http://ibin.co/26o26cO39gvZ fooled me.
11:39crocketIn the figure, t2 reads the value of a ref in the middle.
11:40justin_smithcrocket: yes, and that a1 != a2 shows the retry condition being calculated
11:41justin_smithcrocket: t2 is not reading, it is changing a2
11:41crocketThe figure makes it sound as if there would be no conflict if t1 read a after t2 commited.
11:41crocketThe figure makes it sound as if there would be no conflict if t1 read 'a' after t2 commited.
11:41justin_smitht1 does all its reads at once (at the start)
11:41crocketSo does t2?
11:42crocketIt seems the author fooled a lot of people.
11:42justin_smithright, but t2 started and completed it's alteration of a while t1 was still running
11:42justin_smithwhich means t1 retries
11:44justin_smithcrocket: the official answer to the issue about commute https://groups.google.com/forum/#!msg/clojure/NGiWsqheUjo/9lWI-JBqXo8J
12:05crocketgoing home
13:01jonathanjwhat is the return value of schema.coerce/coercer when there is a coercion/validation failure?
13:02jonathanjapparently it's some value of type `schema.utils.ErrorContainer` but there's nothing that describes how to deal with this, apparently?
13:23justin_smithjonathanj: my instinct would be to check for and handle that type, but maybe there is something more official
14:05nano-Is it possible to configure ring to do http2?
14:07justin_smithnano-: ring is a protocol that various http servers are extended to support, your best bet would be to find out what java / jvm http server supports http2, then look for a ring adapter for that server
14:07nano-Oh, thought ring was a jetty wrapper. I guess I have some reading to do.
14:08justin_smithnano-: well it's a "wrapper" for any http server on the jvm - it's a protocol that makes http servers more convenient to use from clojure
14:08nano-cool, thanks for clearing it out.
17:19ReefersleepHello everyone
17:20ReefersleepI'm trying to get vim-fireplace working with ClojureScript
17:20ReefersleepI've started a lein repl in my project root, I've :Connect'ed to it, I've lein figwheel dev from root, and then, when I do :Piggieback, I get
17:20ReefersleepClassNotFoundException cemerick.piggieback java.net.URLClassLoader$1.run
17:21ReefersleepI've included piggieback and nrepl from my project.clj as per the instructions at the piggieback github repo
17:21ReefersleepSo I can't really figure out what I'm doing wrong :/
17:21ReefersleepI've tried :Piggieback [7888] (the port for my figwheel nrepl) and gotten the same message
17:21ReefersleepSo I figure something's wrong with my piggieback dependency
17:21Reefersleepbut I can't figure out how to clean it
17:23currentoorHas any one here used Datascript on the server?
17:25DomKMcurrentoor: Try asking here https://gitter.im/tonsky/datascript
17:26currentoorThanks!
17:40ReefersleepI think I cleaned it properly just with lein clean
17:40ReefersleepBut now I'm having trouble with the :Piggieback invocation
17:40ReefersleepI don't understand the doc - what are you supposed to write after :Piggieback ?
17:46lodin_I noticed that with-meta forces evaluation of the head of a LazySeq.
17:46lodin_,(let [c (atom 0) _ (with-meta (map (fn [_] (swap! c inc)) (range 100)) {})] @c)
17:46clojurebot32
17:47lodin_Is that strictly necessary?
17:48gfredericksI think so
17:49gfredericksI mean not strictly no
17:49gfredericksbut I think the alternative would add a bunch of checks somewhere
17:49justin_smithlodin_: what if (range) were empty? you can't put meta on nil
17:49gfredericks,(range 0)
17:49clojurebot()
17:49gfredericksjustin_smith: I don't think that's an issue
17:49justin_smithoh, right
17:49gfredericksI'm trying to remember what the real issue is
17:49gfredericksoh right
17:50lodin_I looked at the source, and seq() is called, but at least superficially it seems like you could create a new LazySeq that has meta != null.
17:50gfredericksit's that forcing a lazy seq is a coordinated effort
17:50gfredericksyou don't want to have two LazySeq objects holding the same thunk
17:50gfredericksbecause then they would have to coordinate about who gets to force it
17:51gfredericksso the behavior you're seeing is in service of keeping one LazySeq per thunk-fn
17:51lodin_gfredericks: Ah. I think I understand what you mean.
17:52gfrederickswhich is probably good otherwise every single dang step of realizing a lazy seq would involve making sure nobody else is in the middle of realizing it
17:53gfredericksyou might be able to come up with a high-perf solution to the problem but it would probably be more complex than the current impl
17:56ReefersleepI tried to follow the guide here: http://ofnir.net/posts/make-the-figwheel-repl-work-in-vim-fireplace.html
17:57ReefersleepBut then, when I do the :Piggieback part, I get
17:57ReefersleepCompilerException java.lang.ClassNotFoundException: figwheel-sidecar.repl-api, compiling:(/private/ var/folders/h0/7srrpf416l57gzg3hx9w879c0000gn/T/form-init4543993028774803874.clj:1:83)
17:57Reefersleep:/? Anyone got any ideas?
17:58Reefersleep But then, when I do the :Piggieback part, I get
17:58Reefersleepoh sorry :)
17:59lodin_gfredericks: Btw, have you done any more work on stateless random numbers?
18:03gfredericksI integrated the thing into test.check; now I'm mostly just thinking about other test.check stuff
18:03gfredericksI think the randomness part works as well as it's likely going to
18:04gfredericksI guess it could get moved to a standalone library
18:04gfrederickswhich would entail better API design
18:10lodin_gfredericks: I saw that you made four a couple of years ago, but no plans on updating it then I guess?
18:11lodin_I wrote my own lib that is very similar to four a while back, before I found four, because I really don't like "uncontrolled" randomness. :-)
18:13gfrederickshmm
18:14gfredericksfour was definitely trying to include the immutable RNG thing, but also functions mirroring clojure's random functions but with more control
18:14noogaAnyone used ztellman/gloss? I'm having small problems with it and the doc/src doesn't help :C
18:16gfrederickslodin_: there's a jira ticket around the latter problem, and I'm imagining maybe a contrib library for the immutable stuff
18:44noogaamalloy_: got a minute?
21:19TEttingergfredericks: I'm curious about a better random lib for clojure too
21:21gfredericksTEttinger: mutable or immutable?
21:22TEttingerhm.
21:22TEttingerwith immutable, you would need to pass state around, right?
21:23gfredericksgenerally yeah
21:23TEttingerI can see that being good too...
21:23gfredericksdoesn't have to be a full state monad though if your generator is splittable
21:24gfredericksand I'd say immutability isn't worth much otherwise
21:24TEttingerI've written or copied several RNGs in a java game lib I intend to use eventually
21:25TEttinger(like an RNG that will start generating higher results if it "rolls low" repeatedly)
21:26gfredericksoh so funny distributions
21:26TEttingeryes
21:26TEttingerthey only get funny once a threshold is reached
21:34gfredericksa bit like a 1-bit-generator than never returns the same result more than seven times in a row
21:36gfredericksI guess it's more than a funny distribution, since the successive results are independent
22:05tomjackreally?
22:08tomjackI imagine taking (repeatedly #(< (rand) 0.5)) and going left-to-right, not'ing an element when all the previous k generated elements match it
22:09tomjackthen (nth xs i) and (nth xs (inc i)) are independent?
22:09TEttingeryou would need to realize it to find what was before, right?
22:09TEttingeror retain head or whatever the term is?
22:12tomjackjust trying to see if I understand the claim "the successive results are independent"
22:38gfrederickstomjack: oh maybe I typo'd that and meant "aren't"
22:39gfrederickssorry for the confusion :(
22:39gfrederickss/maybe/definitely/
23:16l34chanyone working on any interesting open source projects?