#clojure logs

2016-03-03

02:51qsysHow do clojurists organize large projects with respect to DIP? Having different 'levels' in a large application, where d'you use 'high order function injection', protocols, multimethods, core.async, ... to comply dependency inversion?
03:05ridcullycomponent and mount are popular choices
03:12qsysyeah, component does not really come for free... it feels too much 'you have to do it this way', to me. Checked 'mount', it's more about state management, isn't it?
04:21zipperWhat are plugins in a project.clj?
04:22zipperWhat would a :ring key mean in a project.clj?
04:22zipperHere's the file https://github.com/weavejester/compojure-example/blob/master/project.clj
04:28CStorm@zipper
04:28CStormread here: https://github.com/weavejester/lein-ring
05:02zipperCStorm: Thanks
05:52KeksikeI have a JSON in my clojure. This JSON has an array inside it. I'm using cheshire to select fields from the JSON. How can I map/iterate/for through the array-field in the JSON?
05:53Keksikewhen I tried mapping it, it mapped every single letter in the json rather than every object in the array
05:54KneivaKeksike: have you parsed the string into a map?
05:54Gonzihdid you get completely parsed data structure?
05:54Keksikeill give you a gist example of the data
05:58Gonzihbetter show your code, i think you are parsing it incorrectly
05:58Keksikehttps://gist.github.com/Keksike/c99a112d79de7ba8508a here, so I basically want to map the objects inside the events field
05:59Keksikewhat I did was '(map mapperFunction (get-in (parse-string myJson) ["events"]))'
05:59Keksikethe mapperfunction got every letter as a parametre
05:59Keksikeso mapperFunction was ran like a hundred times
06:00Keksikealthough there is only two objects inside the events array
06:01KeksikeKneivo I dont think so
06:03KneivaKeksike: in plainjson.txt the event value is a string not an array
06:05KeksikeKneiva: what should I do, other than using Cheshire parse-string?
06:06ridcully,(get-in [:a :b] ["events"])
06:06clojurebotnil
06:07Keksikeridcully: I didnt quite catch that
06:07Keksikesorry, im quite new with clojure :)
06:08KneivaKeksike: Can you change the input (plainjson) so that it actually has an array instead of a string representation of an array? If not the you can parse the input and the parse again the value of "events".
06:09KeksikeKneiva: I'm not sure if I can. I'll try to find out.
06:10KeksikeKneiva: so something like this might work?: (debug (get-in (parse-string (parse-string myJson) ["events"])))
06:11Kneiva(parse-string (get (parse-string myJson) "events"))
06:11Keksikeah
06:11Keksikewhats the difference between get and get-in btw
06:12KneivaKeksike: Also you can turn the keys into keywords for easier access: (parse-string (:events (parse-string myJson true) true)
06:13Kneivaoops, missing one )
06:13Keksikedo I have to do something to make that work?
06:14KneivaNope. But it's nicer. (get data "events") vs. (:events data)
06:15Keksikeyeah its alot nicer! :) thanks
06:20KeksikeI got that working! :)
06:21Keksikeanother question, about map though
06:21Keksikeif I want to send a 'static' param to map, what should I do
06:21Keksikeso basically I want to send two parametres to the map function, one which is an array to map and another which is just a string that is needed in the map function
06:31KneivaKeksike: You want to add stuff to a map?
06:32KeksikeKneiva: nah, I just want to give my map function (map delete-one-event (parse-string (:events (parse-string events true) true))))
06:32Keksikea second parametre (in addition to the array)
06:32Keksikethe delete-one-event function that is
06:36KneivaKeksike: Can you give an example again of what is the input and what is the desired output?
06:36sunset-shimmerhello
06:37KeksikeKneiva: this is an example of what I want to basically do, but this doesnt work https://gist.github.com/Keksike/6d597c568f8b10e5470c
06:37sunset-shimmercan you tell me please where I can put commands that should be injected in the nrepl after connection via lein
06:37Keksikeso the chainId is just a plain string
06:37Keksikewhich I want to send to the delete-one-event function
06:39sunset-shimmerin the project.clj in figwheel settings
06:44KneivaKeksike: You can use partial on delete-one-event. Btw. Your example is missing the ) I forgot from my example. It should be like this: (parse-string (:events (parse-string events true)) true)
06:45Keksikeyeah its on different row accidentally
06:45Keksikecan you give me an example of using partial here? or I can just google :)
06:51Kneivahttps://clojuredocs.org/clojure.core/partial
07:28Keksikewoo I got it working, thanks alot Kneiva!
07:28Keksikeim starting to like clojure
07:29Keksikethough my working with it is still extremely slow
07:30KneivaKeksike: np
07:44renlHi do people use clojure in robotics in any form?
07:48kwladykarenl the answer is the same if they use Java.
08:23MasseRrenl: yes
08:23MasseRrenl: finnish firm zenrobotics is a clojure firm
08:58oracleI have the following map. And give a parameter of sex, need to pickup the user without the most money for that sex. How to do it?
08:58oracle
08:58oracle{:user1 {:money 400 :sex :male}
08:58oracle:user2 {:money 300 :sex :female}
08:58oracle:user3 {:money 200 :sex :male}
08:58oracle}
08:58oracle
08:58oracle
08:58oracle
09:16mpenet:gender would be a nicer key name :>
09:16mpenet(sort-by (comp :money val) {...})
09:18jgertmam i correct in assuming that core.logic/membero doesnt work with sets?
09:59patham9hi
09:59patham9how do I get IntelliJ to overwrite the old definitions in REPL on "send to repl"?
10:02patham9ah found
10:35cortexmani am getting Caused by: java.util.concurrent.ExecutionException: java.lang.IllegalArgumentException: :db.error/lookup-ref-attr-not-unique Attribute values not unique: :some/id
10:35cortexmani have confirmed that the attribute value is unique
10:35TimMcMasseR: I was seriously considering applying to them. :-)
10:55solatisehrm, noob question
10:55solatisi'm having a vector
10:56solatisbut the standard sequence functions (for example, `for`) don't seem to work on it
10:56solatisis that by design? or am i doing something wrong?
10:56Gonzih,(for [i [1 2 3]] (* i 10))
10:56clojurebot(10 20 30)
10:56Gonzihthis works solatis
10:57solatishmmm
10:58solatis,(type [1 2 3])
10:58clojurebotclojure.lang.PersistentVector
10:58solatisi'll be damned
10:58solatisi'm doing something wrong then...
10:58Gonzih,(class [1 2 3])
10:58clojurebotclojure.lang.PersistentVector
10:58Gonzihprobably :)
11:03solatisok, so, i'm doing something stupid, probably:
11:03solatishttps://www.refheap.com/115469
11:04solatisis it because of laziness?
11:04solatiswhat am i missing here
11:06schmiruse doseq instead of for
11:07solatisfinally!
11:07solatisi knew there was something like that
11:07solatisso, for is lazy, because of infinite lists ?
11:07schmirsolatis: also you don't the need the extra '(do...)'
11:07solatisyeah i know
11:08solatisthat's just debugging
11:08schmirsolatis: for is lazy
11:08Gonzihyeah lazy seq
11:08Gonzihyou can also wrap for in to doall call
11:08solatiswhich forces evaluation?
11:08Gonzih,(doall (for [i (range 10)] (prn i)))
11:08clojurebot0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n(nil nil nil nil nil ...)
11:08Gonzihyeah
11:36sunset-shimmerhm... I've created an atom: (defonce test (atom (func-that-returns-lazy-seq param)))
11:36sunset-shimmernow I am trying to reset it but have got only "clojure.lang.Cons cannot be cast to clojure.lang.IAtom"
11:38sunset-shimmerreset with (reset! test (func-that-returns-lazy-seq new-param))
11:38sunset-shimmerdid you know how to handle that?
11:38cortexmanUnable to resolve symbol: !swap in this context
11:39cortexman(def some-atom (atom {})) (defn some-fun [] (let [blah ...] (do (!swap some-attom assoc blah))))
11:39cortexmanwhen i just type !swap in the repl i get the same error
11:40cortexmanoh god, i have it backwards :)
11:40cortexmanit's that damn datalog notation
11:40sunset-shimmercortexman: swap!
11:43kriyative@sunset-shimmer -- test resolves to clojure.core/test, try a different name?
11:44sunset-shimmerkriyative: "test" was chosen just for example purposes, In a real code I have normal name.
11:45kriyative@sunset-shimmer actually, i take that back ... still doesn't explain why the reset! fails
11:45kriyativemaybe the defonce?
11:47kriyativeis it possible you defonced test to something not an atom in your repl?
11:47sunset-shimmerkriyative: good question. I will try it now...
11:48sunset-shimmeryes, seems possible, https://www.refheap.com/ee8ef3eeabce17b7a99c51646
11:49sunset-shimmerwait
11:50kriyativesunset-shimmer: was that value of @test, my question was whether you'd defonce test to be something other than an atom
11:53sunset-shimmerkriyative: no! The same error
11:59cortexmanhow can i get if to return nothing on false
11:59cortexmannot nil - but rather nothing
11:59kriyativesunset-shimmer: is this similar to what you're seeing: https://www.refheap.com/115474
12:01cortexman(if (get @test-atom "balh") "success" do-not-return-anything-not-even-nil))
12:01kriyativesunset-shimmer: if you defonce'd test to be something other than an atom, you'll have to `(def test ...)` to change it back to an atom, at least in the REPL
12:01cortexmanhow to achieve that?/
12:02lumacortexman, there's no way to do that. in clojure, all forms evaluate to some value.
12:02kriyativecortexman: not sure you can do that, every Clojure expression has a value
12:02sunset-shimmerkriyative: yes, it was like an error after the second statement in your example. I see you point, thank you, it helps. But now stupid question: how can I use atom from different namespace, like test-ns/@test-atom (that didn't work)
12:03kriyativesunset-shimmer: @test-ns/test-atom
12:12sunset-shimmerkriyative: great! all works fine now. Thank you!
12:27justin_smithadd -auto
13:06bhsiaowhen you run "lein repl" are you not in the main thread?
13:06bhsiaoapparently glfw windows can only be created in the main thread, is there any way to get around this?
13:07justin_smithbhsiao: the main thread will be the one that launches the repl itself iirc, the process you interact with is a client sending messages over a network socket
13:07justin_smithbhsiao: you could use lein run -m clojure.main and not have the nrepl features, but be in the main thread
13:08cortexmanif i generate my tempids with (d/tempid :db.part/my-partition) i get :db.error/not-a-partition Entity id -1000967 is not in a valid partition. if i instead specify {:db/id ;#db/id[:db.part/mypartition] ...} in my transaction, i get :db.error/datoms-conflict Two datoms in the same transaction conflict
13:09bhsiaojustin_smith: sweet, the clojure.main repl worked
13:09bhsiaowhat does nrepl have that this doesn't besides client/server?
13:10justin_smithbhsiao: readline support, C-c as interrupt of current task rather than kill the process
13:10justin_smiththose are the two big ones
13:10justin_smithreadline being the library that allows convenient command line editing and history
13:11bhsiaohm, rlwrap seems to work so far
13:11bhsiaothe C-c thing is annoying though
13:12bhsiaomight there be any workaround
13:13zeebrahWondering if it's possible to add a method to an existing object (that i created using proxy). Specifically i have a JPanel and i wish to add a method to it
13:13ridcullyalso tab completion in lein repl
13:18justin_smithzeebrah: you can extend a protocol for that Class, but not the specific object
13:19zeebrahjustin_smith: ok, then i'm screwed..
13:20zeebrahdoes that mean you can't compose together things made using proxy?
13:20justin_smithzeebrah: proxy makes a brand new singleton Class
13:21zeebrahwhat i mean is can you proxy something you made using proxy
13:21justin_smithsure but that's making a different Object and a different Class, which wasn't what I thought you were asking for
13:22zeebrahno you're right, im just trying to solve this problem another way now.. i asked a different question initially
13:24zeebrahso how would that look, (proxy [(proxy [javax.swing.Panel] [] ...)) ?
13:25justin_smithzeebrah: wait, why do you even need the two layers of proxy here?
13:25justin_smithyou know a single proxy can implement as many interfaces and protocols as you like, right?
13:25zeebrahjustin_smith: beacuse im trying to avoid copying pasting code
13:26zeebrahso i have a create-modelled-JPanel method and i have a create-closable-JPanel method. now i want to make a composite of those two things without c-p the code
13:26zeebrahi do know that
13:26zeebrahcreate-modelled-and-closable-JPanel
13:27justin_smithoh, I think I was misled by your direct call of proxy inside proxy
13:27justin_smiththis makes more sense if you have a use for both
13:28zeebrahyep
14:07rhg135,(apropos "proxy")
14:07clojurebot(clojure.core/construct-proxy clojure.core/get-proxy-class clojure.core/init-proxy clojure.core/proxy clojure.core/proxy-call-with-super ...)
14:08rhg135I think you can
14:10rhg135There's a function that takes a implementation map and the proxy object and let's you reimplement what it extends
14:10justin_smithrhg135: sure, you could do this with extend even
14:11justin_smithno, never mind that, that changes the protocol to work with that proxy, it doesn't make a new Class
14:11rhg135,(doc proxy)
14:11clojurebot"([class-and-interfaces args & fs]); class-and-interfaces - a vector of class names args - a (possibly empty) vector of arguments to the superclass constructor. f => (name [params*] body) or (name ([params*] body) ([params+] body) ...) Expands to code which creates a instance of a proxy class that implements the named class/interface(s) by calling the supplied fns. A single class, if provided, mus...
14:12rhg135At the end it mentions how it just delegates to functions
14:50fantazois describing a map structure recursive complex or simple?
15:25ShayanjmAnyone know if java.util.regex is an NFA regex implementation?
15:25TimMcfantazo: Can you rephrase?
15:25ShayanjmI'm trying to build a 'compilation layer' for a bunch of regex to assess if any inputs are functionally equivalent - and the only way I can come up with to do that is by comparing the DFAs. Storing the subsequently 'compiled' DFAs and executing them directly would also be nice
15:26TimMcShayanjm: From <http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html&gt;: "The Pattern engine performs traditional NFA-based matching with ordered alternation as occurs in Perl 5."
15:26Shayanjmsweet, now to see if I can poke around and figure out how to build, store, and use DFAs
15:29amalloyi don't beliebe it. if you use any backreferences at all, regexes are too powerful to represent with a [DN]FA, and j.u.regex supports backreferences, so its engine can't be pure DFA
15:33Shayanjmamalloy: that's what I thought too
15:34ShayanjmI'm trying to see where the NFA is actually constructed
15:36fantazoTimMc: say you put a hash into a hash with the key "obj", which itself has a key "obj" which is a hash that has a key "obj". and so on until there is no hash with a key obj.
15:38fantazoTimMc, is that supposed to be complex or simple? I'm riddling around if one proposition I made to my coworkers to use such a description for describing a hierarchy of objects as "too complex".
15:38rhg135"NFA-based"
15:39rhg135X-based usually means not X
15:40TimMcfantazo: When you say hash, do you mean a map?
15:40fantazoTimMc, yes a map.
15:40TimMcfantazo: And do you mean something like this? {"obj" {"obj" {"obj" 5}}}
15:41fantazoTimMc, correct.
15:42fantazothe only difference would be that it would have a couple of more "attributes".
15:43TimMcSo... what's the question?
15:43fantazolike in: {"name" "myself" "obj" {"name" "key" "obj" [{"name" "thing"} {"name" "stuff" {"obj" 5}}]}}
15:43Shayanjmamalloy: is it possible to call a private method on a regex Pattern object arbitrarily?
15:44amalloywhy are you asking me instead of the channel at large?
15:44fantazoTimMc, more the philosophical if such a structure can be considered simple or complex.
15:44rcassidyThat really depends on your thresholds for those considerations.
15:44Shayanjmerr, that too - I tabbed habitually and your name happened to pop up
15:44TimMcI guess I don't really have enough information to say.
15:44amalloyhaha
15:45amalloyShayanjm: anyway, you can do it with reflection if you want
15:54justin_smithfantazo left, but I think it's relevant to bring up the fact that with update-in, assoc-in, and get-in, the complexity of clojure code can stay managable with nesting, though overusing nesting can definitely be one symptom of overengineering, but you can only make that judgment in regards to a specific problem domain and a particular nesting...
16:40WorldsEndlessI have an input stream. What's the easiest way to spit it to a file on disk?
16:44TimMcspit
16:44TimMcwait, might be confused
16:45WorldsEndlessYeah, spit didn't work for me just now
16:45WorldsEndlessI get a file with the name/memory location of "PipedInputStream"
16:46TimMcclojure.java.io/copy might do it
16:46TimMcwith a writer
16:49WorldsEndlessTimMc: Hey! I didn't know about io/copy. With an output stream that worked wonders! thanks!
17:14lumpkinHow do I get an OutputStream for *out* (which is an OutputStreamWriter)
17:29hiredmanthe value of *out* will depend on in what context your code is running
17:30hiredmanclojure by default binds it to something based on System/out, but different repls will bind it to other things
17:31hiredmanso writing to System/out doesn't always write to the same place as repls will print to
17:33lumpkinok tnx
17:49blake__Is it customary to prefix "clj" and "cljs" to your code in a project that has both?
17:49justin_smithblake__: prefix where?
17:50blake__Sorry, namespaces.
17:50blake__cljs.myproject.whatever and clj.myproject.somethingelse
17:50justin_smithclojure.core does this with cljs vs. clojure
17:50blake__'cause if it were cljs.myproject.whatever and clj.myproject.whatever, you'd sort of need to prefix or change the name.
17:53blake__I had some idea the namespace had to match the directory structure, too.
17:53justin_smithblake__: yes, namespace matching directory structure is neccessary if you want to call require or use in your code
17:55blake__justin_smith: Well, that's interesting. I turned a Clojure app into a mixed clojure/clojurescript app and put all the clj namespaces under a new clj directory, and changed nothing else and it seems to work.
17:55blake__With all of the namespaces requiring each other, that is.
17:55blake__So what used to be "myproject/src/core.clj" became "myproject/src/clj/core.clj".
17:56blake__er, "myproject/src/core.clj" became "myproject/src/clj/myproject/core.clj".
17:56justin_smithblake__: well, the directory structure restriction is inside the classpath, when you rename src to clj or src-clj or whatever you are changing classpath in lein along with it right? and the relative to classpath dir structure is unchanged
17:56justin_smithso likely you changed in lein from "src" to "src/clj" right?
17:57blake__right
17:58blake__So I guess that answers the original question, since those are relative paths as well, prefixing them is superfluous...unless maybe they (the clj and cljs) share code?
22:12will_smIs it viable to run a basic clojure server on a BeagleBone black? ~ 1Ghz, 512MB Ram
22:13rhg135It's possible for sure
22:13amalloyyou don't need anything close to 512MB to run a small webserver in clojure
22:14lockdownwill_sm: just don't run it with lein
22:15will_smI was really worried since I did `boot repl`, and that thing took 1GB on my system
22:15will_smBut some apps do get greedy with my 32GB of ram
22:16lockdowns/lein/lein and boot/
22:18rhg135But I don't know what the response time is like
22:19hiredmanI ran a little rest api written in clojure on a bealgebone to do home automation stuff, worked great
22:22rhg135Cool
22:35hiredmanactually, at one of the conjs I gave a lightening talk about a little rover running clojure on a beaglebone that streamed video to the browser
22:35hiredmanhttps://www.youtube.com/watch?v=XMIKfOmAMjQ
22:39hiredmanI also have a compiler I started (written in clojure) for a basic like language for the programmable realtime units on the beaglebone
22:39hiredmanon short, beaglebones are fun
22:39hiredmanin