#clojure logs

2015-05-17

00:26tmtwdis there a way to load files in the repl
00:26tmtwd?
00:26tmtwdlike :l hello.clj?
00:56crocket(:hell worlds)
01:07heuristtmtwd: (doc load-file)
01:08tmtwdthanks
01:51ffwacombrap cunts
01:53crocketcunt
02:36chomwittcan i ask a question about the ring library ?
02:37andyf~ask
02:37clojurebotThe Ask To Ask protocol wastes more bandwidth than any version of the Ask protocol, so just ask your question.
02:39chomwitt:-). i want to start experimenting with a webapp (i mean using websockets or ajax?) . does 'ring' support that or is just for post-get traditional websites?
03:29TimMcchomwitt: Well, AJAX is just regular ol' HTTP calls from the server's point of view.
03:29TimMcI think there's a websocket adapter for ring but I haven't looked specifically.
03:33TimMcchomwitt: You will probably want a routing library on top of ring, such as compojure. And I haven't played with it myself.
03:33TimMc...but clojure-liberator is apparently a great way to handle a lot of the complexities of HTTP.
03:40chomwittTimMc: so ring is necessary even for a websocket baset webapp
03:41chomwittso i guess i'll start with ring+compojurte and http-kit
03:57TimMcBy the way, careful about web searches for liberator -- that's also a brand of sex furniture. Add the keyword "clojure" to be sure. :-P
03:59wasamasawat
03:59wasamasawell, indeed
04:00wasamasaguess I've always combined it with a CS-related term
04:00wasamasamind you, not *that* kind of CS
04:04TimMcCounterstrike?
04:55dysfunchomwitt: if you're using websockets, you may want to look into sente. or one of aleph and core.async
04:56dysfunhttps://github.com/ptaoussanis/sente
06:28weire-frame question: why does a subscription function get an atom, when it’s supposed to be read-only? why not just receive value?
07:43TimMcwei: "subscription function"? What's the context?
07:45weiI’m talking about subscriptions in Day8/re-frame. https://github.com/Day8/re-frame. He has an example of a subscription function toward the middle of the page, (defn greet …)
07:45weiTimMc: ^
07:53TimMcHmm! No idea.
07:56weiThanks anyway TimMc
08:09benhudahello
08:09benhudai'm looking for some opinion about json web tokens and authentication with them (JWT/JWS)
08:29TimMcbenhuda: Huh, hadn't heard about this before. Looks like it's just an HMAC standard for JSON?
08:30benhudaTimMc yes. it didn't come up on my radar, and i just go to manage this new team who sprinkled this all over the place in their microservice arch.
08:30benhudait takes me back to oauth1/oauth2 times. they used it to replace "regular" token auth with a database
08:30benhudasomething here feels broken architecturally but i cant point a finger
08:31benhudai accept that it's a good way to do 3rd party API calls, but not internally in your own arch.
08:34TimMcbenhuda: I dunno, the only issue I see is revocation.
08:35TimMcIf you make a call back to the auth server you're incurring a network call but you get instant revocation of authn.
08:37TimMc(You can have either one with OAuth.)
08:46benhudaTimMc see here http://lucumr.pocoo.org/2013/11/17/my-favorite-database/
08:51TimMcbenhuda: Our OAuth2 service at work is running into token size limits *because* we're not using a database. "Small" is relative.
08:52TimMcI might like to see us move to a hybrid DB/signed-token model.
08:53TimMcEncoded token too bug to fit in an HTTP header or URL? Shove it in a DB.
08:56TimMc(Revocations can also be managed by sending hashes or IDs of tokens off to a DB asynchronously and then distributing revocation lists to all your consuming servers, but that adds complexity too...)
09:00benhudaTimMc i'm seeing it how you see it.
09:00benhudaTimMc for some reason it feels this kind of solutions are escaping reality and just postponing the solution
09:01benhudaI see now reason why you can't incur a 1-5ms DB query at worst (better cases using k/v store or inmemory k/v provisioning)
09:01benhudaand then if other microservices need to identify a user, make a service-to-service call via some kind of fast RPC (pb/thrift/zmq)
09:01benhudas/now reason/no reason
09:02TimMcWell, every dependency on the DB might turn into an ∞ ms latency at any time.
09:02benhudaif that stops working and doesn't "scale" - THEN try looking at those kind of solutions
09:03benhudaTimMc yep, but then again that's only one of many dependencies in today's systems
09:03benhudait's just that i'm facing this team now who is in love with this kind of solution and they want to stick tokens and signing literally everywhere
09:04benhudait is over engineering, but there's no argument i can take that can shed some light at this for them
09:04benhudaand i really believe in convincing rather than forcing everyone to not use this anymore
09:05benhudarevocation is good - but then, how often do you revoke registered users
09:05TimMcOn logout.
09:05TimMc(Unless there are async operations still using the token.)
09:05TimMcOr you use short expiries.
09:06benhudathe context is this - accounts service is responsible for registration, it will give you a token to use with APIs for other services of the system. you then take this token and for every system, you need to carry it along. every such system needs to make sure you are registered and valid before letting you in
09:07benhudaso every "feature" system, let's say your Dashboard service, will take your token - will need to "ask" the accounts service if you are valid by handing it the token.
09:07benhudait can be done server-to-server by RPC
09:07TimMcAnd every system has its own trust boundary because they're all accessed via the web?
09:07benhudait can also be done by PKI. if the accounts service signed the token and the Dashboard service validated it.
09:08benhudayes, they're all accessed from the web. there is no "unifying gateway" through which all clients access features of the system.
09:08TimMcor a datacenter where you have lots of trusted calls between servers
09:09benhudaTimMc feature services such as the Dashboard expose API to any kind of client. say a mobile phone.
09:09TimMc*nod*
09:10benhudaso the two models are: a feature service checks with the accounts service "under the counter", or the accounts service signs the token while the feature service verifies it
09:11TimMcOr a hybrid, just to make things confusing. :-P
09:11benhudayep :)
09:11benhudathere's nothing bad in adding a signature
09:11benhudai'm not sure it's all good if signing is the only security mechanism here
09:11TimMc(e.g. fall back to signature when only recourse)
09:12TimMcWe've gone the signature route and it has mostly worked fine.
09:12TimMcThe signing keys last long enough that even when there is network trouble, resource servers can still authorize inbound requests, and that has been very valuable.
09:13TimMcbut like I said, it turns out not to be sufficient either
09:14TimMcSign-only also means you need short token lifetimes (unless you have revoke-on-logout, which is a whole 'nother problem!) so long-running operations get into trouble.
09:20TimMcbenhuda: I feel pretty comfortable with signatures. I count three failure modes:
09:21TimMc1) Someone compromises the signing keys. (Irrelevant because someone could compromise the user database or accounts server just as easily.)
09:22TimMc2) Someone cracks the signing keys but not by gaining access. (Unlikely, I think, but different from the network call scenario.)
09:23TimMc3) The cryptography or trust model is wrong, and someone can replay, coin, modify, or otherwise subvert the token system due to a design flaw. (Most likely scenario, but largely avoided by using a popular standard and library.)
09:25TimMc(On point 1... this suggests not using a symmetric key distributed to the consuming servers, because that increases the number of places a compromise could occur. On the other hand, asymmetric crypto is pretty computationally expensive!)
09:28benhudaTimMc your logic is sound
09:42crocketI'm getting a feeling that the way "Chas Emerick, Brian Carper, Christophe Grand-Clojure Programming-O'Reilly Media (2012)" explains things is close to reference manual.
09:54crocketI think I'll read "Clojure Programming-O'Reilly Media" after braveclojure.com
09:54crocketNot really a good introduction to clojure...
10:04m1dnight_Is there a way on clojure for a thread to read out the value of another threads threadlocal variables? (readonly)
10:04m1dnight_or have an abstraction to do so or something?
10:26crocketDoes #() support a rest-param?
10:27crocketOh yes, %&
10:41surrealanalysisIs there a way to reload leiningen dependencies while using cider, via cider-jack-in?
10:42justin_smithsurrealanalysis: you can add new ones, but you can't update to newer versions
10:42justin_smithwithout restarting clojure
10:44surrealanalysisIs there a function to run that makes them available? I added clojurewerkz.neocons to my project.clj, but in cider after doing a lein deps from the command line, I still get “FileNotFoundException Could not locate clojurewerkz/neocons/rest__init.class”
10:45justin_smithsurrealanalysis: you can use pallet/alembic to load any new deps from project.clj
10:45surrealanalysisAwesome, thanks
10:45justin_smithit's also possible, but a little more complicated to do, with pomegranate
10:45surrealanalysisI’ll check that out
10:45justin_smithsurrealanalysis: for future reference, the function is alembic.still/load-project
10:46surrealanalysisI appreciate it. Though I was originally hoping to not reload at all, this definitely helps for future times this comes up
10:53justin_smithyeah, alembic is one item that will always be in my profiles.clj (along with criterium and clojure.trace)
10:57allenj12is there a common math library where I can get simple functions e^nth
10:57justin_smith,(Math/exp 2.0)
10:58clojurebot7.38905609893065
10:58justin_smithhttp://docs.oracle.com/javase/7/docs/api/java/lang/Math.html
10:58borkdudecider says: "Please, install (or update) cider-nrepl 0.8.2 and restart CIDER". but I have cider-nrepl 0.8.2...
10:58borkdudehttps://www.dropbox.com/s/uqu4bnek6svs2m6/Screenshot%202015-05-17%2016.57.37.png?dl=0
10:58allenj12justin_smith: thanks
10:59borkdudescreenshot here http://postimg.org/image/i2wghig8j/
11:03TEttingerallenj12: also numeric-tower is a nice lib that takes math fns and makes them work with clojure ratios and other types
11:03TEttingerhttps://github.com/clojure/math.numeric-tower
11:04allenj12TEttinger: thats what i originally go to, but the exp function forced 2 arguments and was wondering if there was anything else because of that
11:04justin_smith,Math/E
11:04clojurebot2.718281828459045
11:05borkdudeit's probably a lein ring problem
11:09borkdudelein ring still depends on nrepl 0.2.3, that may cause problems? https://github.com/weavejester/lein-ring/blob/master/src/leiningen/ring/server.clj#L43
11:30MajenfulHello there
11:32MajenfulI saw a piece of code on ruby lang website, there is 2 arrays (foo = %w[a b c d] and bar %w[b c]), and with foo - bar the output is %w[a d]
11:33MajenfulI tested with vector, it works with this code: (clojure.set/difference (set foo) (set bar)), is there a better code ?
11:38allenj12hmm i have a style qusestion... I want to write a function (map #(repeatedly % #(rand)) [1 3]) say for example, however clojure does not let you have nested #() is there a way to do this whle keeping this a one liner?
11:39justin_smithuse fn
11:39justin_smith,(map #(repeatedly % rand) [1 3])
11:39justin_smithor just use rand
11:39clojurebot((0.15493350293339403) (0.07908483961278112 0.6330284451347732 0.38239825150370765))
11:40justin_smithin the example case rand is already the function you want so there is no need to construct one, but more generally, use fn
11:40justin_smith,(map (fn [i] (repeatedly i rand)) [1 3])
11:40clojurebot((0.6449643600828655) (0.44102695938111813 0.5327623466180637 0.7406192877830506))
11:46allenj12justin_smith: alright
13:02SeyleriusDamnit. Trying to test my work in CIDER, but it's failing. This (http://ix.io/iBB) is getting "Unable to resolve symbol" errors on everything.
13:02SeyleriusWell, almost everything.
13:02Seyleriusnumbers and sample-2d resolve, but blank-square, doesn't resolve in sample-2d's resolution
13:07xeqiSeylerius: clojure evaluates the file in order. In his case sample-2d is trying to use blank-square, but blank-square is not defined yet. I'd move sample-2d below blank-square
13:08SeyleriusIt also didn't resolve (-main), which doesn't use anything.
13:08xeqiwhat do you mean by resolve?
13:08SeyleriusBut, strangely, that fixed (-main) too
13:08Seylerius"Unable to resolve symbol"""
13:09SeyleriusBut it's fixed now, thanks.
13:09xeqiwhen you try to ...? load-file, jump-to-symbol, etc?
13:10justin_smithSeylerius: like I said last night, the definition of blank-square needs to be before the definition of sample-2d
13:10SeyleriusI must've missed that bit.
13:10justin_smiththis has nothing to do with cider. Clojure does not look ahead in files while compiling.
13:10SeyleriusYeah, I see that in my logs, totally missed it.
13:10Majenfulany words for my question about vectors ?
13:10SeyleriusI was _tired_ last night.
13:11justin_smithMajenful: is order in the output important
13:11justin_smith?
13:12justin_smithif no, use the two sets approach, if yes use (filterv (set coll2) coll1) or filter rather than filterv if you don't need the output to be a vector
13:12justin_smith,(filterv #{:a :b :c} [:x :y :a :g :b :c])
13:12clojurebot[:a :b :c]
13:13justin_smitherr, sorry, removev
13:13justin_smith,(removev #{:a :b :c} [:x :y :a :g :b :c])
13:13clojurebot#error {\n :cause "Unable to resolve symbol: removev in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: removev in this context, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6543]}\n {:type java.lang.RuntimeException\n :message "Unable to resolve symbol: removev i...
13:13Majenfuljustin_smith: I would like but it's not important
13:13justin_smitherm...
13:13justin_smith,(remove #{:a :b :c} [:x :y :a :g :b :c])
13:13clojurebot(:x :y :g)
13:31Majenfuljustin_smith: but your solution cannot "compare" 2 vectors ? In fact, I want to get the element not in the other vector
13:36oddcullyMajenful: look at clojure.set/difference
13:40oddcullyMajenful: or just complement the solution from justin_smith from above: ,(filterv (complement (set [:a :b :c])) [:a :x :b :c :y :z])
13:40oddcullyclojurebot: you're on vacation or what?
13:40clojurebotGabh mo leithscéal?
13:49Majenfuloddcully: I already used clojure.set/difference (clojure.set/difference (set foo) (set bar)), but I wonder if there was a shorter code, or without having to transform into seq before testing the difference
13:49Majenfulanyway, thanks for the help :)
14:01justin_smithMajenful: the remove version gives you the elements in the second arg that are not in the first set
14:01justin_smithturn your se3cond arg into a set, make it the first arg to remove
14:07michaelr`hi
14:12xeqihello
14:29michaelr`trying to run some stuff which starts an embeded jetty, when executing from Clojure the jetty code fails on NPE after getting a null from getClassLoader(), when ran from java works ok
14:29michaelr`anyone familiar with this sort of problems?
14:30michaelr`Caused by: java.lang.NullPointerException: null
14:30michaelr` at org.eclipse.jetty.util.log.Log$1.run (Log.java:94)
14:34bensumichaelr`: are you starting it from java with special options?
14:35bensuit looks like you need to specify a log class
14:35michaelr`No
14:35michaelr`not starting with special options
14:36bensumichaelr`, have you setup custom logging?
14:38michaelr`not sure.. I have log4j.xml if that's what you mean
14:39michaelr`URL testProps = Log.class.getClassLoader().getResource("jetty-logging.properties");
14:40michaelr`This is the line from org.eclipse.jetty.util.log.Log
14:40michaelr`getClassLoader() returns null when called from Clojure and the system class loader when called from java
14:40bensumichaelr`, that is line 94? So Clojure can't find the class Log
14:40bensu?
14:41bensumichaelr`, sorry, I missread. getClassLoader() returns null
14:42bensumichaelr`, not sure I can help, I have no knowledge of Class Loaders
14:44michaelr`thanks anyway!
15:22weiI have a build that works with cljsbuild but not with figwheel. Any tips on troubleshooting? Here’s the project.clj: https://gist.github.com/yayitswei/317dfec919d01e67fb4c
15:46SeyleriusIs there a good reason why (= sample-2d (resheet-rows (sheet-rows sample-2d))) would be false using this code? http://ix.io/iBV
15:52amalloythe & in resheet-rows makes me think you might need (apply resheet-rows ...), but if that's not it you'll need to find someone who knows anything about core.matrix
16:05Seyleriusamalloy: That's totally it.
16:05SeyleriusThanks.
16:08borkdudewhy is rename-keys in clojure.set?
16:14SeyleriusGrr... Still not working.
16:17gfredericksborkdude: clojure.set would get lonely otherwise
16:54holohi
16:55Seyleriusamalloy: Okay, that's stupid and annoying, and makes testing difficult. I simplified the data a wee bit, and the string representations are identical, even though they don't test as equal.
16:56holodefn is forgiving about doc-string and params order. is it considered bad style to use params before doc-string?
16:56SeyleriusThere's something stupid in the optimizations the damn thing's using that keeps identically structured matrices from equating.
17:03SeyleriusOkay. How do I chop a 9x9 into 9 3x3s, in box form?
17:05jtmarmonhey there - i'm trying to do some basic logging on an import job via "prn", but it seems the output doesn't go to the screen until the thread is done executing. is there a way I can send the data to the screen via a background thread so i can watch the logs as the process executes
17:08SeyleriusOkay, better question: what will let me take [:a :b :c :d :e :f :g :h :i] and return [[:a :b :c] [:d :e :f] [:g :h :i]]?
17:09amalloy&(doc partition)
17:09lazybot⇒ "([n coll] [n step coll] [n step pad coll]); Returns a lazy sequence of lists of n items each, at offsets step apart. If step is not supplied, defaults to n, i.e. the partitions do not overlap. If a pad collection is supplied, use its elements as necessary to comple... https://www.refheap.com/101228
17:11xeqiholo: doc-strings go before params. If you put the string after the params then your using the string as part of the function body, not as a doc-string
17:13xeqijtmarmon: are you running this via a future, a (Thread. ..), or another mechanism ?
17:13jtmarmonxeqi: it's simply a bunch of cascading function calls. there's no multi threading currently
17:13Seyleriusamalloy: Thanks
17:14holoxeqi: oh yes :> haha thanks
17:14holo(inc xeqi)
17:14lazybot⇒ 16
17:15jtmarmonshould I just have my printlns be wrapped in a function and dispatched asynchronously (.start (Thread. (fn [] (prn "hi!")))?
17:18xeqiI'm surprised its not working if your not currently doing any threading currently
17:20jtmarmonxeqi: it's not :P. would that be the right solution to handle logging then?
17:22xeqinope, trying to use Thread. will cause problems due to *out* and its binding. future would be better since it sets the dynamic vars up right, but I still don't think thats the right solution.
17:23xeqiI would have thought flushin to be a problem, but prn is suppose to do that
17:23SeyleriusHow do I take (nthrest row 3) of each row in coll?
17:24xeqiso as long as *flush-on-newline* is true, I don't have any idea why your not seeing output until the very end. I definitly wouldn't want to introduce multithreading to try so solve it, I'd expect that would just make things worse
17:25jtmarmonyep it's true
17:26jtmarmonSeylerius: you mean you want [[1 2 3] [4 5 6] ...] -> [3 6]?
17:28Seyleriusjtmarmon: [[:a :b :c :d :e :f :g :h :i] [:a :b :c :d :e :f :g :h :i]] ==> [[:d :e :f :g :h :i] [:d :e :f :g :h :i]]
17:28SeyleriusAnd I'll also need [:a :b :c :a :b :c]
17:29jtmarmon&(doc take-last)
17:29lazybot⇒ "([n coll]); Returns a seq of the last n items in coll. Depending on the type of coll may be no better than linear time. For vectors, see also subvec."
17:29jtmarmon(map #(take-last n %) data)
17:32Seyleriusjtmarmon: Yeah, that's it.
17:32jtmarmonif you want the first half as well, you can use:
17:32jtmarmon&(doc split-at)
17:32lazybot⇒ "([n coll]); Returns a vector of [(take n coll) (drop n coll)]"
17:33SeyleriusNeed them in different spots, so I'll probably map a #(drop-last n %) over it for that, and reduce it into a vector.
17:36SeyleriusNow how does this become non-ugly? http://ix.io/iC5
17:37SeyleriusMaybe break it into two functions...
17:40xeqiSeylerius: is that outer loop equiv to mapcat?
17:43Seyleriusxeqi: Hmm...
17:44Seyleriusxeqi: Here it is in two functions. I think maybe. What do you think?
17:44SeyleriusMaybe I can reduce the whole loop of sheet-boxes into mostly just a mapcat of break-box-row?
17:46xeqiSeylerius: think you forgot a new paste
17:47Seyleriushttp://ix.io/iC7
17:48Seyleriusxeqi: I did forget the new paste, you're right.
17:48SeyleriusThat's it.
17:54Seyleriusxeqi: Weird. break-box-row is failing on memory overload, demanding something in the neighborhood of 150+G of memory.
17:54Seyleriusabout 190G, give or take
17:54SeyleriusWait...
17:55xeqiSeylerius: I can't reason about what its doing. why is (map #(take-last 6 %) box-row) the new value thats checked for loop termination
17:55SeyleriusNo, that's 295M
17:55RaynesClojuresque could use a wee tad bit of documenting huh
17:55RaynesSure wish I knew shit about gradle, it'd make this much easier.
17:56irctc_I am calling map over a collection. The function that process the items of the collection has side effects. If I use dorun on the map it does not realizes the map, but if I omit the dorun the map executes. Why is that? Should not be the other way around.
17:56RaynesDo you return a collection of values from the map?
17:57RaynesBecause if not, use doseq instead.
17:57SeyleriusWhat it's supposed to do is take a 9x3, break it into 3x3s, and give back the 3x3s as 9x1s.
17:58RaynesSo it does return a collection of values, just those values are the result of a function that performs side effects to produce them?
17:58SeyleriusRaynes: I want to take a sudoku sheet and return the 3x3 boxes as 9x1 vectors
17:59xeqiRaynes: 2 different conversations
17:59RaynesOh, this shitty irc client.
17:59Raynesxeqi: Derpthnx
17:59RaynesProbably would have carried on real confused for a while.
17:59xeqiI was tempted....
17:59RaynesI'll hurt you
18:00Raynesirctc_: Okay sir those previous messages were all directed at you.
18:00RaynesSeylerius: I still love you but I hate sudoku and can't even
18:00Seyleriusxeqi: That's the total goal. I have a 9x9 sudoku sheet (well, 9 of 'em), and I want to take the 3x3s out of it as 9x1s.
18:01SeyleriusRaynes: It's okay, sudoku hates you too.
18:01RaynesYou don't even know
18:01SeyleriusRaynes: I'm making a solver. For 3d sudoku. So if you ever want to beat it into submission, this thing could probably help.
18:02RaynesBut only if you get it working first
18:02SeyleriusRight.
18:02RaynesSo let's get that sorted out for the betterment of mankind.
18:02SeyleriusI'm struggling on breaking out the boxes.
18:02SeyleriusRight.
18:02SeyleriusAnd the betterment of my wallet.
18:03SeyleriusI can break the sheet into 9x3s reliably now.
18:03irctc_Raynes With dorun I have tried returning items and not returning them, and none of them works
18:03irctc_It just return nil
18:04Seyleriusxeqi: So how would you take a 9x3 and chop it into 3 3x3s?
18:05Raynesirctc_: The point is, if the map executes but you don't get back a return value, does it matter? Do you need to call foo on (1, 2, 3) and get back (new1, new2, new3) or will foo just do *things* and you don't care about the result?
18:05Seyleriusxeqi: If I've got [[:a :b :c :d :e :f :g :h :i] [:a :b :c :d :e :f :g :h :i] [:a :b :c :d :e :f :g :h :i]], I need [[:a :b :c :a :b :c :a :b :c] [:d :e :f :d :e :f :d :e :f] [:g :h :i :g :h :i :g :h :i]]
18:06RaynesBecause if you don't care about the result of the map, you should use doseq. If you do care, you should use doall
18:06SeyleriusHow does one do that?
18:06Raynesdorun is supposed to return nil.
18:07irctc_Raynes for now I do not care. But I have a use case where I care. And I care that the whole seq is never in the memory since it is too big. So I would like to make dorun work, since in the docs it says that is meant just for this.
18:07RaynesYou cannot make dorun work.
18:07RaynesIt is not designed for this purpose.
18:08RaynesIf you want to not hold the entire seq in memory but still have the side effects happen, you're gonna have to iterate through and do things with the results one way or the other.
18:08Seyleriusamalloy: Any idea what would turn [[:a :b :c :d :e :f :g :h :i] [:a :b :c :d :e :f :g :h :i] [:a :b :c :d :e :f :g :h :i]] into [[:a :b :c :a :b :c :a :b :c] [:d :e :f :d :e :f :d :e :f] [:g :h :i :g :h :i :g :h :i]]?
18:09SeyleriusThe way I'm currently doing it demands 295M and fails hard.
18:10amalloyhow on earth can you use up 300MB on a 3x9 vector?
18:10RaynesWhere there's a will there's a way.
18:10Seyleriusamalloy: With this crap: http://ix.io/iC9
18:10amalloyanyway, it starts with (map (partial partition 3) m)
18:11xeqiSeylerius: somethign like (apply map concat (map #(partition 3 %) matrix)
18:12irctc_Raynes I am composing lazy operation together (->> map filter ...) and one of this has side effects(it writes to db and returns beck what itsaved). Is there a way to execute this chain of functions without never having the entire sequence in memory?
18:13amalloyi just finished writing a worse version of xeqi's solution
18:13RaynesYay you're second best
18:13amalloyat least mine had balanced parens, though. that's a win
18:13Raynesirctc: Yes, you need to either throw away the results or process them and produce a smaller sequence.
18:14Seyleriusamalloy, xeqi: Thank you both so much.
18:14Seylerius(inc amalloy)
18:14lazybot⇒ 270
18:14Seylerius(inc xeqi)
18:14lazybot⇒ 17
18:15SeyleriusIs there a difference between (inc <nick>) and (inc <nick> )?
18:15SeyleriusIn fact, let's find out:
18:15oddcully(inc justin_smith )
18:15lazybot⇒ 12
18:15oddcullyyes
18:15Seylerius(inc xeqi )
18:15lazybot⇒ 2
18:15RaynesWe're not actually reading Clojure forms there.
18:15SeyleriusVery interesting.
18:15RaynesIt's a regex that amalloy will never get right.
18:16oddcully(dec justin_smith ) ; didn't deserve it
18:16lazybot⇒ 11
18:16SeyleriusI'll need to remember that when I'm tab-completing nicks for that...
18:16Seylerius(dec justin_smith ) ; Did this last night, meant to give it to the real person
18:16lazybot⇒ 10
18:16Seylerius(inc justin_smith)
18:16lazybot⇒ 254
18:20SeyleriusOkay. The two functions do their job. Now how do I reverse them? http://ix.io/iCa
18:20irctc_Raynes let´s say i do not return elements from the map˙s function. dorun should still force the sequence right?
18:20RaynesYes.
18:21RaynesI know you said this was not working, but without sample code I'm afraid I can't do much beyond say I'm sorry :P
18:22irctc_in my case it does not. I have a fun that as body has a let which does not return anything. Can this be the problem?
18:23irctc_like this (map (fn [x y z] [a side-effect1 b side-effect2...]) coll)
18:24SeyleriusDamn. It's symmetric.
18:24Seyleriusxeqi: Your solution, when combined with my mapcat, is completely symetric.
18:24Seylerius(inc xeqi)
18:24lazybot⇒ 18
18:26SeyleriusTake a look at the whole file, and try (matrix/array (sheet-boxes (sheet-boxes sample-2d)))
18:26irctc_(map (fn [x y z] (let [a side-effect1 b side-effect2...])) coll) * eh... But I think this has nothing to do with it. I will try to explore further
18:26SeyleriusThere are quirks about the NDArray implementation that prevent it from equating, but if you take the string reps and diff them, they're identical.
18:40SeyleriusIf you're constraining a foo-seq based on a constraint-seq, is it more clojurish to have the args go [foo-seq constraint-seq] or [constraint-seq foo-seq]?
18:40SeyleriusFrom a stylistic perspective...
18:41SeyleriusActually, nvm
18:52devnhello all
19:00SeyleriusDamn, functional programming is easier to reason about in the long run.
19:01SeyleriusIs this where y'all would put the line breaks for maximum readability? http://ix.io/iCe
19:21weiIs there a library for helping to create REST api bindings? Seems like it would be useful
19:22devnwei: you mean like liberator?
19:22weilike the other way around- client bindings
19:22weie.g. a facebook, twitter, or youtube api wrapper
19:22devnwhat's an example from another language?
19:23weidevn: I’m not sure there is one. but I find myself rewriting the same patterns as I’m building these bindings, and was wondering if anyone else had generalized it
19:24weior even better— parse the docs and generate the code!
19:40SeyleriusDamnit. I wish NDArray would test equality properly. Maybe I need the operators from core.matrix...
19:47xeqiSeylerius: re line breaks, consider using -> in that example
19:48amalloyalso, (map f\n (x y)) is usually more readable than (map f (x\ny))
19:49SeyleriusThank you both
19:49Seylerius(inc xeqi)
19:49lazybot⇒ 19
19:49Seylerius(inc amalloy)
19:49lazybot⇒ 271
19:49Seylerius-> is... awesome.
19:52xeqiSeylerius: in this case I meant ->> since you have a bunch of (map fn ...)
19:53SeyleriusYeah, I noticed that.
19:53Seyleriusxeqi, amalloy: How's this look? http://ix.io/iCf
19:57amalloySeylerius: looks okay. have you tried factoring out the repeated calls to map constrain? it might be nicer if you did something like (let [steps [(comp sheet-columns resheet-rows) (comp sheet-boxes resheet-columns) (comp matrix/array sheet-boxes)]] (reduce (fn [sheet f] (f (map constrain sheet))) (sheet-rows sheet) steps))
19:57amalloythat's probably not shorter, but it does separate out the tedious (map constrains) from the specialized steps
20:00SeyleriusI could also make a constrain-rows, constrain-columns, and constrain-boxes that just does the steps for each, with a map constrain in the middle, and push the sheet through those.
20:01amalloythat would also be reasonable
20:03Seyleriusamalloy: http://ix.io/iCg
20:04SeyleriusClojure <3s functions. I should remember to take advantage of that.
20:04amalloySeylerius: why do you not have a funciton somehwere for (map constrain xs)?
20:05SeyleriusA constrain-these?
20:08Seyleriusamalloy: Like this? http://ix.io/iCh
20:08amalloysure
20:08Seyleriusamalloy: The point being to make the meanings fully obvious?
20:09SeyleriusRather than having to think about what mapping constrain over shit means?
20:09amalloywell, the point being to write things in the language of your domain. since you basically never call constrain alone, mapping constrain seems like the domain-specific thing to do
20:10Seylerius…And now I continue hunting for the appropriate way to make equality-testing work with an object-NDArray.
20:11SeyleriusRight. That makes sense.
20:12Seyleriusamalloy: Do you know anything about core.matrix? I'm trying to figure out how to check equality of the NDArrays, but it's designed to work with fscking doubles and longs, not objects.
20:13amalloyno. why are you using core.matrix anyway instead of just some vectors?
20:13SeyleriusI suppose I could. Thought it might be better/faster, and I like the slices function a lot.
20:13SeyleriusAnd the easy transpose, which makes resheet-columns work more simply.
20:14amalloytranspose is not hard
20:14SeyleriusTrue. I could just grab a transpose out of rosetta-code.
20:14amalloy(apply map list '((1 2 3) (4 5 6) (7 8 9)))
20:14amalloy,(apply map list '((1 2 3) (4 5 6) (7 8 9)))
20:14clojurebot((1 4 7) (2 5 8) (3 6 9))
20:14SeyleriusThat's not hard.
20:14SeyleriusWhat about slicing?
20:15SeyleriusThat's the other main thing I use.
20:15SeyleriusI basically need to work with progressively smaller-dimensioned slices (in arbitrary axes) of a 9x9x9.
20:15amalloythat is too vague a feature fro me to propose an alternative. what kind of slicing do you do, and why?
20:16SeyleriusTurn a cube into sheets from each of the three axes, and slice those sheets into rows, columns, and boxes.
20:16SeyleriusI get how with a transpose I can get columns out of a sheet.
20:17SeyleriusBut getting sheets out of the cube, along an arbitrary axis, is a tougher one.
20:18SeyleriusBasically, I'm going to need (slices cube 0) (slices cube 1) and (slices cube 2) to give me the slices along each axis in turn.
20:18amalloyare you still talking about sudoku? this talk of cubes, axes, and sheets is bizarre
20:18Seylerius3d sudoku
20:19TimMcamalloy: Makes sense to me -- array slicing.
20:20SeyleriusIn 3d sudoku, you could say that each square is constrained by 3 different sudoku boards: one in the X-axis, one in the Y, and one in the Z.
20:23SeyleriusSolving 3d sudoku can be thought of as taking passes of "constrain slices along the x-axis", "constrain slices along y", and "constrain slices along z", followed by "fill slices along (x y z)"
20:24SeyleriusAnd then you branch on ambiguities.
20:25Seyleriusamalloy: So, I just need to be able to, from an arbitrary direction, turn a 9x9x9 into a succession of 9x9s.
20:26SeyleriusAnd reliably be able to put them back together.
20:26SeyleriusMaybe a 3d transpose would do it.
20:26SeyleriusBeing able to essentially rotate the whole cube before slicing it.
20:29SeyleriusTimMc: Any ideas on how to transpose in three dimensions?
20:29Seylerius(In a reversible way?)
20:30SeyleriusAh, fuck it. I
20:30SeyleriusI'll just study mikera's damn slices function and re-use it.
20:35xeqi(first cube), (apply map first cube), (map #(apply map first %&) cube) ?
20:41Seyleriusxeqi: testing that with a 3x3x3 with toy values to see if it works
20:43Seylerius,(def toy-cube [[[:a :b :c] [:d :e :f] [:g :h :i] [[:j :k :l] [:m :n :o] [:p :q :r]] [[:s :t :u] [:v :w :x] [:y :z :zz]]]])
20:43clojurebot#'sandbox/toy-cube
20:43Seylerius,(first cube)
20:43clojurebot#error {\n :cause "Unable to resolve symbol: cube in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: cube in this context, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6543]}\n {:type java.lang.RuntimeException\n :message "Unable to resolve symbol: cube in this co...
20:43Seylerius,(first toy-cube)
20:43clojurebot[[:a :b :c] [:d :e :f] [:g :h :i] [[:j :k :l] [:m :n :o] [:p :q :r]] [[:s :t :u] [:v :w :x] [:y :z :zz]]]
20:45Seylerius,(def toy-cube [[[:a :b :c] [:d :e :f] [:g :h :i]] [[:j :k :l] [:m :n :o] [:p :q :r]] [[:s :t :u] [:v :w :x] [:y :z :zz]]])
20:45clojurebot#'sandbox/toy-cube
20:45Seylerius,(first toy-cube)
20:45clojurebot[[:a :b :c] [:d :e :f] [:g :h :i]]
20:45Seylerius,(apply map first cube)
20:45clojurebot#error {\n :cause "Unable to resolve symbol: cube in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: cube in this context, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6543]}\n {:type java.lang.RuntimeException\n :message "Unable to resolve symbol: cube in this co...
20:45Seylerius,(first toy-cube)
20:45clojurebot[[:a :b :c] [:d :e :f] [:g :h :i]]
20:45Seylerius,(apply map first toy-cube)
20:45clojurebot#<ArityException clojure.lang.ArityException: Wrong number of args (3) passed to: core/first--4107>
20:47xeqi,(map first toy-cube)
20:47clojurebot([:a :b :c] [:j :k :l] [:s :t :u])
20:47devnnot really sure what you're going for here
20:47devnbut...
20:48devn,(apply (partial map first) toy-cube)
20:48clojurebot#<ArityException clojure.lang.ArityException: Wrong number of args (3) passed to: core/first--4107>
20:48devnerr uhhh wait, what
20:48xeqiheh
20:48devnworks in my repl
20:49devn,(apply (partial mapv pop) toy-cube)
20:49clojurebot#error {\n :cause "Wrong number of args (3) passed to: core/pop"\n :via\n [{:type clojure.lang.ArityException\n :message "Wrong number of args (3) passed to: core/pop"\n :at [clojure.lang.AFn throwArity "AFn.java" 429]}]\n :trace\n [[clojure.lang.AFn throwArity "AFn.java" 429]\n [clojure.lang.AFn invoke "AFn.java" 40]\n [clojure.core$map$fn__4557 invoke "core.clj" 2633]\n [clojure.lang.Lazy...
20:49xeqiSeylerius: do you have a 9x9 solver already?
20:49devnwhy is it breaking on this?
20:50devnthese work in my repl
20:50devn,*clojure-version*
20:50clojurebot{:major 1, :minor 7, :incremental 0, :qualifier "master", :interim true}
20:50devnoh, transducers?
20:52devnno, that's not it
20:52Seyleriusxeqi: Very nearly. Got sidetracked by the question of "how do I know when I've blocked at an ambiguity?", which I figured I could answer with "does attempting to constrain and fill do nothing?" which blocked on the fact that core.matrix didn't want to test equality for object matrices. And so I'm tossing core.matrix, but I can only toss core.matrix if I can replace 3d slicing.
20:52devn,(apply (partial mapv peek) #'sandbox/toy-cube)
20:52clojurebot#error {\n :cause "Don't know how to create ISeq from: clojure.lang.Var"\n :via\n [{:type java.lang.IllegalArgumentException\n :message "Don't know how to create ISeq from: clojure.lang.Var"\n :at [clojure.lang.RT seqFrom "RT.java" 528]}]\n :trace\n [[clojure.lang.RT seqFrom "RT.java" 528]\n [clojure.lang.RT seq "RT.java" 509]\n [clojure.core$seq__4125 invoke "core.clj" 135]\n [clojure.core...
20:52devn,#'sandbox/toy-cube
20:52clojurebot#'sandbox/toy-cube
20:52devn,sandbox/toy-cube
20:52clojurebot[[[:a :b :c] [:d :e :f] [:g :h :i]] [[:j :k :l] [:m :n :o] [:p :q :r]] [[:s :t :u] [:v :w :x] [:y :z :zz]]]
20:54SeyleriusI suppose I could simply assume that I /can/ build 3d slicing and recomposing, and leave it for later, and toss core.matrix in the now...
20:54devni don't mean to detract from the discussion, but xeqi or anyone else know why clojurebot cant handle that?
20:55devnnot the most previous one, that's my bad
20:55devnbut the arity exceptions
20:55xeqidevn: so the (apply (partial mapv pop) toy-cube) one?
20:55devnyeah
20:56Seyleriusxeqi: Figure I ought to table the 3d-slicing for now?
20:56SeyleriusAnd simply mark it "assumed solvable later"?
20:57xeqidevn: because toy-cube is a list of 3 lists. Then apply passes it to map which takes the first element of each list, and calls pop with them as the 3 arguments
20:57xeqidid you miss the redefinition of toy-cube earlier due to a misplaced ] ?
20:57devnxeqi: it works in my REPL. why?
20:57devnperhaps
20:58devnah yes, that's what happened
20:58devnd'oh
20:58devnxeqi: i was sitting here wondering if i was taking crazy pills
20:59xeqiSeylerius: well, if I was solving it (by brute force) my plan would be split along X axis. Get solutions for each 9x9 board. Then combine them into all possible cubes. Then remove them based on each board in the Y and Z directions. I'd start with the 9x9 solver as its used in both the generate and filter steps
21:08Seyleriusxeqi: My basic strategy boils down to looping (constrain-x constrain-y constrain-z fill-axis), cycling through the axes for each pass with fill-axis. When I block on an ambiguity, I take the most-constrained unit (choosing one arbitrarily if there are multiple), and recurse the solver with each possibility for the selected unit. A solver returns one of the following [solution (solutions-returned-by-branches)], or throws an exception.
21:10Seyleriusfilling works both on situations where a unit has only one possibility left after being constrained, or when a given row, column, or box can only get a particular value in one location.
21:33devnwhat's the name of the clojure "fork"?
21:33devnthe one with the rationale
21:34xeqi$google dunaj clojure
21:34lazybot[Dunaj project · GitHub] https://github.com/dunaj-project
21:34devnty
21:43SeyleriusOkay... Recurse the solver with each step, or loop with each step?
21:43SeyleriusWhat's going to be more efficient?
21:47devnah-ha, i missed this: https://github.com/cgrand/megaref
21:55SeyleriusOkay. Wrapping up the 2d solver. Going with recursion, rather than loops.
22:04xeqiSeylerius: do you have a 3d input file?
22:13TimMcNeat, it looks like Rust has full macros! Awkward, but full-powered.
22:14devnyeah, pretty cool eh?
22:15TimMcI'm s proud of them.
22:15TimMcWelcome to the club, kiddo.
22:17Seyleriusxeqi: Not at the moment.
22:17SeyleriusNeed to gen one of those.
22:17SeyleriusOkay... I need (foo x y) for each x and y in seqx and seqy.
22:20amalloy(map foo xs ys)
22:20SeyleriusWait, map'll do that
22:20SeyleriusYep
22:25SeyleriusDoes this look like a sensible way to get the coords of the square with the smallest value (most constrained possibilities)? http://ix.io/iCs
22:26SeyleriusAll three relevant functions: http://ix.io/iCt
22:27aravindhi, if I have to wait for a second before doing anything else in a thread.. is there any difference (or advantage) to using (Thread/sleep 1000) vs. (async/alts!! [(async/chan) (async/timeout 1000)]) ? The general advise seems to be don't sleep in a thread, because it prevents the thread from doing anything else.. but if I don't have anything else for the thread to do.. is there any point to using the more
22:27aravindcomplicated alts!! ?
22:29justin_smitharavind: clojure or clojurescript?
22:30justin_smithI mean Thread/sleep is clojure, and so you can easily have more threads than you have CPUs, if you need to wait, you can just wait, right?
22:43aravindjustin_smith: yeah, in clojure.
22:43aravindjustin_smith: yup.. in a simple wait for x seconds type situation.
22:44justin_smithit's better to have an event to wait for, but a simple sleep can work too
22:45aravindin this case, how does waiting for an event (a fake one like the simulated alts!! thing) make it better than a sleep ?
22:45justin_smithno, I mean a real event
22:45justin_smithlike, if you can actually be notified of the thing you are waiting for
22:45justin_smithnot treating a sleep as if it were an event
22:46aravindwell.. here its more a case of I have a problem now, I want to wait a second and retry again.
22:46aravindthere is no real event to wait for.
22:46justin_smithyeah, just use sleep
22:46aravindcool.
22:46aravindthanks.
22:48kristofaravind: Why are you using async with multiple threads if you're pretty confident about how many threads you need and what they're going to do?
22:48binjuredi apologize in advance for the vague question... i'm using Luminus, just running the sample app basically, which should be a super simple ring server... but it takes 30+ seconds to get the server running with `lein ring server`. is that normal?
22:48kristofaravind: The point of async is the ability to spawn concurrent green threads.
22:48kristofaravind: So when one green thread is blocked, the machine worker thread can take another task off the queue and keep doing work.
22:49justin_smithkristof: but he doesn't need green threads for a simple pause and retry
22:49kristofaravind: So in your case, there is no advantage to using alts!! over sleep. But there is also no advantage to using green threads at all.
22:49aravindkristof: yeah, I guess you are right.
22:50kristofjustin_smith: Right, that's what I'm saying.
22:50justin_smithgot it
22:50kristofjustin_smith: I didn't see any of the conversation after "complicated alts!! ?", I disconnected
22:51justin_smithahh, OK
22:51kristofapologies if I missed something
22:51aravindhrmm.. the reason I am using a go style thing is I want to kick something off in the background, and return an initial value. The background thing does it's business with waits etc.
22:52aravindI guess this is a case where I should be using a future, and return
22:52justin_smithsleep / retry in a future works for that
22:53aravindyeah, this whole go block is overkill for what I am doing.
22:53kristofYeah, go is cool because you can spawn all teh procz and you don't race conditions, the semantics are clear, etc.
22:53kristofTakes and puts block until there's actually a value. Communication points are lock-proctected by default. Etc.
22:54aravindyeah.. somehow the whole idea that I didn't need a go block for this was never clear to me.. until I open my mouth in public and ask stupid questions.
22:54aravindthanks for the pointers.
22:54kristofCSP is so cool, actors are actually emergent from CSP. an actor can just be defined as a loop that takes from a mailbox buffered chan and dispatches on the message received
22:57kristofAnd you might say "well, can't everyone take from the mailbox? Isn't that bad?" But to that I say that that's just a feature of flexibility, and you can do all sorts of mixing and matching. Have multiple actors take from the same mailbox without needing a man in the middle to distribute messages.
23:00SeyleriusHow do you find the coords of the smallest value in a grid?
23:19amalloySeylerius: create a seq of all the coords, and do something like (apply max-by #(get-in the-grid %) coord-seq)
23:20Seyleriusamalloy: I think I've figured it out, hold on and I'll have a function for you to check out.
23:23SeyleriusAh, crap. It worked in the repl, but I must've made a typo bringing it to the code.
23:24SeyleriusNope, it works, I forgot a step when testing it.
23:24SeyleriusOkay.
23:25Seyleriushttp://ix.io/iCu
23:25Seyleriusamalloy: That works.
23:25SeyleriusIt's kinda ugly, though.
23:30Seyleriusamalloy: What do you think of this? http://ix.io/iCv
23:35xeqiSeylerius: I'l be interested to see how your looks/runs when your finished
23:36Seyleriusxeqi: Thanks
23:36xeqithe problem intrigued me enough to adapt https://github.com/clojure/core.logic/wiki/Examples#sudoku into a 3d solver
23:36Seyleriusxeqi: Is there an easy way to replace a given item in a seqence?
23:37xeqi&(doc replace)
23:37lazybot⇒ "([s match replacement]); Replaces all instance of match with replacement in s. match/replacement can be: string / string char / char pattern / (string or function of match). See also replace-first. The replacement is literal (i.e. none of its characters are treated... https://www.refheap.com/101234
23:38xeqi,(replace {1 4} [1 2 3 4])
23:38clojurebot[4 2 3 4]
23:38xeqiSeylerius: ^ like that?
23:38SeyleriusThat's pretty close.
23:38SeyleriusI just need to swap at an index
23:38xeqi,(replace [0 4] [1 2 3 4])
23:38clojurebot[4 2 3 4]
23:39xeqi,(replace [1 4] [1 2 3 4])
23:39clojurebot[4 2 3 4]
23:39xeqiblah
23:39SeyleriusIf coll is [:a :b :c], (replace-index coll 1 :d) ==> [:a :d :c]
23:39SeyleriusBasically
23:42xeqi(assoc [:a :b :c] 1 :d)
23:42xeqi&(assoc [:a :b :c] 1 :d)
23:42lazybot⇒ [:a :d :c]
23:42xeqiSeylerius: ^
23:45SeyleriusYes! That's it, exactly.
23:51SeyleriusWhat's annoying about this project, and also why it's fun (and why I can't use an existing solver), is that I need to generate _all_ solutions, rather than just one.
23:57SeyleriusGreat. This code (http://ix.io/iCw) returns this error (http://ix.io/iCx).
23:57Seyleriusbuild-branch works, and smallest-2d works.
23:58Seyleriusxeqi, amalloy: Any guesses as to what broke it?
23:59amalloySeylerius: build-branch obviously doesn't work, the stacktrace says it is calling assoc on a seq
23:59amalloyyou probably meant to be calling it on a vector