#clojure logs

2015-09-17

02:05justin_smithwin 15
04:26OlajydHi All
04:27gilliardMorning
04:27OlajydHi, TEttinger :D
04:27TEttingerhey Olajyd!
04:30OlajydI want to split a comma seperated values, “Costa Rica, El Salvador,Paris” :(clojure.string/split “Costa Rica, El Salvador,Paris” (re-pattern “,”)) => [“Costa Rica”,”El Salvador”,”Paris”], I’m kinda lost on the regex to use ;)
04:33luma,(clojure.string/split "Costa Rica, El Salvador,Paris" #", *")
04:33clojurebot["Costa Rica" "El Salvador" "Paris"]
04:43Olajyd(clojure.string/split "Costa Rica, El Salvador,Paris" (re-pattern “, *”))
04:43Olajyd,(clojure.string/split "Costa Rica, El Salvador,Paris" (re-pattern “, *”))
04:43clojurebot#error {\n :cause "Unable to resolve symbol: “ in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: “ in this context, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6704]}\n {:type java.lang.RuntimeException\n :message "Unable to resolve symbol: “ in this context"\n ...
04:44Olajyd,(clojure.string/split "Costa Rica, El Salvador,Paris" (re-pattern ", *"))
04:44clojurebot["Costa Rica" "El Salvador" "Paris"]
04:51TEttingerlooks like you got it on your own, Olajyd!
04:52TEttinger(inc Olajyd) ; for learning by doing
04:52TEttinger(dec lazybot) ; for never being online
04:52Olajyd(inc TEttinger) for the support :D
04:59oddcully(inc luma)
05:08wombawombaSo I have a ^:dynamic var, that I would like to be able to set in the repl, *without* wrapping every single call to a function that touches it with (binding [...] ). How do I accomplish this?
05:09wombawomba(I would be cool with having something like a set-my-var-to-the-repl-value function, that could be manually called)
06:07hyPiRionwombawomba: (set! *var* foo), no?
06:08hyPiRion,(set! *print-length* 7)
06:08clojurebot7
06:08hyPiRion,(range 10)
06:08clojurebot(0 1 2 3 4 ...)
06:08hyPiRion,*print-length*
06:08clojurebot5
06:09hyPiRion,( o (set! *print-length* 7) (range 10))
06:09clojurebot#error {\n :cause "Unable to resolve symbol: o in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: o in this context, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6704]}\n {:type java.lang.RuntimeException\n :message "Unable to resolve symbol: o in this context"\n ...
06:09hyPiRion,(do (set! *print-length* 7) (range 10))
06:09clojurebot(0 1 2 3 4 5 6 ...)
06:28noncomjustin_smith: yes, in reagent. i think that having a per-page small status atoms, like what subpage is displayed is ok, and have a browser-local database-like state in a dedicated namespace where all the main data model is stored
06:29noncomhowever, maybe there is a better design or maybe this one can bring complexions later
06:29noncom*complications
06:35voytechHello all, I have a question, I'd like to do something like (binding []) but to be able to initialize var automatically and to have dynamic scope to be able to get binding value in inner function. Is this possible ?
06:36voytechI want almost the same functionality as binding, but to not to be required to initialize var ealier.
06:48hyPiRionvoytech: bound-fn?
06:52voytechhyPiRion: As I see bound-fn is rather to move bindings into different thread. I'd like to not have to call: def :^dynamic somevar before we can use it in binding []
06:53voytechhyPiRion: I think I can do this by interning var then accessing in nested function by var-get and then removing from ns
06:54voytechhyPiRion: But I was looking for better way.
06:55voytechhyPiRion: My question is because I have some function local vars which I want to be visible in nested function with the same binding, but I do not want to use def :^ dynamic inside function.
07:10Empperihmm, I'm trying to open an InputStream against a File object with explicitly defined encoding
07:10Empperibut it looks like clojure.java.io doesn't use the applied opts at all in that scenario
07:10Empperifirst it goes here https://github.com/clojure/clojure/blob/master/src/clj/clojure/java/io.clj#L229
07:11Empperiwhere it creates FileInputStream object directly from the given File object, no problem here
07:11Empperihowever, then it goes here https://github.com/clojure/clojure/blob/master/src/clj/clojure/java/io.clj#L191
07:11Empperiand there opts is silently ignored
07:12Empperiwhich kinda sucks ass
07:12Empperibut! now I understand
07:12Empperiof course... I should use a Reader
07:12Empperiforget it ppl :)
07:34wombawombaif I'm interacting with a library from the repl, and that library requires me to bind a ^:dynamic var to work, is there any way to get around having to wrap every single call in (binding [lib/var myvalue] ...)?
07:35anehttps://www.refheap.com/109644 is this the right way to do this?
07:36justin_smithwombawomba: you could just set the root binding with set! right?
07:36justin_smithor does that not work with dynamic vars...
07:36wombawombano idea lol, I'll try that right away
07:36justin_smithane: instead of an atom plus while, use go-loop and a branch where you don't call recur
07:37aneoh, that exists
07:37justin_smithane: also, alts! returns a two element vector, the value and the channel it came from
07:37aneyeah, but i don't need the channel
07:38justin_smiththen don't use it!
07:38justin_smithbecause right now v is the two element vector :)
07:38ane<! will work just fine?
07:38justin_smithif you are only reading from one channel, indeed it will
07:38wombawombajustin_smith: java.lang.IllegalStateException: Can't change/establish root binding of: *the-thing-i-want-to-set* with set
07:38justin_smithwell OK then
07:40justin_smith"Currently, it is an error to attempt to set the root binding of a var using set!, i.e. var assignments are thread-local."
07:41justin_smiththe next question should be obvious...
07:42wombawombawelp I don't know what the next question should be :(
07:43justin_smithhow to set the thread-local rather than root value
07:43wombawombaoh, okay
07:43justin_smith(other than binding which is impractical of course)
07:43wombawombayeah
07:43justin_smithbut I don't know the answer to that one yet
07:48wombawombajustin_smith: I tried using https://clojuredocs.org/clojure.core/push-thread-bindings, but I can't get it working in the repl..
07:51justin_smithwombawomba: you can set dynamic vars for your repl in project.clj, maybe doing it that way is easiest?
07:51justin_smiththough I would really prefer something that you could do from scratch in a repl
07:53anejustin_smith: replaced it with this https://www.refheap.com/109646
07:53anei guess that could be even shorter with if-let
07:53ane*when-let
07:54justin_smithyup, that would probably be the thing, and at that point it would be perfect I guess
08:02wombawombajustin_smith: how would I do that?
08:02visof__how can i generate random numbers between 0 and 1?
08:02wombawombaI guess I could make the library check if some var is set, to try to figure out if it's part of the repl, but... eh
08:02wombawombait seems there should be a better way..
08:02justin_smith,(rand) ; visof__
08:03clojurebot0.004625421258164786
08:04visof__,(rand 1)
08:04clojurebot0.47916350622420223
08:04visof__,(rand 1)
08:04clojurebot0.3507468588750795
08:04visof__,(rand 1)
08:04clojurebot0.16249550680299163
08:04visof__,(rand 1)
08:04clojurebot0.4649720453046504
08:04visof__that's great
08:04justin_smithvisof__: you don't need the arg
08:04justin_smith,(rand)
08:04clojurebot0.22746045171118823
08:04visof__justin_smith: its limit to 1
08:04visof__?
08:04visof__,(rand)
08:04clojurebot0.09761248165826408
08:04visof__,(rand)
08:04clojurebot0.27152246889876974
08:04visof__,(rand)
08:04clojurebot0.5025658325879707
08:04visof__,(rand)
08:04clojurebot0.11801785522003727
08:04visof__,(rand)
08:04clojurebot0.7971211475060466
08:04visof__,(rand)
08:04clojurebot0.1795771621448604
08:05justin_smith,(apply (juxt min max) (repeatedly 1000 rand))
08:05clojurebot[2.9476404946426893E-4 0.9995800375194103]
08:05justin_smithout of 1000 calls, those were the smallest and largest resulting values
08:05wombawombais there any way to modify lein repl commands before they are run?
08:06justin_smithwombawomba: you can set root bindings in project.clj
08:06visof__,(apply (juxt min max) (repeatedly 1000 (rand 1)))
08:06clojurebot#error {\n :cause "java.lang.Double cannot be cast to clojure.lang.IFn"\n :via\n [{:type java.lang.ClassCastException\n :message "java.lang.Double cannot be cast to clojure.lang.IFn"\n :at [clojure.core$repeatedly$fn__5099 invoke "core.clj" 4924]}]\n :trace\n [[clojure.core$repeatedly$fn__5099 invoke "core.clj" 4924]\n [clojure.lang.LazySeq sval "LazySeq.java" 40]\n [clojure.lang.LazySeq seq...
08:06justin_smithvisof__: repeatedly needs a function
08:06justin_smithwombawomba: https://github.com/technomancy/leiningen/blob/master/sample.project.clj#L258
08:07visof__,(apply (juxt min max) (repeatedly 1000 (fn [] (rand 1))))
08:07clojurebot[1.0407398903533593E-4 0.9988080589538587]
08:07wombawombajustin_smith: but I only want this to happen in the repl
08:07visof__,(apply (juxt min max) (repeatedly 1000 (fn [] (rand 1))))
08:07clojurebot[9.545941192781182E-4 0.9993885416513495]
08:07justin_smithwombawomba: then put it in the repl profile?
08:08gilliardvisof__: have you looked at the source for (rand) ?
08:08visof__justin_smith: is there more accurate to only get random numbers between 0 and 1?
08:08visof__gilliard: nope
08:08gilliard(rand n) just does (* n (rand))
08:08justin_smithvisof__: accurate? what do you mean?
08:08wombawombajustin_smith: ok
08:08justin_smithvisof__: those min and max values are pretty damn close to 0 and 1
08:09visof__ok
08:11wombawombajustin_smith: so the binding I want to change is part of a specific namespace, and it seems I can't override that using the :global-vars thing
08:12wombawomba(because that's only for global vars, I guess)
08:12justin_smithoh, because the ns is not loaded yet
08:12justin_smithall vars are global, once they exist
08:12wombawombaalright
08:12justin_smith(except with-local-vars but nobody uses that)
08:12justin_smithwombawomba: maybe an injection that loads the ns before setting the global binding? not sure
08:13wombawombayeah, maybe
08:13wombawombathat's also kinda bad though
08:13justin_smithor make an alternate -main that launches an nrepl server inside a (binding [...] ...) block
08:13justin_smithdynamic vars seem like a real pain in the ass
08:14wombawombaideally I would want this to happen *from* the repl
08:14wombawombabasically, what I'm doing is I'm writing a docker wrapper, that starts up or attaches to containers and helps you communicate with them
08:16wombawombawhen running the actual code, I want to always get fresh containers (the goal is to use this for testing)
08:16wombawombabut in the repl, I want to be able to either start a container or attach to one that's already running
08:17wombawombaalso, I don't want to have to pass references to the containers around everywhere
08:17wombawombawhich is why I'm using bindings
08:18wombawombawhich works great, since it allows me to have different threads spin up and manage their own containers
08:18wombawombaaand it allows me to override the default behaviour when I'm working in the repl, so I don't have to deal with restarts etc
08:19wombawomba..but then that requires me to wrap everything in (binding [*container-a* my-repl-container *container-b* my-other-repl-container] ...), which is bad
08:19wombawombamaybe there's another approach I could take that would work?
08:24cross[A
08:44wombawombajustin_smith: in case you're interested, I did find a solution that works pretty well :)
09:37visof___1,(reduce and false [false false true])
09:37clojurebot#error {\n :cause "Can't take value of a macro: #'clojure.core/and"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Can't take value of a macro: #'clojure.core/and, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6704]}\n {:type java.lang.RuntimeException\n :message "Can't take value of a macro: #'clojure....
09:38visof___1,(every? true [false false true])
09:38clojurebot#error {\n :cause "java.lang.Boolean cannot be cast to clojure.lang.IFn"\n :via\n [{:type java.lang.ClassCastException\n :message "java.lang.Boolean cannot be cast to clojure.lang.IFn"\n :at [clojure.core$every_QMARK_ invokeStatic "core.clj" 2553]}]\n :trace\n [[clojure.core$every_QMARK_ invokeStatic "core.clj" 2553]\n [clojure.core$every_QMARK_ invoke "core.clj" -1]\n [sandbox$eval48 invoke...
09:38visof___1,(every? [false false true] true)
09:38clojurebot#error {\n :cause "Don't know how to create ISeq from: java.lang.Boolean"\n :via\n [{:type java.lang.IllegalArgumentException\n :message "Don't know how to create ISeq from: java.lang.Boolean"\n :at [clojure.lang.RT seqFrom "RT.java" 535]}]\n :trace\n [[clojure.lang.RT seqFrom "RT.java" 535]\n [clojure.lang.RT seq "RT.java" 516]\n [clojure.core$seq__4116 invokeStatic "core.clj" 137]\n [cloj...
09:40visof___1,(every? true? [true false false])
09:40clojurebotfalse
10:11lodin-awayvisof___1: You can wrap and in a function, #(and %1 %2), but note that it will not short circuit.
10:55TimMcWhat's a reasonable way to determine if a value appears anywhere in the leaves of a data structure?
10:55TimMcI'm looking for a string somewhere in a big pile of records, vectors, and seqs.
10:55clojurebotTitim gan éirí ort.
10:56TimMcOf note, flatten (which I was eyeing suspiciously) doesn't flatten maps.
10:57sobelTimMc: maybe useful? https://mwfogleman.github.io/posts/20-12-2014-flatcat.html
11:01TimMcah, tree-seq!
11:02expezfunctions updating the state of an agent are subject to retries, right?
11:03expezOr is there an internal queue of next states?
11:03expezstatic class ActionQueue
11:03expezsweet
11:05TimMc(.contains (tree-seq coll? #(if (map? %) (vals %) %) ds) "search-item")
11:06TimMcEven better: (tree-seq coll? seq ds)
11:19phaseNiHello, is it possible to use reify dynamically? for instance, pass it a generated seq of methods rather than putting it in the code
11:20sobeli don't see why not
11:23phaseNii get a null pointer exception from the compiler
11:23phaseNi(reify VariousMessageListenerAdapter methods)
11:24lumareify is a macro, you can't pass the methods dynamically
11:24phaseNiwould eval work?
11:30lodin-What do you usually use for handle expected failures when just returning nil is not enough? I often just return [:success ...] or [:failure ...] and use core.match on the returned value. Any nice library out there that you use?
11:38sobelcould you wrap reify in a fn?
11:40voytechlodin-: I'd probably end up with something like throwing ex-info and maybe core.match on exception data ?? (but this is only my first thought - I'm not convinced it will match your needs)
11:41lodin-voytech: I avoid throwing when the failure is a valid response.
11:42lodin-phaseNi: I rarely use reify, but all methods must belong to an interface (possibly genereted by defprotocol), right?
11:43voytechlodin-: Ah ok, if it is something expected then throwing seems to be not best choice.
11:47sobelif you make your functions nil-tolerant then you can get away with fewer throws from creational code
11:47sobelor that's been my nominal experience
11:49lodin-sobel: Right, but nil does not convey any information, so to be able to handle the failure you need to pass out some kind of failure information.
11:50sobelthat's fair. my error handling fu in clojure is not very strong yet
11:52lodin-Returning [:success x] instead of x and [:failure info] instead of (throw (ex-info "Failure" info)), and unpacking with core.match works rather well.
11:54lodin-I'd prefer to use a library that might add some sugar and what-not, if such a library exists. A superficial search on clojars didn't turn up any though.
12:00sobelyes, tagging returns sounds pretty hip
12:13zipprI'm building a Hacker News reader in ClojureScript as a learning exercise. I'm building up a vector of maps of stories, but I'm mutating an atom to do so. I'm wondering if there's a better way to do this, using pure functions? The thing that's throwing me off is that the requests are async, so I'm not sure if I could use something like reduce. http://pastebin.com/Xbpg8LzU
12:14zipprI'm using this lib for ajax calls https://github.com/JulianBirch/cljs-ajax
12:19zipprMy example above works, but I'd like to batch the 30 calls together, and reset! the atom after I've gotten results for all API calls
12:19zipprNot sure if I need futures or core.async for this
12:27lodin-zippr: I don't have a full understanding of your problem, but I'd say core.async.
12:29zipprlodin-: Basically I'm wondering if I can use pure functions to build up a data struct instead of mutating the atom repeatedly.
12:32blake_I have a string I want to put into HTML output: <link href="/style.css" rel="stylesheet" type="text/css">
12:33blake_I found htmlize but I was wondering if there wasn't something amongst the many libraries I've been using that would do this.
12:33Deraenzippr: https://github.com/r0man/cljs-http works great with core.async for doing http calls
12:33blake_Maybe not, considering I haven't had to do it until now.
12:33lodin-zippr: I have not used cljs-ajax. I assume that GET returns immediately and handler is invoked when the response is available?
12:33zipprlodin-: correct
12:35lodin-zippr: In that case you can use a promise and deliver in the handler, and the other code in the handler is pure. Like (let [stuff (promise)] (GET :handler #(deliver stuff (f %))) @stuff). But I'd opt for core.async.
12:37zipprlodin-: Interesting; I'll check that out. Thanks.
12:40Deraenzippr: lodin-: Cljs doesn't have promises
12:40blake_Hmm. HTMLize is an emacs macro.
12:41lodin-Deraen: I always forget that cljs not= clj. I haven't learned the differences yet. I do it the hard way (i.e. code as if it was clj and discover I need to do it differently). :-/
12:42lodin-zippr: Correction. I *really* opt for core.async. ;-)
12:43zipprlodin-: Deraen: :-) core.async it is
12:43DeraenAnd instead of trying to use cljx-ajax with core.async I would suggest using cljs-http
12:44zipprAny recommended resources for learning core.async?
13:03joefromctdoes anyone know where i can find more help or documentation on sparkling? Specifically i'm trying to understand how to deploy with a master on yarn.
13:15zerokarmaleftzippr: https://github.com/cognitect/async-webinar
13:18WorldsEndlessI'm trying to get the hang of monger/mongodb and can't seem to figure out the syntax to use $set in my update function
13:18zerokarmaleftzippr: the core.async repo has a repl-friendly walkthrough also under examples/
13:19WorldsEndless(coll/update libdb "books" {:author "Tolkien"} {$set {:title "The Fellowship of the Ring"}}) ;; fails "unable to resolve symbol: $set"
13:22justin_smithI just got my copy of Clojure Applied in the mail
13:23justin_smithWorldsEndless: what is $set supposed to be? it's not a valid definition clearly
13:23WorldsEndless$set is a mongo symbol to simply change the given without altering the other items; supposedly monger supports it, so I'm trying to get it to work
13:24justin_smithWorldsEndless: then maybe you want a symbol
13:24justin_smith'$set is a symbol
13:24WorldsEndlessjustin_smith: You are correct. Odd that the documentation gave a different example of usage
13:25justin_smithWorldsEndless: maybe they quoted the whole hash-map
13:25uris77I've used "$set"
13:25justin_smith'{$set {:title ...}}
13:25WorldsEndlessOh, wait. They have [monger.operators :refer :all] in the ns declaration; I'm guessing that does it
13:26uris77yeah
13:27uris77i've used it like this, now that I recall, https://github.com/uris77/pasmo-gigi-clj/blob/master/src%2Fpasmo_gigi%2Fdb%2Foutlet_surveys.clj#L7
13:27uris77I remember struggling to find the namespace
13:34WorldsEndlessWhoa... just discovered the grimoire. I have a feeling that clojure just got easier.
13:46trissso laziness.... when we do a `map` or `filter` or whatever the first 30 elements in the seq are evaluated immediately aren't they?
13:46trissIs it possible to defer evaluation right up until the values are used?
13:48lodin-triss: Google for dechunk and/or seq1.
13:48trisscheers lodin-
13:53justin_smithtriss: also, you could use something like reduce/reduced where you can separate the laziness of the source from the optional creation of side effects
13:54trissthanks justin_smith ... got some serious mulling over to do.
13:54lodin-triss: Or use transducers, see http://stuartsierra.com/2015/08/25/clojure-donts-lazy-effects .
13:55trissI've got seqs with functions embedded that may or may not use state from the outside world.
13:55justin_smithtriss: or even doseq of course
13:55justin_smith(doseq [el (take 10 source)] (frob el))
13:55justin_smithin that case, the chunking of "source" does not matter
13:56justin_smithonly 10 elements will be frobbed
13:56mavbozo,(take 2 (map println (range 50)))
13:56clojurebot(0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\nnil nil)
13:56justin_smith,(doseq [el (take 2 (range 50))] (println el))
13:56clojurebot0\n1\n
13:56justin_smithsee, much better behaved
13:57trissaha..... thanks justin_smith
13:57trissdoseq looks like what I'm after I think....
13:59noncomhttps://pbs.twimg.com/media/CPDVoj8WUAA56UD.jpg think different..
14:00justin_smithwow that's annoying
14:00justin_smithI hope someone makes adaptors
14:00noncomhaha :) that pretty much encompasses the overal experience of working with apple thinkgs for me..
14:00blkcatlol
14:00lumathat would be fun if it were true
14:00blkcatoh apple, those lovable scamps
14:00snowellThat seems overly contrarian even for Apple
14:01lumaall manufacturers use the "apple connector" nowadays
14:01noncomheh, just a little fun, yeah :)
14:01justin_smithalso, it's long established that your ground is the ring that is furthest out
14:01justin_smithlike, pretty much every ring and tip plug ever does this
14:01justin_smithbut of course they have to not do that because reasons
14:04noncomjustin_smith: so, about the state for a single-page app. i am thinking of having one db-like namespace to store all app space and little atoms to store things like "current-catalog-page-number" locally in the relevant namespaces
14:04noncomits reagen atoms
14:04noncomhow do you think, that's ok?
14:04justin_smithnoncom: that sounds reasonable. In my own current app we somewhat accidentally ended up with all state in a single atom, and then having a special :page key that gets overwritten for different view states
14:05justin_smithbut separate atoms per page would be nice for a few reasons...
14:06noncomyeah, mainly to have it in small portions and to have it locally.. okay then!
14:07lodin-noncom: I've been going back and forth on this. I think the replayability you get if you do it re-frame style could be quite valuable. I have not had the chance to utilize that yet.
14:07justin_smithnoncom: for example, if we have a request to some endpoint, where the endpoint returns data that is only relevant to a specific page
14:07justin_smithif the page data was separate, the user could come back to that view and get data that had trickled in
14:08justin_smithas opposed to maybe randomly getting data stuck on your page that was originally meant for a different page
14:09trissis there a pred that returns true if value passed to it is a vector or a list but not any other type of value?
14:09justin_smith#(or (vector? %) (list? %))
14:09justin_smithbut checking for lists is pretty much useless
14:09justin_smithlazy seqs are not lists
14:09justin_smith(for example)
14:10lodin-(every-pred vector? list?), if you don't like %. :-)
14:10lodin-oh. no.
14:10justin_smithlodin-: wrong logical operator
14:10noncomi see...
14:10lodin-Yes.
14:10justin_smithyou want some-pred
14:10justin_smithheh
14:10sdegutisjustin_smith: what router do you use
14:10sdegutisfor http routing
14:10justin_smithsdegutis: I wrote one from scratch in like 50 lines
14:10sdegutisniiiice
14:10lodin-justin_smith: I read and, but then I was like "can't be both list and vector". Heh.
14:10justin_smithsdegutis: oh, http, never mind
14:11sdegutisjustin_smith: does it have functionality similar to clout?
14:11sdegutisjustin_smith: by http I meant e.g. compojure
14:11justin_smithsdegutis: http I wrote one in more than 50 lines it is called polaris (also other people helped) caribou/polaris
14:11justin_smithpolaris uses clout (but if it were up to me alone it would not have)
14:11snowell,(doc some-pred)
14:11clojurebotPardon?
14:12justin_smithsnowell: I don't think that actually exists
14:12snowellThat's what I was seeing, and I was confused :)
14:12lodin-,(doc some-fn)
14:12clojurebot"([p] [p1 p2] [p1 p2 p3] [p1 p2 p3 & ps]); Takes a set of predicates and returns a function f that returns the first logical true value returned by one of its composing predicates against any of its arguments, else it returns logical false. Note that f is short-circuiting in that it will stop execution on the first argument that triggers a logical true result against the original predicates."
14:12sdegutisjustin_smith: why not?
14:12sdegutisre: clout
14:12justin_smithsdegutis: I'd rather use a trie based approach rather than multiple regexes
14:13sdegutisjustin_smith: you mean tree-based?
14:13justin_smithit's cleaner / cheaper
14:13justin_smithsdegutis: no I mean trie based
14:13sdegutisjustin_smith: is that the thing bidi and silk do?
14:13trissthanks guys!
14:13justin_smithsdegutis: you can take a series of routes and from them build a trie that quickly finds an input's destination
14:14justin_smithit's as if it is making a single regex out of all your routes, and can call the apropriate handler based on the match
14:14justin_smithsdegutis: hmm, I don't know if they use tries...
14:14sdegutisjustin_smith: sounds like it would have an ugly API
14:14sdegutisnot as convenience as e.g. compojure
14:14justin_smithsdegutis: nah, you hand it a series of strings and functions, it returns a function that finds the first match among those strings given an input, and returns the apropriate function
14:14sdegutisjustin_smith: I mean for variables inside paths.
14:15justin_smithvariables only make it slightly harder to implement
14:16sdegutisjustin_smith: why didn't you use a trie?
14:16justin_smithit doesn't look like bidi uses a trie, no
14:16justin_smithsdegutis: I didn't design that part of polaris
14:17justin_smithsilk doesn't either
14:18DomKMAs far as I know the only trie-based Clojure router is Pedestal.
14:28agarman_is there a way to get the enclosing var name from a macro?
14:28justin_smithagarman_: as in, a macro knowing its own name?
14:29agarman_(defn foo [] (insert-macro-here)) ;; where inserted macros determines it's in #'foo
14:29justin_smithabsolutely not
14:29agarman_yeah, all I could find is line numbers
14:29agarman_which is about 80% useful
14:30agarman_oh and file name
14:30justin_smithknowing what surrounds it that breaks a basic clojure assumption about scope and power of expressions (and that assumption brings a lot of sanity with it)
14:30agarman_so very round about I could read into the file to get the info, but in an ugly way
14:30justin_smithnot to say your own plan is totally insane, but in general, it keeps things sane
14:30agarman_yeah, that's not my plan
14:31justin_smithlike, imagine if when I wrote code I had to stop and wonder about special case forms that totally change in behavior based on their caller?
14:32agarman_yeah, it'd be pretty basic stuff available to C#
14:32agarman_that's useful for logging with context without the pain of adding boiler plate
14:34justin_smithuh...
14:34justin_smithagarman_: you can get context from the stack trace, you can get the stack trace of the current thread, and walk up until you find a "relevant" namespace
14:35justin_smithagarman_: I guess the hard part would be the "is this namespace relevant" code
14:35agarman_I'd want the info at compile time.
14:46anecan i somehow examine a reified object to see what method it has
14:48anemethods*
14:53justin_smithane: you can check what interfaces it claims to implement
14:55justin_smith,(instance? clojure.lang.IDeref (reify clojure.lang.IDeref (deref [this] "hi")))
14:55clojurebottrue
14:55justin_smith,@(reify clojure.lang.IDeref (deref [this] "hi"))
14:55clojurebot"hi"
14:58gfredericks,@@@@@@@@@@@@@@(reify clojure.lang.IDeref (deref [this] this))
14:58clojurebot#object[sandbox$eval77$reify__78 0x24980d0 {:status :ready, :val #object[sandbox$eval77$reify__78 0x24980d0 {:status :ready, :val #object[sandbox$eval77$reify__78 0x24980d0 {:status :ready, :val #object[sandbox$eval77$reify__78 0x24980d0 {:status :ready, :val #object[sandbox$eval77$reify__78 0x24980d0 {:status :ready, :val #object[sandbox$eval77$reify__78 0x24980d0 {:status :ready, :val #object[sa...
15:01sdegutisjustin_smith: I don't understand.. why does polaris use an :identifying-key instead of just a map of a route to a function?
15:03justin_smithsdegutis: so that we can do reverse routing, or store routes in a db
15:03sdegutisOooh, reverse routing. That makes sense.
15:03sdegutisStoring routes in a DB seems strange...
15:03justin_smithroutes as pure data opens up a lot of power
15:03justin_smithsdegutis: in caribou, you can use the cms to create a page
15:03justin_smithwhen you create a page, you need to also create a new route
15:03sdegutisoooh
15:04sdegutisWell that's one way of looking it up I guess.
15:04justin_smithsdegutis: this means that frontend guys, or even a producer, can throw a new page into the app
15:04justin_smith:)
15:04justin_smithit is all about RAD
15:04sdegutissure but RAD means something different for us
15:04sdegutiswe dont need CMS functionality
15:05sdegutisreverse-routing however would be nice
15:05justin_smithor, more likely, a producer doesn't create a page, but a client demands a different name for some route string (bikeshed!) and the producer can just go in and change it in the cms ui to the db
15:05justin_smithand thanks to reverse routing, even our generated links to that URI in other pages are automatically still correct
15:06justin_smithand if we were smart enough not to hard code any routes, nothing breaks!
15:15mungojellymy thinking keeps getting confused where "everything is data" meets "everything is an infinite lazy sequence"
15:17opqdonutbut everything is not an infinite lazy sequence
15:17opqdonute.g. [1 2 3], nil or :hotdog
15:17opqdonutor (defn factorial [n] (if (= n 0) 0 (* n (factorial (dec n)))
15:18blake_I'm having a Java freakout. https://www.refheap.com/109660
15:19blake_If I have a function a that returns an javaObject, then outside-fn(a) should be the same as outside-fn(javaObject.), right?
15:19blake_Especially if javaObject returns the SAME object every time?
15:20blake_i.e., (= a javaObject.)?
15:20opqdonutblake_: looks really weird
15:21opqdonutblake_: I guess .-text is resolving to a different method in the different calls somehow
15:21opqdonutor at least I've had something like that happen in the past
15:21blake_It is weird. The problem I'm having is that in code (not in REPL) is ALWAYS giving the formula, and it should not.
15:22opqdonutor perhaps .apply is getting resolved differently
15:22blake_Well, .apply returns a CellFormatResult which has, like, three methods.
15:22blake_Maybe apply. CellFromat is more complex.
15:22opqdonutthere's a .apply(Cell c) and .apply(Object o)
15:22opqdonutyes that must be it
15:22opqdonutthe variable cf isn't hinted
15:22opqdonutso it will resolve to the Object version
15:22opqdonutthe call CellFormat is hinted (because it's java)
15:23opqdonuttry: (.-text (.apply ^CellFormat cf cell))
15:23opqdonuterr no
15:23blake_opqdonut: That breaks it! I'd say that's progress. =P
15:23opqdonutdisregard my explanation, it's Cell vs Object not CellFormat vs Object
15:24opqdonuttry: (.-text (.apply cf ^Cell cell))
15:24blake_opqdonut: Aha!! That may have done it!
15:25opqdonutyeah now that I think of it this is exactly the case that I had
15:25opqdonutsome object had both .foo(Something s) and .foo(Object o) methods
15:25blake_Bingo!!!
15:25blake_(inc opqdonut)
15:25blake_(I think points are even more imaginary than usual these days, but the intention is there.)
15:26opqdonutyou might want to write a helper function to make sure you get the right .apply
15:26opqdonutinstead of sprinkling hints left and right :)
15:27blake_opqdonut: Yeah, I may. I'm working on cleaning up some example code written in Java, and moving as much as I can into Clojure.
15:27blake_So, that's good to know. I don't know if I'd have been able to figure that one out.
17:10justin_smith,(map count ((juxt identity set) (remove #{\space \, \!} "sphinx of the black quartz, judge my vow!")))
17:10clojurebot(32 26)
17:12justin_smithso it re-uses 6 letters, but it uses all of the basic lower case letters
17:14justin_smith,(map count ((juxt identity set) (remove #{\space \, \!} "sphinx f black qurtz, jdge my vow!")))
17:14clojurebot(26 26)
17:15justin_smiththat version is dumb
17:21phorseI need to deploy a clojure webapp with apache. Do I have to mess about with Tomcat or can I just proxy to whatever port lein ring server shows up on?
17:21ed-gphorse, I prefer to reverse proxy to the lein ring server port
17:21justin_smithphorse: don't use lein on production
17:21justin_smithphorse: it's a waste of ram
17:21justin_smith(among other issues)
17:22phorseOkay, so there is a preformance benifet to using tomcat.
17:22justin_smithwell, you can also use "java -jar my-uber.jar"
17:22DeepSymmetryYou don’t need to use tomcat, … right, what justin_smith said.
17:22justin_smithlein uberjar - simple
17:23phorseGreat! I've been wrestling with out-of-date tomcat docs all day. Thanks.
17:23justin_smithother advantages include being able to go back to a previous deployed version all you need is a single file backed up, faster startup
17:23sobeleven up-to-date tomcat docs would be unnecessary
17:25ed-gI've been trying to use uberjar for deployment but when I attempt to build the jar it says my class file is too large.
17:25justin_smithed-g: the class file for your main ns?
17:25ed-gjustin_smith, yes
17:26justin_smithed-g: a quick fix for that would be to move functions into another namespace (so they end up in a different compiled class)
17:26justin_smithed-g: also, it's possible to do an uberjar with no aot / no gen-class
17:26ed-gjustin_smith, ok for some reason I thought aot was required when building an uberjar
17:26justin_smithed-g: the key is that you run it with "java -cp my-uber.jar clojure.main -m my-ns.core"
17:27justin_smithed-g: it just makes it easier to run
17:27ed-gjustin_smith, thanks for the help! I spent a number of hours on this a few months ago and eventually gave up.
17:27justin_smithbut with a command line like the above you can run whatever
17:27justin_smithed-g: another awesome trick - on prod you can run "java -cp my-uber.jar clojure.main" and get a clojure repl running on prod
17:27justin_smithwith all your code available in that repl (as of jar packaging time, of course)
17:28ed-gthat's cool. I've been running an nREPL server (on a private port) but that's handy because I only really use it every once in a blue moon.
17:29DeepSymmetryThe advantage of the nREPL server is that it will let you connect to your running VM.
17:29justin_smiththat's true
17:47phorseI've built an uberjar that works fine on my dev machine, but when I try to java -jar myapp.jar on the server, it throws an error about Buddy's bcrypt. I thought that the magic was supposed to work the same everywhere, is there something I'm missing?
17:47justin_smithphorse: it generates two files
17:47justin_smithyou want my-app-standalone.jar
17:48phorseOh, I didn't even notice the other one. I'l ltry that.
17:51DeepSymmetryThe smaller one is a library jar you can use in conjunction with other library jars (like would be served from Clojars) with Leiningen. The standalone jar embeds all the libraries you used into one massive jar that can be used all by itself.
17:54phorseOk. Actually, it looks like I was using the larger file, it just wasn't labelled 'standalone'.
17:54phorseWhen I run java -jar myapp.jar (the big one), it boots up on localhost:3000 and works just fine.
17:54phorseTransfer it over to the server and the same thing generates a stacktrace.
17:54justin_smithphorse: can you share the stack trace?
17:55phorseSure:
17:55justin_smithfor example on http://refheap.com
17:55justin_smithdon't paste it here
17:55phorseException in thread "main" java.lang.UnsupportedClassVersionError: buddy/impl/bcrypt/BCrypt : Unsupported major.min or version 51.0
17:55phorse at java.lang.ClassLoader.defineClass1(Native Method)
17:55phorse at java.lang.ClassLoader.defineClass(ClassLoader.java:643)
17:55phorse at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
17:55phorse at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
17:55phorse at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
17:55phorse at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
17:55phorse at java.security.AccessController.doPrivileged(Native Method)
17:55phorse at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
17:55phorse at java.lang.ClassLoader.loadClass(ClassLoader.java:323)
17:55justin_smithphorse: it's a problem with your jdk version
17:55phorse at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
17:55phorse at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
17:55justin_smithand don't paste things like that here
17:55phorse at java.lang.Class.forName0(Native Method)
17:55phorse at java.lang.Class.forName(Class.java:274)
17:55aneeurgh
17:56phorse at clojure.lang.RT.classForName(RT.java:2154)
17:56phorse at clojure.lang.RT.classForNameNonLoading(RT.java:2167)
17:56phorse at buddy.hashers$loading__5340__auto____23.invoke(hashers.clj:15)
17:56phorse at buddy.hashers__init.load(Unknown Source)
17:56phorse at buddy.hashers__init.<clinit>(Unknown Source)
17:56phorse at java.lang.Class.forName0(Native Method)
17:56phorse at java.lang.Class.forName(Class.java:274)
17:56phorse at clojure.lang.RT.classForName(RT.java:2154)
17:56phorse at clojure.lang.RT.classForName(RT.java:2163)
17:56phorse at clojure.lang.RT.loadClassForName(RT.java:2182)
17:56phorse at clojure.lang.RT.load(RT.java:436)
17:56phorse at clojure.lang.RT.load(RT.java:412)
17:56justin_smithane: I really hate emacs "paste protection" which simply slows down your paste to prevent booting, instead of making you not paste
17:56phorse at clojure.core$load$fn__5448.invoke(core.clj:5866)
17:56phorse at clojure.core$load.doInvoke(core.clj:5865)
17:56phorse at clojure.lang.RestFn.invoke(RestFn.java:408)
17:56anejustin_smith: i think that's just standard irc server behaviour
17:57justin_smithane: no, the server kicks you for pasting too fast
17:57aneit may be his client then, don't know if he's using erc
17:57amalloyane: he's talking about clients that circumvent the (useful) server behavior
17:57justin_smithane: dysfunctional clients slow down your paste so you don't get kicked
17:57amalloyusually it's ERC
17:57aneirssi does this too
17:58justin_smithOK, I hate how irssi does it too (but erc also makes it easy to accidentally paste a huge block)
17:58aneirssi does have paste protection though, which is great
17:58anedefaults to five lines after which it'll ask "are you sure?"
18:11noncom|2i have bootstrap and jquery in my project deps so they are included in my webapp. now i want to have this: https://github.com/CWSpear/bootstrap-hover-dropdown
18:11noncom|2in their installation section they say that their lib is to be included AFTER bootstrap and jquery
18:11noncom|2how do I ensure that?
18:12noncom|2on my single html page there is no mention of either bootstrap or jquery
19:16noffleis there a way of killing a running clojure program (that you started from the repl via (-main)) that doesn't result in the repl also dying?
19:16justin_smithnoffle: Control-C in an nrepl at least
19:18blake_OK, working over a table in rows and columns (nested doseqs) and want to know what column and row I'm on.
19:19justin_smithblake_: you probably don't need nested doseq
19:19blake_justin_smith: Probably not. I'm working over someone else's code. It =is= side effect driven, at least until I rewrite it.
19:20blake_But I got a collection of rows, and I use the individual rows to get the columns.
19:20blake_My intern put a counter in there, which of course didn't work. ;)
19:21nofflejustin_smith: thanks. I think the library I'm using is starting a subprocess that opens a window, and I don't see a way to kill that window without crashing nrepl. But this smells like a lib-specific Q rather than a purely nrepl thing.
19:21justin_smith,(doseq [[i row] (map list (range) [[:a :b :c] [:d :e :f]]) [j e] (map list (range) row)] (print i j e \; \space)) ; blake
19:21clojurebot0 0 :a ; 0 1 :b ; 0 2 :c ; 1 0 :d ; 1 1 :e ; 1 2 :f ;
19:21justin_smithblake_: see above, I get each item, with a row number and a column number
19:22justin_smithwith one doseq, no nesting
19:22blake_justin_smith: Thanks...I think. =P
19:23justin_smithblake_: if it's confusing, feel free to ask more questions, but that's not an unusual usage of doseq, it's supposed to go down into nested indexes like that
19:24blake_justin_smith: I'm just under the gun. I'll do it right. Or righter...
19:25justin_smithblake_: anyway, (map list (range) c) or (map-indexed list c) are standard ways to get indexes for each item
19:25justin_smith,(map list (range) [:a :b :c])
19:25clojurebot((0 :a) (1 :b) (2 :c))
19:26blake_justin_smith: Thanks. I forget about map-indexed.
19:26justin_smith,(map-indexed list [:a :b :c])
19:26clojurebot((0 :a) (1 :b) (2 :c))
19:26blake_(fake-inc justin_smith)
19:26justin_smithI tend to just use the map list version, it's exactly the same number of characters :P
19:27blake_,(count "map-indexed")
19:27clojurebot11
19:27blake_,(count "map list")
19:27clojurebot8
19:27justin_smithremember it also has (range) in there
19:27justin_smithand you call list in both cases
19:28justin_smith,(map count ["(map-indexed list c)" "(map list (range) c)"])
19:28clojurebot(20 20)
19:28blake_Ahhh. =P
19:29blake_So...in Clojure JVM interop .- = . ?
19:30justin_smithblake_: .- is for field access
19:30justin_smith. is either field or method
19:30justin_smithblake_: with the jvm it is guaranteed unambiguous but you still might like .- for style reasons, with js it is not guaranteed unambiguous
19:30blake_I was trying to figure out if this was because there could be no class in Java.
19:31blake_Er, clash, not class.
19:31blake_Java's got all kinds of class.
19:31justin_smithheh
19:31blake_justin_smith: Right.
19:31justin_smithclassy as fuck
19:31blake_Yuge Classes. Gold leafed. Leather bound.
19:32justin_smithwith an emphasis on hereditary inheretance to make sure that the class division stays in the future
19:32justin_smithunlike those commie non-oo langs
19:34blake_ha
19:38blake_Ah, I think I got it. Thanks.
19:42blake_justin_smith: Crap, what if I need to do something between the row and the column? Like print out a <tr>?
19:42justin_smithblake_: aha, then you might want a nested doseq... - or just test for the first index going down
19:43justin_smithwait second index
19:43justin_smithtest if second index is 0
19:43blake_I guess I could wrap the...oh, yeah, that'd work. Sorta old school. Right.
19:43justin_smiththen bob's your uncle
19:51justin_smiththen bob's your uncle
19:56blake_justin_smith: Do we have a way of knowing we're at the end of one of the internal loops in a doseq?
19:57blake_I mean, I can call the same thing I called in the doseq and count it, but I was wondering if there was a better way. Nested doseqs might not have been bad here. =P
19:59justin_smithblake_: if you also need that, yeah, that might make it easier
20:00blake_Eh, good enough for now. This is "prove it can work" time.
20:03tolstoyI use loop/recur when I have to do that kind of thing and can't think of a different design.
23:00tmtwdis there source code for a macro that does the same thing as "if"?
23:09jeremylitetmtwd: it would have to be implemented in terms of cond
23:20neoncontrailsWhen implementing message passing, is it more idiomatic to pass the message as a keyword, quote literal, or string?