#clojure logs

2015-06-07

03:34cflemingSo I'm surprised to discover that the inferred type of the initialiser isn't propagated to :tag with plain def
03:35cflemingSo (def x "Hello") (.length x) is a reflective call.
04:01amalloycfleming: there was probably a time when :tag on vars was only for "function returning Foo", not actually "Foo"
04:02cflemingamalloy: Could be, yeah
04:02cflemingamalloy: BTW you asked a while ago about the type-inference augmented completion
04:03amalloyi remember
04:03cflemingamalloy: By far the most useful change turns out to be that on completion of something that looks like a field or method, I walk the local variables in scope and add completions from their classes.
04:04cflemingThat gives you the completions you want 95% of the time
04:04clojurebotHuh?
04:04amalloyyeah, i bet
04:04cflemingI'm still going to add the order-swapping completion but I'm not sure it'll be as useful after this change
04:04amalloybut i imagine locals often aren't hinted well wnough to help?
04:05cflemingI'm not sure in general, mine are because I make sure I have no reflective calls
04:05cflemingBut I'm the only one using this right now
04:08cflemingIt does work very well for when you have chained calls, which is very common: https://twitter.com/CursiveClojure/status/606387674052575232
04:09cfleming(i.e. I obey the inferred types, not just the tagged ones)
04:14amalloysure, of course
04:34H4nsdoes anyone remember the relatively recent blog post that showed the dramatic effects that missing type hints can have on performance? i'm unable to find it.
04:35H4nsalso, can anyone recommend a intermediate level clojure book? i've tried two from packt only to get reminded that packt usually publishes crap.
05:06cflemingH4ns: Have you read Joy of Clojure?
05:06cflemingH4ns: I'd recommend that if you haven't.
05:06H4nscfleming: thanks, i'll grab that!
05:27anti-freezeHi everyone. I'm having issues with multimethods. I want to create a multimethod with a default value, depending on the argument provided. For example (create :users {:username "someone"}), if a :users create is defined, it should call that. Now thats standard multimethod behaviour, though I want to be able to define a default method, so in the case that :users method isn't defined, create is called on the :users collec
05:27anti-freezetion. Any ideas?
05:29TEttingercfleming was around recently, amalloy before that, and they're both pros. and now here's tbaldridge!
05:30cflemingThanks for the vote of confidence TEttinger, but sadly I almost never use multimethods
05:30TEttingersame here
05:30anti-freezeIs there a better way to do this. Clojure noob here
05:31anti-freeze?*
05:32TEttingeranti-freeze, it's odd, multimethods are powerful but rarely written by many clojure users
05:32TEttingerI've never written one
05:33anti-freezeI feel like I'm taking a completely wrong approach. How do I handle default behaviour then?
05:33TEttingerI think there probably is a simple way, and it may involve multimethods
05:34cfleminganti-freeze: I actually seem to recall that multimethods allow you to use a :default dispatch
05:34cfleminganti-freeze: Yeah, they do: http://clojure.org/multimethods
05:34anti-freezecfleming: Yea, they do, but I don't think they allow you to get the type the method was dispatched with
05:36cfleminganti-freeze: Sorry, that's all I've got :-(
05:36anti-freezecfleming: Should I send you the sauce, maybe you can tell me why I can't seem to be able to clean this code up
05:37cfleminganti-freeze: Ok, refheap it up. I don't have long, but I'll take a look
05:39anti-freezecfleming: https://www.refheap.com/102234 This is how I'm using stuff currently. I have for example a (defn all-* [coll] (...)) method that I make in to a partial. Seems like a shitload of duplication for pretty standard operations
05:41cflemingSo "projects" is the name of a data store in mongo?
05:41cflemingLike a table or something?
05:41cflemingAnd you're doing this so you don't have to call (create-* "projects" ....)
05:41cfleming?
05:42cfleminganti-freeze: ^ ?
05:42anti-freezecfleming: Pretty much
05:43anti-freezecfleming: Its the same for every collection at the moment. The exact same copy-pasta for the users collection.
05:44cfleminganti-freeze: yeah, I don't think that's gaining you much. I'd just rename all-*, create-* etc to just add and create, and then use (create :projects ...)
05:44cfleminganti-freeze: The code reads the same, and you don't have that duplication
05:44anti-freezecfleming: Yup... Alright, I just spent 2 days wasting my time. Thanks wunderhacker
05:46cfleminganti-freeze: Generally I'm a huge fan of keeping things as simple as possible. I almost never use partial, I'd rather have a little duplication and see what's going on.
05:46cfleminganti-freeze: Functional programming sometimes seems like a race to ultimate conciseness, but I'm not a fan
05:47TEttingerI am a fan though
05:47TEttinger440 chars or less
05:47anti-freezeTEttinger: do you have any ideas on the matter?
05:48anti-freezeActually no, cfleming's argument is really valid
05:48TEttingeryes
05:48TEttingerI mostly make small laughably terse clojure snippets for IRC
05:48TEttinger,(let[a #(apply str(flatten %))r repeatedly p partition N rand-nth n #(a(N(concat(repeat %"")(mapcat p[1 2 3]%&))))v #(n 0"aioeu""iaai")w(fn[](let[b(n 6"!.""""...")s[(n 0"STKNYPKLG""GlThShNyFt""ZvrCth")(r(N[1 2])#(do[(v)(n 9(map str"'-"(r 2 v)))(n 0(concat"lpstnkgx"[(N["h""gl""gr""nd"])(v)])"rlthggghtsltrkkhshng")]))]][b(if(seq b)[" "s][(n 3",")" "(.(a s)toLowerCase)])]))](re-find #"[A-Z].+"(a[(r 500 w)"."])))
05:48clojurebot"Thirle'ong! Pagh piagek! Kauia-ond ying. Tholtiagg nyirk yurl shoggu'ong! Kaipult fti'agh tughia'ekh. Pegh... Thakhes tux sil, pok! Shasaig pugh. Ftiao ge-aitsai'egg! Lagh, gekhorl, sek, tais... Cthaioep, tasix, kugia'ol, pai-ughits. Zvrelt goguth gikh shang... Piashul kiats, nu-ap guth ftupep cthiag ftangiagr kot kax nyia-akhung, kughilt tun! Kiath ftotix ftosh goltait. Kiltugr koltash, yundailt...
05:48TEttinger&(let[a #(apply str(flatten %))r repeatedly p partition N rand-nth n #(a(N(concat(repeat %"")(mapcat p[1 2 3]%&))))v #(n 0"aioeu""iaai")w(fn[](let[b(n 6"!.""""...")s[(n 0"STKNYPKLG""GlThShNyFt""ZvrCth")(r(N[1 2])#(do[(v)(n 9(map str"'-"(r 2 v)))(n 0(concat"lpstnkgx"[(N["h""gl""gr""nd"])(v)])"rlthggghtsltrkkhshng")]))]][b(if(seq b)[" "s][(n 3",")" "(.(a s)toLowerCase)])]))](re-find #"[A-Z].+"(a[(r 500 w)"."])))
05:48lazybot⇒ "Gash cthailtoth, nyuth, gerlo'ogg! Shap gaipi-ait... Nox ctha'iand. Cthelt... Ftunilt, kug, na'iakh. No'ulus, kea! Kiarl! Thath... Nyerl, pia-eltaigg, laggol, piats! Tek ftel... Korl, kukha-osh thogg nyus lalog ftogh, te-ukh... Nyiang shaixog. Cthund... Nasoth gang... https://www.refheap.com/102235
05:48TEttingerto the refheap!
05:49anti-freezeI was going to define a macro and do a DSL to define operation groups and the use the (use-operations :default) to generate the methods
05:51oddcullyyou don't try to chant us an elder one?
05:52anti-freezeIt's how the came up with the dragon word thingies in skyrim
05:52anti-freezeClojure was used for skyrim
05:57TEttingermy favorite one-liner, srsly
05:57TEttingerlots of clojure features once you start being able to read that terse code
05:58TEttinger#(mapcat partition [1 2 3]%&)
05:58TEttingerthat's a key one
05:59TEttinger(#(mapcat partition [1 2 3]%&) "ABCD" "ThChPhWh" "CthSprZvr")
05:59TEttinger&(#(mapcat partition [1 2 3]%&) "ABCD" "ThChPhWh" "CthSprZvr")
05:59lazybot⇒ ((\A) (\B) (\C) (\D) (\T \h) (\C \h) (\P \h) (\W \h) (\C \t \h) (\S \p \r) (\Z \v \r))
05:59TEttingerthat's used throughout the snippet to get appropriate lengths of random letter sequences
06:00TEttingernever a Qj in there
06:28H4nsam i right in assuming that a type tag does not imply a cast in the java sense? i.e. if i have, say, a SQLConnection object which I know is a PGConnection, I need to both cast it and type tag it? (.getNotifications ^PGConnection (cast PGConnection conn))
06:30TEttingerH4ns, correct, a type hints are really just telling the compiler "this is currently this type, not a variable that could be any type" so the compiler knows what to do with it. but if the type hint doesn't match the actual type, it's ignored
06:31H4nsTEttinger: thanks!
06:32H4nsTEttinger: i wonder why the compiler does not know the type from the cast, though.
06:32H4ns(from the explicit cast, that is)
06:32TEttinger(doc cast)
06:32clojurebot"([c x]); Throws a ClassCastException if x is not a c, else returns x."
06:32TEttingerthat would be why :)
06:34H4nswell, that implies that the returned value always has the class given as argument to cast, doesn't it?
07:05cflemingH4ns: In your example, you don't need the cast
07:05cflemingH4ns: In that case, the hint is effectively a cast
07:09cflemingH4ns: TEttinger is correct that type hints really just tell the compiler what the type of an expression is, but in your case the compiler will then use that hint to look up the method at compile time, and will cast the object automatically to invoke it.
07:10sobelTEttinger2: is that Klingon?
07:11sobelor Lovecraftian
07:11H4nscfleming: thanks!
07:12cflemingH4ns: I do interop all day, and I've literally never used cast
07:13H4nsok - i'll avoid it
07:13H4nsis there a way to access a record's field so that the type tag is preserved? if i use keyword lookup, it seems that the type tag that i established with defrecord is not seen by the compiler.
07:14supersymthat shouldnt happen
07:14H4nsah, ok, right. my fault, sorry
07:14supersymthe use of 'type',
07:15BronsaH4ns: there's no way to preserve it, the type tag is compiled away
07:15supersymor 'name' or whatever doesn't matter as those are bound in local scope, their meaning doesnt apply anymore
07:15supersymunlike other languages where use of 'class' or 'type' indeed causes problems
07:15Bronsadefrecord/deftype fields are stored in `Object` fields, no matter what you type hint them with
07:16supersymah... type HINT .. different one
08:04mearnshhi all! looking for some workflow advice: i'm working on a clj/cljs proj (via chestnut) w CIDER. right now i've got two nrepl connections going so i can eval my cljs in one (via weasel) and clj in the other. but CIDER doesn't play too nice with this since the default shortcuts send everything to just one of the repls (hence i can only eval my clj code successfully)
08:12kwladykawhat is the difference in compojure between X-CSRF-Token and X-XSRF-Token? X-XSRF-Token is encrypted?
08:14kwladykaor there is no difference?
08:19noncommearnsh: also try #clojurescript
08:19mearnshyeah, thx
08:20noncomis it possible to make clojure map destructuring to work with string keys?
08:21mearnsh,(let [{:strs [k1 k2]} {"k1" 1 "k2" 2}] (prn k1 k2))
08:21clojurebot1 2\n
08:21noncomwow!
08:21mearnsh,(let [{:syms [k1 k2]} {'k1 1 'k2 2}] (prn k1 k2))
08:21clojurebot1 2\n
08:22mearnshalso
08:22mearnsh:)
08:22noncomwow, never really knew that!
08:24mmeixwhere would I find doc for :strs and :syms?
08:24mmeix(special forms?)
08:25noncommmeix: i haven't seen the doc, hence i did not know.. but i guiess if you look at the source or the destructuring fn in clojure.core, they're there..
08:25oddcullymmeix: yes. section `Map binding destructuring`
08:25noncom*of the destructuring fn
08:25mmeixjust found it: http://clojure.org/special_forms
08:25noncomis that a new feature or is it present already for a long time?
08:26Bronsabeen there as long as :keys has
08:29mmeixI just made me a helper function, which puts vals of a map into vectors. {:foo 1} => {:foo [1]}, for using it with merge-with into afterwards ... is this reinventing some wheel. or does it exist in core? didn't find something so far ...
08:29mmeix,(defn vals->vector [m] (into {} (map (juxt key (comp vector val)) m)))
08:29clojurebot#'sandbox/vals->vector
08:30mmeix,(vals->vector {:foo 1})
08:30clojurebot{:foo [1]}
08:30noncomi think this is a kind of a deep merge
08:30noncomafaik people invent their own wheels for that
08:30mmeix,(apply merge-with into (map vals->vector {:foo 1} {:foo 2}))
08:30clojurebot#error {\n :cause "Wrong number of args (2) passed to: sandbox/vals->vector"\n :via\n [{:type clojure.lang.ArityException\n :message "Wrong number of args (2) passed to: sandbox/vals->vector"\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" 36]\n [clojure.core$map$fn__4555 invoke "core.clj" 262...
08:31mmeix,,(apply merge-with into (map vals->vector [{:foo 1} {:foo 2}]))
08:31clojurebot{:foo [1 2]}
08:31noncomyes, like this..
08:31mmeixok
08:32mmeixgoes into toolbox
08:33mmeixah, ok: http://dev.clojure.org/jira/browse/CLJ-1468
08:34mmeix(what's better: building the own toolbox, using other's, or compiling other's?)
08:34noncomyeah, too many particularities.. many different possible usecases where you need slightly different behavior.. very hard to generalize..
08:34mmeixI see
08:35kwladykatoolbox is not up to date - dont use that
08:35mmeixflatland/useful seems to be ...
08:35kwladykaoh, i read that too fast - you are not talking about toolbox website :)
08:35mmeixno
08:35noncomin my toolbox i have many methods adviced by people on this channel, so you may say, that it is half-compiled from others and half my own
08:36noncomflatland is popular, yes
08:36mmeixok - besides being a learning opportunity, each time :-)
08:40mmeixah, flatland's merge-in looks great ... though I don't (yet) understand the (letfn [(merge-in* ...)] (defn merge-in ...)) construction there - homework for this evening, I guess
08:42mmeixa function can be defn-ed inside a (letfn ...) and is visible outside?
08:43arkhmmeix: you wouldn't want to do that though
08:43mmeixhttps://www.refheap.com/102239
08:44mmeixit's at least counertintuitive to me
08:44mmeixI thought everthing inside a local binding is invisible ...?
08:45arkhoh, ok. I guess they did it for the purpose of defining the function, as opposed to 'as an additional thing I'm doing inside a let'
08:45arkhdef and defn create global bindings, even inside something lexically nested
08:45dhardisonwhat's the difference in the syntax of using [] and a "do" or maybe nothing?
08:46dhardisoni'm looking at some code that has [(if true) ...]
08:46mmeixso this is sort of very clever and self contained
08:46arkhmmeix: yes
08:47mmeixother way would have been to (defn merge-in* ..) and then using that in (defn merge-in ...) ?
08:47arkhdhardison: what you just wrote is creating a vector of something with contents that depend on the if condition
08:48dhardisonarkh: makes sense, thank you
08:48mmeixarkh thanks for pointing out the global thing there
08:49arkhmmeix: what I would have done (which seems more boring me but I don't know if it's better or worse) is, instead of creating a function with letfn, I would have done a normal defn and used an anonymous function in place of merge-in*
08:49mmeixah
08:49arkh^ *boring to me but I don't know if it's better or worse
08:49mmeixyes, that sounds more understandable/readable, at least for me
08:50arkhthe upside with what they did is they gave an otherwise anonymous function a name, so maybe that's more readable
08:50mmeixaha!
08:51arkhbut then I don't expect something lexically nested to be part of global scope, so maybe it's less readable for that reason
08:51arkh*shrug* : )
08:51mmeixthis is what I didn't get when reading it first
08:51mmeixthanks for explanations!
08:52arkhyou bet : )
08:56dhardisonis there an easy way for me to print a list to the js console? doing js/console.log list prints some kind of clojure object -- i just want to see the contents
08:56mmeixflatland/useful is a learning ressource, I just found
08:56gfredericksdhardison: does prn work?
08:59arkhdhardison: if you put (enable-console-print!) before any print statements then those statements will send their output to the js console
08:59dhardisongfredericks: that did work - thank you. arkh i'll look at that too thank you.
09:06mmeixfollow-up question: if I used a lib like flatland/useful in a clojurescript-project, using only few bits out of it, then the Google Closure compiler in advanced mode would remove unused functions as dead code, and so there would be no size penalty - is this correct?
09:06mmeix(maybe should ask this in #clojurescript)
09:07arkhmmeix: that is correct
09:07mmeixgreat
09:07mmeixthanx again
09:20profilis there a more clojury solution to this problem? (re-find #"(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})Z" "20150606T180000Z")
09:20profila simple way to parse basic iso8601 dates
09:21winkI'd use joda time, maybe with a wrapper if there's one
09:22arkhI've always like clj-time
09:22arkh*liked
09:23winkand yes, it may sound like overkill to pull a lib for that.. but regarding time and date, I think it's usually worth it
09:24profilhmm, I wondering if it's worth it, the datestring _will_ always look like that
09:25arkhif you're not going to deal with more dates than that, re-find is still 'clojury' : )
09:27profilokay, thanks for the suggestions. Will stick with it for now, and change it when I need more in the future :)
09:28oddcullySimpleDateFormat?
09:32oddcully,(import 'java.text.SimpleDateFormat)
09:33clojurebotjava.text.SimpleDateFormat
09:33oddcully,(.. (SimpleDateFormat. "yyyyMMdd'T'HHmmss'Z'") (parse "20150606T180000Z"))
09:33clojurebot#inst "2015-06-06T18:00:00.000-00:00"
09:34arkhnice
09:47mmeixflatland/useful.fn.annotate ... that's really useful! just wanted to express some spontanous happyness :)
09:52arkhI've used comp a number of times; never found a compelling reason to use juxt
09:53arkhit probably means I'm missing out
09:55mmeixI do find this useful:
09:55mmeix,(map (juxt :step :acc) [{:step 2 :acc :sharp :d "foo"} {:step 3 :d "foo"}])
09:55clojurebot([2 :sharp] [3 nil])
09:55mmeixpulling out relevant data from maps
09:56arkhI can see that
09:56mmeixjust having learned about juxt a few days ago though ...
09:57arkh(hopefully what I wrote doesn't sound snarky - didn't mean it that way)
09:57mmeixno ... I'm always looking for education here for myself, being a beginner still
10:16profiloddcully: I am using clojurescript
10:16gfrederickswhy would I see a boxed math warning when loading a namespace in cider but not when running `lein do clean, test`?
10:18jtmarmonanyone know why compiling a 36 line compojure route would cause a stack overflow (compilation, not runtime)?
10:18gfredericksjtmarmon: nope; have you tried minimizing it to see what part causes the overflow?
10:20jtmarmonyeah i'm working on it & getting closer. one sec
10:28jtmarmongfredericks: so there are two clauses in this let statement that seem to cause it. if i uncomment either i get the exception again. one is a datomic query, the other is a threading macro w/ 7 args
10:35gfredericksjtmarmon: welp maybe sharing some code would help
12:10iamjarvoi deleted a template from ~/.m2 and now lein wont fetch it automatically. I get "Failed to resolve version for"
12:19justin_smithiamjarvo: odd - did you only delete the template, or the template and pom etc.
12:19iamjarvojustin_smith i figured it out. I was typoing the template name using ctrl-r
12:19iamjarvo*sad-face*
12:20justin_smithaha, OK
12:20iamjarvojustin_smith but is that the right way to uninstall something? just delete it from ~/.m2
12:21justin_smiththere isn't really a concept of "install" - but if you want to reduce the disk usage you may want to remove things you are not going to use again
12:21justin_smithI mean yeah there is a command "lein install" that puts something in your m2 cache, but it is more about caching things than installing them
12:25iamjarvoo ok, thank you
12:37ionthas_Why I cannot use (use 'midje.repl) from another namespace?
12:38ionthas_CompilerException java.lang.RuntimeException: Unable to resolve symbol
12:38justin_smithionthas_: hmm, I would expect that error if you forgot to quote it
12:38justin_smith,(use foo.bar)
12:38clojurebot#error {\n :cause "foo.bar"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.ClassNotFoundException: foo.bar, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6543]}\n {:type java.lang.ClassNotFoundException\n :message "foo.bar"\n :at [java.net.URLClassLoader$1 run "URLClassLoader.java" 366]}]\n :trace\n [[java.net.URLClass...
12:39justin_smithoh, no, that's a different error
12:39kwladykahttps://www.refheap.com/102256 - what this code do and how to get this variable from other places?
12:39justin_smithwhat symbol can't it resolve?
12:39kwladykait is from https://github.com/ring-clojure/ring-anti-forgery
12:39ionthas_justin_smit: It cannot resolve the function use.
12:40justin_smithionthas_: did you use in-ns?
12:40ionthas_yes
12:40justin_smith(clojure.core/refer-clojure)
12:40justin_smiththe problem is that in-ns doesn't load code
12:40justin_smithit simply creates an unusable empty namespace
12:40kwladykaionthas_, http://clojuredocs.org/clojure.core/use
12:40justin_smith(unless the namespace was properly created before)
12:40justin_smithkwladyka: that's not the issue
12:41justin_smithkwladyka: he used in-ns, which leads to clojure.core not being referred properly
12:41kwladykaoh, sorry
12:41kwladykajust tried help :)
12:41justin_smithso he needs to explicitly spell out clojure.core in order to do anything useful
12:41ionthas_justin_smit: I didn't know that. Thanks :)
12:42ionthas_kwladyka: Also thanks to tou :P.
12:42kwladyka;)
12:42justin_smithionthas_: for future reference, you probably want require in order to load your namespace, to make sure it exists before using in-ns
12:42justin_smithionthas_: you can fix the broken ns (after refer-clojure) by doing (require 'some.ns :reload) which loads the ns file even though the ns already exists
12:43ionthas_thanks!
12:43justin_smithkwladyka: like any other var, you can access *anti-forgery-token* via the namespace it is in
12:43justin_smithkwladyka: of course it's special, because it is a dynamic bar with a per-thread binding
12:44kwladykajustin_smith, but how is it working? It is just (def *anti-forgery-token*) with extra metadata
12:44justin_smith,(def ^:dynamic *foo*)
12:44clojurebot#'sandbox/*foo*
12:44justin_smith,*foo*
12:44clojurebot#object[clojure.lang.Var$Unbound 0x1a6b32a1 "Unbound: #'sandbox/*foo*"]
12:45justin_smiththat creates a var, with no value bound to it
12:45justin_smith,(binding [*foo* 1] (+ *foo* *foo*))
12:45clojurebot2
12:45justin_smiththere, foo has a value
12:45justin_smith,*foo*
12:45clojurebot#object[clojure.lang.Var$Unbound 0x1a6b32a1 "Unbound: #'sandbox/*foo*"]
12:45kwladykahmm so it is something like * (indicator) in C++?
12:45justin_smithbut notice that the root of *foo* is still unbound
12:45justin_smithno
12:45justin_smithkwladyka: each thread has a different value for *foo*
12:46justin_smithunbound if it has not been bound yet, or whatever local binding is established
12:47justin_smithkwladyka: so the idea here is that ring-anti-forgery can let your app's handler know the token to render into the html via dynamic binding, and then it checks for that same dynamically found var coming back on the client's request
12:47justin_smithit prevents replay attacks
12:49kwladykammm still i feel a little magic :) In which moment in the code the value is generated?
12:49kwladyka(binding ...) ?
12:49justin_smithkwladyka: hidden somewhere in the anti-forgery middleware
12:50kwladykaoh.... right :)
12:50justin_smithkwladyka: https://github.com/weavejester/ring-anti-forgery/blob/master/src/ring/middleware/anti_forgery.clj#L67
12:50justin_smiththat's where it happens
12:51justin_smithand I showed above how binding works (creates a value for a def that is only valid for one block of code, in one thread)
12:51justin_smithkwladyka: binding / dynamic vars is still kind of magic, and many people have convincing args that they should be avoided
12:52justin_smitheg. http://stuartsierra.com/2013/03/29/perils-of-dynamic-scope
12:55kwladykaok, i added this to bookmark to read in free time, thank you
12:56justin_smiththe important part for understanding that anti-forgery code is that via dynamic binding a symbol var can be used to represent different tokens in each thread
13:01kwladykaso use this var should looks like that (:require [ring.middleware.anti-forgery :refer *anti-forgery-token*]) ? i guess not, because it doesnt work :)
13:01justin_smithkwladyka: that's not how refer works
13:01justin_smithyou need a vector
13:01kwladyka?
13:02justin_smith,(require '[clojure.string :refer join])
13:02clojurebot#error {\n :cause ":only/:refer value must be a sequential collection of symbols"\n :via\n [{:type java.lang.Exception\n :message ":only/:refer value must be a sequential collection of symbols"\n :at [clojure.core$refer doInvoke "core.clj" 4086]}]\n :trace\n [[clojure.core$refer doInvoke "core.clj" 4086]\n [clojure.lang.RestFn applyTo "RestFn.java" 139]\n [clojure.core$apply invoke "core.clj...
13:02justin_smiththat's the version that fails
13:02justin_smith,(require '[clojure.string :refer [join]])
13:02clojurebotnil
13:02justin_smithit works with a vector
13:02kwladykaoh true.... sorry, i am learning a lot and sometimes i forgot about basic things...
13:03justin_smith(join ", " ["hello" "world"])
13:03justin_smith,(join ", " ["hello" "world"])
13:03clojurebot"hello, world"
13:03kwladykayeah, it works :)
13:16mmeixbuilding a function, which creates a run between two numbers, but inclusive the higher num, and self-sorting:
13:16mmeix,(let [range-incl (fn [a b] (apply range (map + ((juxt min max) a b) [0 1])))] (range-incl 11 -3))
13:16clojurebot(-3 -2 -1 0 1 ...)
13:16mmeixgood solution?
13:18mmeix,(defn range-incl [a b] (apply range (map + ((juxt min max) a b) [0 1])))
13:18clojurebot#'sandbox/range-incl
13:18mmeix,(range-incl 5 -2)
13:18clojurebot(-2 -1 0 1 2 ...)
13:24kwladyka,(range-incl 5 5)
13:24clojurebot(5)
13:25mmeixwhich is ok
13:25mmeixfor my use-case
13:27kwladykammeix, (range (min -2 5) (inc (max -2 5))) - maybe something in that style?
13:27kwladykashould be more readable?
13:27mmeixright you are
13:58dhardisonwhat's the best way to look up browser dom elements using clojure?
13:59justin_smithdhardison: you'll likely get more help in #clojurescript, but you can use any method that works in js, in my experience it's better to use react so you don't have to look up elements
13:59justin_smith(well, reagent or om, which use react)
13:59dhardisoni see - i'll take a look thank you
15:18dhardisoncan i store a keyword into a variable using let (e.g. (let [keyword :black] ... ) i'm geting a compile error atm but maybe it's not related to that
15:21farhaven,(let [foo :bar])
15:21clojurebotnil
15:21farhavenseems to work
15:21farhaven,(let [foo :bar] foo)
15:21clojurebot:bar
15:22j-pbhu?
15:23farhaventhat was in reply to dhardison
15:23j-pbah sorry, I missed the top part, and was wondering if you had a question :)
15:37sywhen working with leiningen and the cider nrepl i notice that if i modify a .clj file that provides a required namespace in another file, the file containing the required nmespace isn't re-loaded and re-compiled by lein or cider
15:37syshould i expect it be re-loaded ?
15:40justin_smithsy: what are you doing to make reload happen?
15:44syif file1.clj requires a namespace in file2.clj, file2.clj gets compiled when i start cider, if i (load ...) the namespace in file1 again, file1 gets compiled but required namespace in file2 isn't re-compiled, i am missing a clue about this simple project management
15:45justin_smithsy: the point of require is that it does nothing if the file you required is already loaded
15:46justin_smithsy: instead of (load ...) use (require ... :reload-all) to cause it and all it's dependencies to be reloaded
15:46justin_smiththere is no way to force reload of namespaces that require a given namespace though
15:51syah... i knew there was a way, reminds me of lisp and ASDF, there is syntactic wizardy required :)
15:51syRecognized flags: :reload, :reload-all, :verbose
16:22verma_not sure if this is the right channel for this, but what controls the indentation of methods defined under defrecord?
16:23verma_I want them to indent like defn, but the first statement indents right under the parameter list
16:23verma_tried the clojure-backtracking-indent stuff, but no luck so far
16:28justin_smithverma_: indentation by whom?
16:29verma_oh sorry, didn't realize I never mentioned the context, clojure-mode under emacs.
16:29verma_justin_smith: ^
16:31sythis is interesting about namespaces and multiple sources files and the jvm --> https://github.com/clojure/tools.namespace#reloading-code-motivation
16:32justin_smithverma_: the default indent rules are all defined in clojure-mode.el
16:34verma_justin_smith: yeah I am trying to change them, it seems the computer I am on has a more recent version of clojure-mode, so its doing the indentation differently, can't really understand what the clojure-backtracking stuff means :(
16:44amalloyverma_: are you writing your defrecords incorrectly?
16:45amalloyclojure-mode indents correct code correctly, but if you write illegal code it won't understand how to indent
16:50verma_amalloy: could be the reason, things have stopped working :(
16:50verma_amalloy: checking ..
16:53dhardisoncan i do an if statement within a let variable declaration similar to what you can do with a list?
16:56H4nsdhardison: you mean (let [a (if foo 1 2)] ...) ? or what?
16:56dhardisonH4ns: yes
16:56H4nsdhardison: yes. `if` is not a statement, and an if form is just an expression.
16:57H4nsdhardison: there are no statements in clojure, for what it is worth.
16:58sybinding-form init-expr
16:58syexprs are meant for evaluation
17:04j-pband thats just what they'll do
17:31gfrederickshello
17:34m1dnight_Is there an up to date guide on clojure SQL?
17:34m1dnight_I cant seem to get it working anymore. Been a while since I tinkered with this code.
17:35verma_justin_smith, amalloy: this is the indentation I get: https://gist.github.com/verma/69c407f9621154288d6a
17:35m1dnight_I was trying the basics like creating and reading but I can only seem to create a database. Reading always returns nil.
17:35verma_the method bodies are aligned with arguments :(
17:35gfredericksm1dnight_: what's "clojure SQL"?
17:35verma_looking at some of the examples on clojuredocs, it seems that's what its supposed to be?
17:36amalloyverma_: weird. do you have backtracking indent turned on?
17:36m1dnight_oh, right. I'm talking about jdbc here. (clojure.java.jdbc)
17:36m1dnight_Im trying to play with a postgresdb
17:36amalloythat's the feature that's supposed to make it indent defrecord sensibly
17:37gfredericksm1dnight_: (jdbc/query conn ["SELECT 1"])?
17:37m1dnight_all nil :p
17:37m1dnight_I dont get it. Queries to create tables work though..
17:37m1dnight_I must be missing something stupid here..
17:38verma_amalloy: I am trying to set it up so that it doesn't do that, with no success, seems to me like its a recent change, since the version of clojure-mode I have on my notebook isn't doing this
17:38gfredericksm1dnight_: my guess is there's some weird other problem
17:38m1dnight_Also, I checked in pgadmin and there is actual data in the database.
17:38gfredericksm1dnight_: because SELECT 1 should not return nil under like any dang circumstances
17:39verma_going to take a look at what the nodebook version is doing to clojure-backtracking-indent
17:39m1dnight_But when I execute the following (on an existing db): (sql/insert! (read-db-config) "testing" {:data "fobar"})
17:39m1dnight_ClassCastException clojure.core$identity cannot be cast to clojure.lang.Named clojure.core/name (core.clj:1518)
17:39m1dnight_that happens. (Yes, the (read-db-config) function returns valid credentials, otherwise the create table wouldnt work, I assume)
17:40m1dnight_Ill give sqlite a shot perhaps.
17:55verma_amalloy: ok, so the version installed on my notebook seems to be behaving correctly, I upgraded it, and it started doing the unwanted indentation again, guess I will just revert to an older version and carry on, no changes to any backtracking indentation, but seems like there was a change to backtracking regexs to account for namespace names.
17:55verma_I think that's why people freeze versions of packages they use, to avoid unnecessary problems :(
17:56amalloyyes. i run clojure-mode off a very old git checkout plus some changes i made, just because i'm not really interested in whatever new stuff comes out
20:14gfredericksokay so I've evolved into this workflow where I run my clj repl process with docker, and connect to it with cider
20:14gfredericksI'm not sure if the docker part is important, but one way or another I find myself restarting the repl a few times a day at least
20:15gfredericksmaybe more often if I debugging something where processes hang
20:15gfredericksand cider seems to make it very difficult to reconnect
20:15gfredericksI have to manually close the buffer of the disconnected process to keep cider from nagging me about existing connections when I try to reconnect
20:15gfredericksdoes anybody else do this better?
20:25gfredericksI think the best option would be some way to get it to reconnect when the repl becomes available, reusing the buffer
21:06gfredericksokay big mystery here um
21:06gfredericksI'm using a lib and a var is mysteriously not defined
21:06gfredericksI can open the jar and see its defn there
21:06gfredericksI can also verify from the repl other changes unique to that jar so I can't imagine anything else running
21:07gfredericksI rm -rf'd the target before starting the repl
21:07gfredericksthis is all physically impossible
21:07amalloygfredericks: are you actually running the jar you have inspected, and not some other jar? are you ssh'd into a different machine accidentally?
21:09gfredericksnow I'm looking at line metadata on the vars to see if that correlates with the file I'm looking at
21:11gfredericksthe pom.properties file on the classpath says everything is normal
21:11gfredericksthe line numbers are super weird though o_O
21:12gfredericksthey don't correspond to any reasonable version of the lib
21:12gfrederickshold up gonna try this on a totally different computer via `lein try`
21:13amalloygfredericks: have you checked that lein classpath points at the jar you think it does?
21:13amalloysome dependency may be pulling in a different version
21:14gfredericksthat wouldn't explain "pom.properties" though no?
21:14amalloyman i dunno what this pom.properties nonsense is
21:15gfredericksokay
21:16gfrederickseverything works fine with `lein try` so I guess it's specific to this project and not the lib
21:16gfredericksnow for `lein classpath`
21:16gfredericksyes indeed there is a dumber version of the project earlier in the classpath wtf.
21:17gfredericksoh I see yep yep
21:18gfredericksit's cuz I'm using a fork with a different group id
21:18gfredericksso my explicit declaration didn't override the indirect dep with the normal group id, and an older version
21:18justin_smithgfredericks: which is a good argument against namespaces that don't include the group
21:18gfredericksphysics is working correctly
21:19justin_smithgfredericks: that's a releif
21:19gfredericksjustin_smith: it's a temporary fork
21:19gfredericksI wouldn't want to renamespace anything
21:19justin_smithgfredericks: oh, OK
21:19justin_smithI was thinking of when I did some work I component
21:19justin_smithI moved it from com.stuartsierra.component to org.noisesmith.component