#clojure log - Jan 11 2016

The Joy of Clojure
Main Clojure site
Google Group
List of all logged dates

0:43 neoncontrails: I'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?

0:45 The 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?

0:50 justin_smith: neoncontrails: well, you at least need some db engine running, and you need to supply the details of that in the config (wherever that goes)

0:51 neoncontrails: 5432 is usually postgres

0:52 neoncontrails: Got it, so Clojure can't create a new database instance, it can only use an existing one

1:00 justin_smith: neoncontrails: 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

1:01 if you use and embedded db (eg. sqlite or hsql), you don't need an external db - but usually you should use an external one

1:03 neoncontrails: justin_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?

1:04 justin_smith: kind of - postgres is the db server, and it can run multiple database instances, and it runs processes for each connection you make

1:05 neoncontrails: 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.

1:06 neoncontrails: Gotcha. That makes sense. Clojure can create new databases, it just has to authenticate first with the Postgres credentials

1:07 justin_smith: right

1:07 so 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?

1:09 neoncontrails: Next step is to create the config ;-) I didn't realize right away the tutorial assumes it exists

1:09 irctc: Hello! 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

1:10 neoncontrails: irctc: I think I can help you there. This looks pretty reasonable, except line 2

1:10 justin_smith: irctc: there is no problem with that code, except for the ugly trailing parens

1:11 irctc: it runs, there is no error

1:11 also, range_creator is not normal clojure naming, range-creator is mor idiomatic

1:11 neoncontrails: nope, nevermind, your line 2 is fine, just formatted unconventionally :-)

1:12 irctc: Ah, 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"

1:12 justin_smith: what?

1:12 clojurebot: http://paste.lisp.org/display/74305

1:13 justin_smith: irctc: every value that is updated in the loop needs to be a loop binding. You have two values that update, low and ret

1:14 irctc: Ah.. I was misunderstanding what the reassignment of "low" in the loop was doing. I understand now. Thanks for your help

1:16 justin_smith: irctc: 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)))

1:17 irctc: Yes, that does make it more clear. Good idea

1:23 On 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.

1:26 neoncont_: irctc: what IDE are you using?

1:27 irctc: Just sublime text and a terminal shell nearby

1:28 neoncont_: I tried cursive with IntelliJ but it got in the way too much. What do you use?

1:30 neoncontrails: irctc: sounds difficult. :-) If you like Clojure, I would recommend choosing an IDE with integrated REPL support. There's a few good ones

1:30 Many people swear by emacs. I'm an Intellij+Cursive man, myself

1:31 irctc: neoncontrails: Okay, I'll try cursive again. I didn't realize it had a REPL built in.

1:32 allenj12: i wanna try cursive but i always like editors i can pretty much any language in

1:32 so i never got around to it

1:33 neoncontrails: Heh, 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

1:34 irctc: neoncontrails: will Cursive inject into the REPL out of the box?

1:35 neoncontrails: irctc: The REPL is actually a Cursive feature

1:36 IntelliJ has no support for Clojure without the Cursive extension, so I don't think it has any REPL-like capabilities natively

1:36 irctc: Wow, this incredibly cool.

1:39 neoncontrails: Love the syntax highlighting, but its still not able to detect a function name change and inject that.

1:39 neoncontrails: allenj12: 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.

1:40 irctc: hmm. say more

1:41 irctc: neoncontrails: 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

1:42 neoncontrails: irctc: when you say "change it" do you mean additionally defining another function in the current namespace called range-creator2?

1:42 irctc: no, modify the current one

1:43 so there no longer exists a range-creator, only exists a range-creator2

1:44 neoncontrails: What you're asking about is possible, but that requires manipulating the namespace macro itself, which I don't think you're doing

1:44 Walk me through your steps

1:47 irctc: neoncontrails: 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.

1:48 neoncontrails: so If a start the REPL and then make a new function: (defn new-thing (println "test")), it will fail if I call it.

1:50 neoncontrails: irctc: 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

1:50 irctc: neoncontrails: oh really? do tell, I'm new to clojure if you can't tell.

1:51 neoncontrails: try selecting the function you want to use and right clicking. There should be an option like "send highlighted definition to REPL"

1:51 there's several ways to import, you can very surgically import single definitions or entire namespaces

1:52 irctc: neoncontrails: that is awesome. Thanks for telling me about this. Definitely switching to Cursive.

1:54 neoncontrails: irctc: no prob, glad to help. Back to your earlier question about changing the name of a function, though

1:55 irctc: neoncontrails: it seems that you just send that newly defined function to the REPL and that solves it.

1:55 neoncontrails: irctc: the way to "undefine" a function would be (ns-unmap mynamespace myfunction), but you probably don't want to do this

1:58 irctc: neoncontrails: 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?

2:00 neoncontrails: irctc: forget what I told you earlier, actually. It's advanced clojure and assumes you've learned about namespaces, which are pretty unique to Lisps

2:03 I 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

2:03 observe that (def foo 5) (def foo 6) foo prints 6

2:05 irctc: err no, I mean changing (defn foo (println "5") to ----> (defn foo2 (println "5"))

2:05 neoncontrails: oh, so that defines two functions

2:05 irctc: right

2:05 neoncontrails: it defines foo first, and then it defines foo2

2:05 irctc: it just won't get injected, and then the REPL starts whining that it can't find foo

2:05 clojurebot: Titim gan éirí ort.

2:05 neoncontrails: foo doesn't "become" foo2 though

2:09 maybe you could pastebin an example showing the behavior. I'm still not sure what you mean when you say "changing" foo to foo2

2:10 irctc: neoncontrails: 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!

2:11 neoncontrails: irctc: no prob. Glad you figured it out!

10:06 jsabeaudry: Is it recommended practice to recursively append ! to all functions that manipulate atoms?

10:18 gfredericks: I 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:27 ToxicFrog: The 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:28 mpenet: originally it indicates "might be retried so beware" more than state modification I think

10:28 (STM context)

10:28 MJB47_: i was under the impression that the definition changes from person to person

10:28 mpenet: but then everybody now uses ! to indicate state changes more or less

10:28 MJB47_: http://stuartsierra.com/2016/01/09/how-to-name-clojure-functions/

10:29 mpenet: I guess "not pure" is broad enough

10:29 MJB47_: last para of "functions with side effects"

10:29 obviously not a definitive source

10:30 TimMc: Ignoring metrics and logging. :-P

10:30 mpenet: read that post, it's very personnal I think. As long as you follow a single rule

10:30 more like "a single set of rule" actually

12:06 sdegutis: What's the benefit of using (foo bar) rather than (.foo bar) when bar is a record and foo is a record method?

12:15 TimMc: You mean :foo ?

12:15 (in the first case)

12:15 mpenet: sdegutis: avoiding reflection for one

12:16 if you use the dot form you might have to add a type hint to the call I think

12:16 sdegutis: mpenet: 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:16 TimMc: I thought you could do (foo bar) if the method was called "foo".

12:16 mpenet: it has the cost of java method dispatch, it's probably **very** fast

12:17 sdegutis: sweet

12:18 So is (.foo bar) generally preferred over (foo bar)?

12:18 mpenet: but I don't know the details really

12:18 imho no

12:18 sdegutis: Why not? What's better about (foo bar)?

12:19 So far it just sounds slower with no benefit.

12:19 mpenet: if you type hint the call it might be faster but it probably is optimized down the road by hotspot

12:19 sdegutis: I guess the only advantage is that it's possible to redef (foo bar), but with good practices that's not needed.

12:20 mpenet: sdegutis: 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:20 TimMc: sdegutis: I don't think you *can* do (foo bar).

12:20 Maybe you're thinking of protocols?

12:21 mpenet: ,(defprotocol Foo (bar [this])) (defrecord foo [a] Foo (bar [this] a))

12:21 clojurebot: Foo

12:21 mpenet: ,(bar foo)

12:21 clojurebot: #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:21 mpenet: ,(let [f (foo. 1)] (bar foo))

12:21 clojurebot: #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:21 mpenet: bah

12:22 ,(let [f (foo. 1)] (bar f))

12:22 clojurebot: #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:22 mpenet: anyway, it's easy to test in a repl

12:22 sdegutis: TimMc: hmm yeah I think so

12:23 TimMc: and a record can implement a protocol, so you can do (foo bar) to record bar with protocol method foo

12:24 ystael: A 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:26 TimMc: sdegutis: You didn't mention a protocol was involved, that changes things...

12:27 ystael: Thread dump? ¯\_( ❛ᴗ❛ )_/¯

12:27 sdegutis: Sorry!

12:27 TimMc: Are you able to call shutdown-agents ?

12:31 sdegutis: So assuming you have a protocol and a record, is it better to do (.foo bar) or (foo bar)?

12:39 TimMc: And bar is not hinted with the record class?

12:44 sdegutis: Yeah no type hints.

12:45 mpenet: without type hints .bar is very likely super slow

12:45 it will go through reflection

12:45 sdegutis: Hmm.

12:46 Is there any previous discussion on this within the Clojure community?

12:46 mpenet: just tested it in repl

12:51 just use (foo ...) why do you want to use the dotted form so bad?

12:51 sdegutis: mpenet: 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:53 mpenet: .foo is just an artefact of the generated code, imho the correct way is to call the clojure fn, not the java method

12:54 sdegutis: Hmm interesting concept.

12:54 mpenet: also if the record was extended i am not even sure .foo works

12:54 sdegutis: Ahhhhhh.

12:54 mpenet: I mean via (extend-protocol ..)

12:54 sdegutis: Clever thought.

12:56 mpenet: yeah 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:57 so yeah, use (foo bar) :()

12:58 sdegutis: Alright, sounds good!

12:58 Thanks mpenet for your input.

12:58 mpenet: yw

13:01 sdegutis: TimMc: also thanks to you for your valuable feedback

13:06 TimMc: You can also use :foo for that matter if it's a record field...

13:06 sdegutis: Hmm interesting.

13:07 TimMc: In any event, try using Criterium to find out what actually is fastest in practice.

13:08 sdegutis: Well I'm not necessarily trying to get to what's fastest.

13:08 Just trying to figure out bestpractices and their reasonings.

13:08 You know what they say: "You're bound to be unhappy if you optimize everything. -Donald Knuth"

13:37 wink: hm, coding style optimized for vim movement commands

13:37 sounds like a cool idea :)

13:41 slester_: wink: what's that in reference to? I love vim! :D

13:42 wink: slester: just trying to think if long lines or short lines would be good. I mean there are // [[--something markers sometimes to code fold

13:43 benjyz1: hello. how can I get the content of a function? e.g. for (defn x []) get the string "(defn x [])"

13:44 justin_smith: benjyz1: by looking in the source file

13:44 benjyz1: or use clojure.repl/source, which does exactly that

13:44 this 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:45 benjyz1: thank

13:45 here is some more info http://stackoverflow.com/questions/3782970/how-can-i-display-the-definition-of-a-function-in-clojure-at-the-repl

13:45 justin_smith: benjyz1: if you need to generally know the source string for functions for application logic, you could look at technomancy's serializable-fn lib

13:45 benjyz1: there is meta :source ?

13:46 justin_smith: no

13:46 like I said, the only way is to look it up in the source file, this is what clojure.repl/source does

13:46 or you can use serializable-fn if you need to be able to get a source string directly from a function

13:46 benjyz1: ah ok. the approach above it writes a macro which assoc the source with meta.. not sure if that's a good idea

13:47 justin_smith: right, that's what serializable-fn does too

13:47 by actually altering what defn does(!)

13:48 benjyz1: cool. I want to send a program over the wire (i.e. clojure source).

13:50 justin_smith: yeah, that's what serializable-fn is meant for

14:06 favetelinguis: are 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:44 HeavenSucks: this is my profiles.clj: https://dpaste.de/X16h

14:44 when I run lein repl

14:45 I get this messages: https://dpaste.de/QZtU

14:46 ah, missing closed bracket ;D

14:47 sdegutis: Hi.

15:33 anti-freeze: I'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:19 justin_smith: anti-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:20 case performs better than cond / condp / multimethods because its tags are all compile time constants and it compiles directly to a jump table

16:24 Frozenlock: yogthos: 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:17 sdegutis: Hey all.

17:22 Frozenlock: hey you

17:22 noncom|2: is it ok to have a namespace whose name starts with a - or _ ?

17:23 sdegutis: I'd rather not ask that question myself.

17:23 Also hi Frozenlock.

17:23 Hope you're doing well this day?

17:25 anti-freeze: justin_smith: Sorry, I got disconnected. case is exactly what I was looking for, thanks

17:26 I guess I'll keep most methods on protocols, and whatever needs to deal with scalars, I can just use case

17:37 One last thing. Is it considered bad practice if I do something like, (fn [v] (new (type v))) in clojurescript?

17:40 hiredman: does that work in clojurescript? it doesn't work in clojure

17:41 in clojure new is a special form that needs a literal symbol that names a class

17:43 anti-freeze: hiredman: 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:45 hiredman: anti-freeze: are you sure it works?

17:45 banana`: 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:45 painful. Does anyone know a better way to accomplish this task?

17:47 anti-freeze: hiredman: https://www.refheap.com/113548

17:49 hiredman: my 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:49 banana`: are you for real?

17:49 ,(map :value [{:value 1} {:value 7}])

17:49 clojurebot: (1 7)

17:50 anti-freeze: hiredman: Interesting, I guess I got my answer. Thanks

17:51 banana`: Wow thank you I thought it should have been simpler than what I was trying to do

17:51 hiredman: ,(map-indexed (fn [i m] (when (contains? #{0 1} i) (get m :value))) [{:value 1} {:value 7}])

17:51 clojurebot: (1 7)

17:52 justin_smith: see also keep-indexed

17:53 hiredman: https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/analyzer.cljc#L1547

17:55 http://dev.clojure.org/jira/browse/CLJS-693

17:58 anti-freeze: hiredman: Turns out you were right

17:58 Oh, you found it before me

17:59 hiredman: it is sort of a weird area

18:00 anti-freeze: Im surprised how easy the source of the compiler was to understand (at a glance anyway)

18:01 hiredman: clojure requires a literal symbol naming a class to avoid doing reflection on the jvm

18:02 that issue doesn't exactly exist the same way for clojurescript, so how should new work?

18:03 anti-freeze: I 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:04 hiredman: maybe that is the intent

19:24 rhg135: has 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:05 kenrestivo: das 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:06 * kenrestivo has become fetishistic about insisting that all his projects pass lein check pedantic

20:06 rhg135: yeah, seems so

20:18 altho I see nothing on the tree

20:21 and it works inside a project...

23:01 WickedShell: How come nested #()'s aren't allowed?

23:09 mgaare: WickedShell: for one thing, what would the %'s refer to?

23:10 WickedShell: oh well... yes I guess that's a good point...

23:10 darn thats making it waay harder to pass some callback's though

23:10 mgaare: WickedShell: Use (fn) in that case

23:11 WickedShell: yeah I guess that's true

23:11 * WickedShell headdesk

23:11 WickedShell: thanks mgaare apparently I'm not making obvious connections at this point

23:11 ajb: is it more common to use #() than (fn)?

23:11 mgaare: as a matter of style, I tend to avoid #() except for the simplest one-liners

23:12 WickedShell: I was creating a simple one liner, and tend to use #() when I have something that doesn't take any additonal inputs

23:13 mgaare: as in, anything more complex than something like #(/ % 2) I prefer fn

23:14 ajb: I 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:14 (I am very new to clojure and lisp in general, so please don't get mad if I royally screw up)

23:14 mgaare: ajb: what would you want the output to look like exactly?

23:15 tolstoy: ,(ffirst [[1 2] [2 1]])

23:15 clojurebot: 1

23:16 ajb: I 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:17 mgaare: so, you want like, [[:li 1][:li 2]] ?

23:19 ajb: sorry, thinking aloud about my problem solved it

23:19 thank's anyways

23:20 :)

Logging service provided by n01se.net