#clojure logs

2016-01-11

00:43neoncontrailsI'm having trouble following the instructions here: http://www.luminusweb.net/docs/database.md. I think the assumption is that you have a db up and running already, and you're trying to configure your app's backend to communicate with it. Right?
00:45neoncontrailsThe error I get when I run "lein run migrate" as the instructions say is that it can't create a DB connection to localhost:5432. Well, I think that makes sense, because I haven't created any database yet. Am I supposed to?
00:50justin_smithneoncontrails: well, you at least need some db engine running, and you need to supply the details of that in the config (wherever that goes)
00:51justin_smithneoncontrails: 5432 is usually postgres
00:52neoncontrailsGot it, so Clojure can't create a new database instance, it can only use an existing one
01:00justin_smithneoncontrails: well, it doesn't contain postgres, so you need a separate postgres running, but it should be able to create dbs and tables as needed
01:01justin_smithif you use and embedded db (eg. sqlite or hsql), you don't need an external db - but usually you should use an external one
01:03neoncontrailsjustin_smith: oh I think I'm starting to understand now. Postgres is a server, and a database is a just a process on that server?
01:04justin_smithkind of - postgres is the db server, and it can run multiple database instances, and it runs processes for each connection you make
01:05justin_smithneoncontrails: and there should be a config with connection info - what user name, what password, what db name to use, what host to connect to (the db doesn't even need to be hosted on the same computer) etc.
01:06neoncontrailsGotcha. That makes sense. Clojure can create new databases, it just has to authenticate first with the Postgres credentials
01:07justin_smithright
01:07justin_smithso what it's saying is that it couldn't connect given the config it has now - next step is to find the config I guess?
01:09neoncontrailsNext step is to create the config ;-) I didn't realize right away the tutorial assumes it exists
01:09irctcHello! Just getting into clojure. I have a question about how [loop... works. Here's my SO post, would appreciate if any of you can help. https://stackoverflow.com/questions/34715147/clojure-multiple-recursive-args
01:10neoncontrailsirctc: I think I can help you there. This looks pretty reasonable, except line 2
01:10justin_smithirctc: there is no problem with that code, except for the ugly trailing parens
01:11justin_smithirctc: it runs, there is no error
01:11justin_smithalso, range_creator is not normal clojure naming, range-creator is mor idiomatic
01:11neoncontrailsnope, nevermind, your line 2 is fine, just formatted unconventionally :-)
01:12irctcAh, thanks. And yes, I understand it runs, I'm just wondering on if the (conj ret low) is being passed in and is the new "ret []", and if so, perhaps the "low low' in line 3 could have been ommitted entirely"
01:12justin_smithwhat?
01:12clojurebothttp://paste.lisp.org/display/74305
01:13justin_smithirctc: every value that is updated in the loop needs to be a loop binding. You have two values that update, low and ret
01:14irctcAh.. I was misunderstanding what the reassignment of "low" in the loop was doing. I understand now. Thanks for your help
01:16justin_smithirctc: it might be clearer to change low to n inside the loop (loop [n low ret []] (if (= n high) ret (recur (inc n) (conj ret n)))
01:17irctcYes, that does make it more clear. Good idea
01:23irctcOn a different note, are there any suggestions for a good REPL reloader? I am using https://github.com/pyronicide/lein-autoreload currently, but it is unable to inject new functions or changed function names. It would be nice to have a REPL reloader that could.
01:26neoncont_irctc: what IDE are you using?
01:27irctcJust sublime text and a terminal shell nearby
01:28irctcneoncont_: I tried cursive with IntelliJ but it got in the way too much. What do you use?
01:30neoncontrailsirctc: sounds difficult. :-) If you like Clojure, I would recommend choosing an IDE with integrated REPL support. There's a few good ones
01:30neoncontrailsMany people swear by emacs. I'm an Intellij+Cursive man, myself
01:31irctcneoncontrails: Okay, I'll try cursive again. I didn't realize it had a REPL built in.
01:32allenj12i wanna try cursive but i always like editors i can pretty much any language in
01:32allenj12so i never got around to it
01:33neoncontrailsHeh, yeah IntelliJ can be a little overwhelming. I think the REPL should be configured right out of the box, typically you'll boot from your project.clj file to load in all your dependencies
01:34irctcneoncontrails: will Cursive inject into the REPL out of the box?
01:35neoncontrailsirctc: The REPL is actually a Cursive feature
01:36neoncontrailsIntelliJ has no support for Clojure without the Cursive extension, so I don't think it has any REPL-like capabilities natively
01:36irctcWow, this incredibly cool.
01:39irctcneoncontrails: Love the syntax highlighting, but its still not able to detect a function name change and inject that.
01:39neoncontrailsallenj12: yeah that is a fair concern. I guess the silver lining is that IDEA has a variety of language-specific editors that all have roughly the same keybindings, so it's trivial to go from IntelliJ to PyCharm e.g.
01:40neoncontrailsirctc: hmm. say more
01:41irctcneoncontrails: so if I have a function (defn range-creator...) and I change it to (defn range-creator2...). The REPL will fail with both range-creator and range-creator2
01:42neoncontrailsirctc: when you say "change it" do you mean additionally defining another function in the current namespace called range-creator2?
01:42irctcno, modify the current one
01:43irctcso there no longer exists a range-creator, only exists a range-creator2
01:44neoncontrailsWhat you're asking about is possible, but that requires manipulating the namespace macro itself, which I don't think you're doing
01:44neoncontrailsWalk me through your steps
01:47irctcneoncontrails: I don't think I'm doing anything too unusual. The REPL won't pickup any new defined functions after its initialization. I was hoping that my entire dev process could be captured continuously through the REPL, but I guess it will always require restarts.
01:48irctcneoncontrails: so If a start the REPL and then make a new function: (defn new-thing (println "test")), it will fail if I call it.
01:50neoncontrailsirctc: not necessarily, but if you define something in the "myapp.core" namespace and want to work with it in the REPL, you will have to import it
01:50irctcneoncontrails: oh really? do tell, I'm new to clojure if you can't tell.
01:51neoncontrailstry selecting the function you want to use and right clicking. There should be an option like "send highlighted definition to REPL"
01:51neoncontrailsthere's several ways to import, you can very surgically import single definitions or entire namespaces
01:52irctcneoncontrails: that is awesome. Thanks for telling me about this. Definitely switching to Cursive.
01:54neoncontrailsirctc: no prob, glad to help. Back to your earlier question about changing the name of a function, though
01:55irctcneoncontrails: it seems that you just send that newly defined function to the REPL and that solves it.
01:55neoncontrailsirctc: the way to "undefine" a function would be (ns-unmap mynamespace myfunction), but you probably don't want to do this
01:58irctcneoncontrails: I am noticing that the REPL will quickly be upset about your changed function name and start to fail. What should I use to "undefine" it?
02:00neoncontrailsirctc: forget what I told you earlier, actually. It's advanced clojure and assumes you've learned about namespaces, which are pretty unique to Lisps
02:03neoncontrailsI guess I'm still confused what you're trying to do. If you're talking about overwriting the definition of a function with a new definition, that's definitely possible -- no namespace manipulation required
02:03neoncontrailsobserve that (def foo 5) (def foo 6) foo prints 6
02:05irctcerr no, I mean changing (defn foo (println "5") to ----> (defn foo2 (println "5"))
02:05neoncontrailsoh, so that defines two functions
02:05irctcright
02:05neoncontrailsit defines foo first, and then it defines foo2
02:05irctcit just won't get injected, and then the REPL starts whining that it can't find foo
02:05clojurebotTitim gan éirí ort.
02:05neoncontrailsfoo doesn't "become" foo2 though
02:09neoncontrailsmaybe you could pastebin an example showing the behavior. I'm still not sure what you mean when you say "changing" foo to foo2
02:10irctcneoncontrails: It's getting pretty late here so I'm going to bed, but thank you for your help. really appreciate it. I ended up getting it all figured out and am really enjoying learning clojure. Have a good night everyone!
02:11neoncontrailsirctc: no prob. Glad you figured it out!
10:06jsabeaudryIs it recommended practice to recursively append ! to all functions that manipulate atoms?
10:18gfredericksI don't think that's normal but it sounds like it would be useful to try just to encourage you to minimize how many such functions you write
10:27ToxicFrogThe principle at work as "functions that mutate externally visible state get a !"; swap! has a ! because it changes the state of the atom in ways visible to other functions.
10:28mpenetoriginally it indicates "might be retried so beware" more than state modification I think
10:28mpenet(STM context)
10:28MJB47_i was under the impression that the definition changes from person to person
10:28mpenetbut then everybody now uses ! to indicate state changes more or less
10:28MJB47_http://stuartsierra.com/2016/01/09/how-to-name-clojure-functions/
10:29mpenetI guess "not pure" is broad enough
10:29MJB47_last para of "functions with side effects"
10:29MJB47_obviously not a definitive source
10:30TimMcIgnoring metrics and logging. :-P
10:30mpenetread that post, it's very personnal I think. As long as you follow a single rule
10:30mpenetmore like "a single set of rule" actually
12:06sdegutisWhat's the benefit of using (foo bar) rather than (.foo bar) when bar is a record and foo is a record method?
12:15TimMcYou mean :foo ?
12:15TimMc(in the first case)
12:15mpenetsdegutis: avoiding reflection for one
12:16mpenetif you use the dot form you might have to add a type hint to the call I think
12:16sdegutismpenet: but if you have multiple things that implement .foo, doesn't that still take a cost of choosing which one to call at runtime when no type hints are given?
12:16sdegutisTimMc: I thought you could do (foo bar) if the method was called "foo".
12:16mpenetit has the cost of java method dispatch, it's probably **very** fast
12:17sdegutissweet
12:18sdegutisSo is (.foo bar) generally preferred over (foo bar)?
12:18mpenetbut I don't know the details really
12:18mpenetimho no
12:18sdegutisWhy not? What's better about (foo bar)?
12:19sdegutisSo far it just sounds slower with no benefit.
12:19mpenetif you type hint the call it might be faster but it probably is optimized down the road by hotspot
12:19sdegutisI guess the only advantage is that it's possible to redef (foo bar), but with good practices that's not needed.
12:20mpenetsdegutis: because 1 less char to type, no need to type hint. (foo bar) is prolly a tiny bit slower, but I doubt it matters in real world app
12:20TimMcsdegutis: I don't think you *can* do (foo bar).
12:20TimMcMaybe you're thinking of protocols?
12:21mpenet,(defprotocol Foo (bar [this])) (defrecord foo [a] Foo (bar [this] a))
12:21clojurebotFoo
12:21mpenet,(bar foo)
12:21clojurebot#error {\n :cause "Unable to resolve symbol: foo in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: foo in this context, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6688]}\n {:type java.lang.RuntimeException\n :message "Unable to resolve symbol: foo in this conte...
12:21mpenet,(let [f (foo. 1)] (bar foo))
12:21clojurebot#error {\n :cause "Unable to resolve classname: foo"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.IllegalArgumentException: Unable to resolve classname: foo, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyzeSeq "Compiler.java" 6875]}\n {:type java.lang.IllegalArgumentException\n :message "Unable to resolve classname: foo"\n :at [clojure...
12:21mpenetbah
12:22mpenet,(let [f (foo. 1)] (bar f))
12:22clojurebot#error {\n :cause "Unable to resolve classname: foo"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.IllegalArgumentException: Unable to resolve classname: foo, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyzeSeq "Compiler.java" 6875]}\n {:type java.lang.IllegalArgumentException\n :message "Unable to resolve classname: foo"\n :at [clojure...
12:22mpenetanyway, it's easy to test in a repl
12:22sdegutisTimMc: hmm yeah I think so
12:23sdegutisTimMc: and a record can implement a protocol, so you can do (foo bar) to record bar with protocol method foo
12:24ystaelA number of Leiningen tasks on my Luminus app are taking extra time to quit. I suspect something somewhere in the app has started a non-daemon background thread. Anybody know a trick for finding the guilty party quickly?
12:26TimMcsdegutis: You didn't mention a protocol was involved, that changes things...
12:27TimMcystael: Thread dump? ¯\_( ❛ᴗ❛ )_/¯
12:27sdegutisSorry!
12:27TimMcAre you able to call shutdown-agents ?
12:31sdegutisSo assuming you have a protocol and a record, is it better to do (.foo bar) or (foo bar)?
12:39TimMcAnd bar is not hinted with the record class?
12:44sdegutisYeah no type hints.
12:45mpenetwithout type hints .bar is very likely super slow
12:45mpenetit will go through reflection
12:45sdegutisHmm.
12:46sdegutisIs there any previous discussion on this within the Clojure community?
12:46mpenetjust tested it in repl
12:51mpenetjust use (foo ...) why do you want to use the dotted form so bad?
12:51sdegutismpenet: I don't have a preference, I'm just asking if the community has a recommended best-practice, and if so what the reaosning is behind it.
12:53mpenet.foo is just an artefact of the generated code, imho the correct way is to call the clojure fn, not the java method
12:54sdegutisHmm interesting concept.
12:54mpenetalso if the record was extended i am not even sure .foo works
12:54sdegutisAhhhhhh.
12:54mpenetI mean via (extend-protocol ..)
12:54sdegutisClever thought.
12:56mpenetyeah it doesn't, defrecord emits the bytecode for the method I guess, and extend-protocol has to have some kind of table for the lookup
12:57mpenetso yeah, use (foo bar) :()
12:58sdegutisAlright, sounds good!
12:58sdegutisThanks mpenet for your input.
12:58mpenetyw
13:01sdegutisTimMc: also thanks to you for your valuable feedback
13:06TimMcYou can also use :foo for that matter if it's a record field...
13:06sdegutisHmm interesting.
13:07TimMcIn any event, try using Criterium to find out what actually is fastest in practice.
13:08sdegutisWell I'm not necessarily trying to get to what's fastest.
13:08sdegutisJust trying to figure out bestpractices and their reasonings.
13:08sdegutisYou know what they say: "You're bound to be unhappy if you optimize everything. -Donald Knuth"
13:37winkhm, coding style optimized for vim movement commands
13:37winksounds like a cool idea :)
13:41slester_wink: what's that in reference to? I love vim! :D
13:42winkslester: just trying to think if long lines or short lines would be good. I mean there are // [[--something markers sometimes to code fold
13:43benjyz1hello. how can I get the content of a function? e.g. for (defn x []) get the string "(defn x [])"
13:44justin_smithbenjyz1: by looking in the source file
13:44justin_smithbenjyz1: or use clojure.repl/source, which does exactly that
13:44justin_smiththis doesn't work for things defined in the repl of course, in that case there is no way to look up the source for a function
13:45benjyz1thank
13:45benjyz1here is some more info http://stackoverflow.com/questions/3782970/how-can-i-display-the-definition-of-a-function-in-clojure-at-the-repl
13:45justin_smithbenjyz1: if you need to generally know the source string for functions for application logic, you could look at technomancy's serializable-fn lib
13:45benjyz1there is meta :source ?
13:46justin_smithno
13:46justin_smithlike I said, the only way is to look it up in the source file, this is what clojure.repl/source does
13:46justin_smithor you can use serializable-fn if you need to be able to get a source string directly from a function
13:46benjyz1ah ok. the approach above it writes a macro which assoc the source with meta.. not sure if that's a good idea
13:47justin_smithright, that's what serializable-fn does too
13:47justin_smithby actually altering what defn does(!)
13:48benjyz1cool. I want to send a program over the wire (i.e. clojure source).
13:50justin_smithyeah, that's what serializable-fn is meant for
14:06favetelinguisare there any good larger git-projects/turtorials that shows how to assemble a larger system using clj and core.async preferebly with soemthing like components? all i can find is small example but would like to se something larger.
14:44HeavenSucksthis is my profiles.clj: https://dpaste.de/X16h
14:44HeavenSuckswhen I run lein repl
14:45HeavenSucksI get this messages: https://dpaste.de/QZtU
14:46HeavenSucksah, missing closed bracket ;D
14:47sdegutisHi.
15:33anti-freezeI'm trying to port a scheme math vector library to clojure and I've hit a road block regarding match and match-lambda. Here's an example: https://www.refheap.com/113542 Is there a better way to do this with decent performance? I've tried using protocols, but I hit road blocks when doing scalar and vector multiplication. Multimethods would probably be too slow.
16:19justin_smithanti-freeze: your best performance will definitely be a protocol or interface. a case will also perform well (and may be similar to your current code structure if it's possible)
16:20justin_smithcase performs better than cond / condp / multimethods because its tags are all compile time constants and it compiles directly to a jump table
16:24Frozenlockyogthos: Any ideas if your 'plugin' idea was put into a library after all? http://yogthos.net/posts/2015-01-15-A-Plugin-System-in-Clojure.html
17:17sdegutisHey all.
17:22Frozenlockhey you
17:22noncom|2is it ok to have a namespace whose name starts with a - or _ ?
17:23sdegutisI'd rather not ask that question myself.
17:23sdegutisAlso hi Frozenlock.
17:23sdegutisHope you're doing well this day?
17:25anti-freezejustin_smith: Sorry, I got disconnected. case is exactly what I was looking for, thanks
17:26anti-freezeI guess I'll keep most methods on protocols, and whatever needs to deal with scalars, I can just use case
17:37anti-freezeOne last thing. Is it considered bad practice if I do something like, (fn [v] (new (type v))) in clojurescript?
17:40hiredmandoes that work in clojurescript? it doesn't work in clojure
17:41hiredmanin clojure new is a special form that needs a literal symbol that names a class
17:43anti-freezehiredman: Sorry, doesn't just work with (new (type x)), but for some reason it works if I do, (let [t (type x)] (new t))
17:45hiredmananti-freeze: are you sure it works?
17:45banana`I have a question about how to access the values from a vector of maps [{:value 1} {:value 7} ... ]. I want to have a function that given the vector and a list of indexs returns the a list of numbers so for the above vector and the indexs '(1 2) it would return a list of '(1 7). One approach I had for ths was using two nested loops to iterate over the vector and the index list, but this seems like a brute force approach and quite
17:45banana`painful. Does anyone know a better way to accomplish this task?
17:47anti-freezehiredman: https://www.refheap.com/113548
17:49hiredmanmy guess is someone put a (assert (symbol? ...)) somewhere in the cljs compiler for 'new' which makes (new (type v)) not work, in an attempt to make it work like clojure's 'new', but of course that isn't enought to rule out the let binding case
17:49hiredmanbanana`: are you for real?
17:49hiredman,(map :value [{:value 1} {:value 7}])
17:49clojurebot(1 7)
17:50anti-freezehiredman: Interesting, I guess I got my answer. Thanks
17:51banana`Wow thank you I thought it should have been simpler than what I was trying to do
17:51hiredman,(map-indexed (fn [i m] (when (contains? #{0 1} i) (get m :value))) [{:value 1} {:value 7}])
17:51clojurebot(1 7)
17:52justin_smithsee also keep-indexed
17:53hiredmanhttps://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/analyzer.cljc#L1547
17:55hiredmanhttp://dev.clojure.org/jira/browse/CLJS-693
17:58anti-freezehiredman: Turns out you were right
17:58anti-freezeOh, you found it before me
17:59hiredmanit is sort of a weird area
18:00anti-freezeIm surprised how easy the source of the compiler was to understand (at a glance anyway)
18:01hiredmanclojure requires a literal symbol naming a class to avoid doing reflection on the jvm
18:02hiredmanthat issue doesn't exactly exist the same way for clojurescript, so how should new work?
18:03anti-freezeI just thought I'd work like the JS Object.constructor, so in my mind (let [t (type x)] (new x)) ==> var ctor = x.constructor; new ctor();
18:04hiredmanmaybe that is the intent
19:24rhg135has anyone seen this when adding the plugins for cider to lein: "Error loading refactor-nrepl.middleware: java.lang.ClassNotFoundException: mranderson046.toolsreader.v0v10v0-alpha3.clojure.tools.reader.impl.utils.TaggedLiteral, compiling:(mranderson046/toolsreader/v0v10v0_alpha3/clojure/tools/reader/impl/utils.clj:50:7)"
20:05kenrestivodas ist weird. maybe a version conflict of tools.reader? i'd use lein tree to see, and lein check to find out what dependency conflicts are there
20:06rhg135yeah, seems so
20:18rhg135altho I see nothing on the tree
20:21rhg135and it works inside a project...
23:01WickedShell How come nested #()'s aren't allowed?
23:09mgaareWickedShell: for one thing, what would the %'s refer to?
23:10WickedShelloh well... yes I guess that's a good point...
23:10WickedShelldarn thats making it waay harder to pass some callback's though
23:10mgaareWickedShell: Use (fn) in that case
23:11WickedShellyeah I guess that's true
23:11WickedShellthanks mgaare apparently I'm not making obvious connections at this point
23:11ajbis it more common to use #() than (fn)?
23:11mgaareas a matter of style, I tend to avoid #() except for the simplest one-liners
23:12WickedShellI was creating a simple one liner, and tend to use #() when I have something that doesn't take any additonal inputs
23:13mgaareas in, anything more complex than something like #(/ % 2) I prefer fn
23:14ajbI have a nested array, say [[1 2] [2 1]] and I am trying to get the first value of the nested array in a map, how would I go about doing that?
23:14ajb(I am very new to clojure and lisp in general, so please don't get mad if I royally screw up)
23:14mgaareajb: what would you want the output to look like exactly?
23:15tolstoy,(ffirst [[1 2] [2 1]])
23:15clojurebot1
23:16ajbI am trying to map something to a li with hiccup and it looked like hiccup takes the output of maps and can use that if they output an array containing the content
23:17mgaareso, you want like, [[:li 1][:li 2]] ?
23:19ajbsorry, thinking aloud about my problem solved it
23:19ajbthank's anyways
23:20ajb:)