#clojure log - Aug 08 2015

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

0:35 Kwhy_Not: Info

2:56 tmtwd: http://pastebin.com/8bzEsdWr

2:57 Can anyone explain this function to me?

3:00 justin_smith: tmtwd: that looks like a react component

3:01 tmtwd: justin_smith, is that what props is or is that an observation?

3:01 :)

3:02 but yeah, it is

3:02 hm, maybe there is something about reagent I'm just not getting

3:25 oddcully: tmtwd: the function returns a function, that takes the props. not knowning reagent, i'd say it gets called to render the component (later) and the props come from reagent (later)

3:26 tmtwd: oh, I see, the anonymous function is being returned, then it gets passed props, which then gets evaluated

3:27 what does {:keys [title on-save on-stop]} do?

3:29 oddcully: destructuring

3:29 arav93: How do I start off sampling clojure.zip. The entire namespace and functions in it seem really confusing!

3:30 oddcully: ~destructuring

3:30 clojurebot: destructuring is http://clojure.org/special_forms#binding-forms

3:30 oddcully: i knew it!

3:35 tmtwd: oddcully, thanks, I could not find that for some reason

3:37 how come this returns nil? ( {:keys [yolo]} {:yolo 23})

3:38 it has to be in scope or something?

3:39 oddcully: because you call map on a map

3:39 you lack the let

3:39 tmtwd: oh

3:39 oddcully: ,(let [{:keys [x]} {:x 666}] x)

3:39 clojurebot: 666

3:40 tmtwd: ohhh

3:40 odd

3:40 oddcully: s/odd/awesome!/

3:41 tmtwd: hehe, what is s?

3:43 clarkenciel: http://vim.wikia.com/wiki/Search_and_replace

5:17 crocket: Can clojure be used to create something like https://github.com/phpsysinfo/phpsysinfo ?

9:32 Bronsa: ambrosebs: ping

9:52 ambrosebs: I saw your ast-ref commits -- thanks! in case you find something else that's not updated, please run spec/buildref.sh so that the html doc gets rebuild too

11:30 Arcaed0x: Hi there...?

11:39 xcthulhu: Hey, is there a nifty way of getting a random free port?

11:40 (I’m doing integration tests for a webserver)

11:40 Hey cemerick, how do I get a random free port so I can do little integration tests with a real webserver?

11:40 With, say, http-kit or whatever

11:42 cemerick: xcthulhu: pass 0 for port number, that will allocate a random available port

11:42 xcthulhu: Sweet how do I grab the port once it picks a random one?

11:43 (I recognize there are docs)

11:45 Here’s where you can grab it: https://github.com/http-kit/http-kit/blob/master/src/org/httpkit/server.clj#L32

11:45 (for all of you future google people who stumble across this IRC chat)

12:14 weebz: does anyone know off the top of their head how to get cider in emacs to not have errors/exceptions display in a new buffer? it's a little annoying constantly closing and switching out of that buffer

12:15 i'm not sure where else it could be displayed, just looking to have something that isn't as interrupting if that makes sense?

12:17 wasamasa: it can pop it to a window

12:18 justin_smith: weebz: best fix is winner mode http://emacswiki.org/emacs/WinnerMode

12:18 weebz: with winner mode you can undo any random popped up anything easily

12:29 weebz: wasamasa, so it'll open in a new window that I can just C-x 0?

12:29 justin_smith: weebz: that would be c-x 5 0

12:29 it's easier to turn on winner-mode and hit C-c <left-arrow>

12:33 weebz: I'm a little confused how the undo is working. My issue right now is that I'm working with 2 windows (one source code, one REPL), and when I type an error in the REPL it opens up the error buffer in the source code window

12:34 winner undo just closes the window when I hit C-c <left>

12:34 justin_smith: then your history is not set up right...

12:34 try starting with one window, then splitting, then opening the right buffer in each half

12:34 weebz: very likely, I'm still quite new to Emacs

12:35 justin_smith: after you do all that, C-c left will take you back to the original window / buffer setup you wanted

12:35 also you can use C-c left / C-c right repeatedly to get all window / buffer configurations back as you like

12:37 weebz: it does what I want if I switch back to the REPL window and hit C-c <left>

12:38 but if I hit C-c <left> while the cursor is in the error window/buffer it reverts both windows to the source code buffer

12:38 justin_smith: weird...

12:38 what about just hitting q when the error buffer pops up?

12:38 wasamasa: weebz: no, q suffices

13:28 jonathanj: hrm, manifold.stream/put! returns synchronously?

13:29 is there a case where one might want to wait one put to complete before doing the next?

13:29 i guess they will appear on the stream in the order they were put so getting the order mixed up is probably unlikely, and anything else is probably application specific

13:36 hrm

13:45 i have a seq of strings ["a" "b" "c" "d"] i'd like to join all but the last with " " and the last with ": "

13:45 i'm not quite sure how to efficiently construct this, i'd also like to avoid using (count)

13:46 (interleave) and (repeat) seem like they might work but i'm not sure how to get the special case separator at the end

13:50 justin_smith: jonathanj: butlast / last?

13:50 oddcully: ,(let [l ["a" "b" "c"]] (str (clojure.string/join " " (butlast l)) ": " (last l)))

13:50 clojurebot: "a b: c"

13:50 tmtwd: cider is giving me an error of input not complete and will freeze up

13:50 how do I quit the current "input"?

13:50 jonathanj: it probably doesn't actually matter for my case but i was trying to avoid those because they talk about linear time

13:51 justin_smith: jonathanj: then use a vector and peek and pop which are much faster

13:52 ,(let [l ["a" "b" "c"]] (str (clojure.string/join " " (pop l)) ": " (peek l)))

13:52 clojurebot: "a b: c"

13:52 justin_smith: does not work with lazy-seqs, and does not work as you would expect with lists

13:53 oddcully: popl and peekl could be a cartoon show

13:53 jonathanj: justin_smith:great, that would work perfectly for my use case

13:56 tmtwd: (without restarting cider, that is)

13:56 justin_smith: tmtwd: C-cC-c should cancel the current input

13:56 tmtwd: justin_smith, :) thansk

14:00 justin_smith: jonathanj: of course creating a vector is linear time

14:00 jonathanj: justin_smith: i find myself wondering if there is a nice solution with lazy seqs without last/butlast

14:01 justin_smith: jonathanj: a recursive function on the lazy-seq could do it

14:02 it would involve testing if you are at the next-to-last item on each iteration, and using a stringbuilder if you want speed (or a bunch of intermediate strings if you don't care about speed)

14:05 tmtwd: Ah, for some reason cider-repl-kill-input just works for me

14:05 jonathanj: i keep forgetting this, but what is this command called: (x [1 2] [3 4]) => [[1 3] [2 4]]?

14:06 (in Python it's called zip)

14:06 oddcully: map vector would result in this

14:07 waynr: can anyone point to an example of using clj-logging-config to set logging configuration dynamically?

14:07 jonathanj: oddcully: ah, true, thank you

14:08 oddcully: but bet there is an easier way i forgot

14:09 amalloy: oddcully: nope

14:32 tmtwd: whats the proper way to define a regex string in clojure? (def the-string "\Q(youtu.be/|youtube.com/(watch?(.*&)?v=|(embed|v)/))([^?&"'>]+)\E") . I'm trying this from a stackoverflow answer, I don't think it is correct though

14:32 I keep getting a unmatched delimiter error

14:35 amalloy: #""

14:35 clojurebot: It's greek to me.

15:27 justin_smith: tmtwd: there's an unescaped " in the middle of that regex

15:27 tmtwd: ah

15:27 justin_smith: also it's a string, and probably you want it to be an actuall regex (using the #"" syntax)

15:28 tmtwd: yes, in that example I forgot the # ----- there should be an app that inserts all the escape chars for you

15:29 and you can select whichever language you want outputted

15:29 justin_smith: tmtwd: there's an emacs mode that does it

15:29 tmtwd: which one?

15:29 justin_smith: one moment, have to look up the name (just remember my keybinding)

15:30 string-edit, it provides the command "string-edit-at-point"

15:30 tmtwd: ok will look into it

15:30 justin_smith: it opens the unescaped string in a new buffer, and when you hit C-cC-c it takes what's in the buffer, escapes it, and puts it back where your cursor was

15:30 also you can use it recursively

15:31 to escape a string inside an escaped string...

15:32 tmtwd: wow

15:32 sounds like a useful tool

16:04 magnars: justin_smith: I made string-edit, and I had never considered that you could use it recursively. Thanks ^^

16:40 justin_smith: magnars: haha

16:42 magnars: thanks for making string-edit btw, it's useful

16:43 magnars: just scratching my own itches - glad it's of help :-)

17:03 jonathanj: i'm writing an IRC client and the API i have at the moment is returning [send-command close-connection!] from the function that establishes the connection, the problem is that commands to reply to a message or say some text turn into something like (say send-command target msg) and i have to pass send-command around everywhere

17:04 in something like java or python, one might return some object that encapsulates a giant pile of state

17:04 is there an idiomatic clojure approach to this kind of problem?

17:09 tdammers: use closures?

17:10 wasamasa: jonathanj: perhaps https://github.com/stuartsierra/component

17:12 jonathanj: tdammers: could you elaborate?

17:13 tdammers: send-command is already a closure, it closes over the raw tcp stream and provides a slightly more high level api than "some bytes"

17:13 tdammers: ah, ok

17:13 jonathanj: tdammers: it's infeasible to provide a closure for every possible command that could ever be executed though

17:13 tdammers: I thought the question was "how do I wrap up a bunch of state in order to pass it around"

17:14 jonathanj: tdammers: it is that, except it's a level up

17:16 component looks like a possible solution, albeit quite a complicated one

17:17 wasamasa: it isn't complicated actually

17:17 just a pretty disciplined way to structure an application

17:17 jonathanj: maybe complicated wasn't the right word

17:17 wasamasa: if you take a look at the code, you'll notice it's nearly nothing

17:18 jonathanj: i guess i always thought of (defrecord) of giving up on a functional style

17:19 as giving up*

17:20 maybe that's just an extreme reaction?

17:21 wasamasa: perhaps

17:21 clojurebot: Excuse me?

17:21 wasamasa: I don't see anything wrong with them considering they're just another type of immutable data structure

17:22 jonathanj: there's also the "Notes for Library Authors" section, which seems pertinent

17:36 weebz: Does anyone know how to list an objects methods+properties in the CLR version on mono?

17:36 It doesn't seem like I'm able to use the typeof() function for some reason

17:46 Figured it out. (.GetProperties (type obj)) and (.GetMethods (type obj))

18:22 tmtwd: is is there a way to use callbacks in reagent , like I want to do in this example? http://pastebin.com/N3y0KSiu

18:23 justin_smith: tmtwd: that do is redundant

18:24 does create-new-contact do something async?

18:24 tmtwd: it just adds a contact to a database , but list-contacts (which renders the list) seems to be called before the contact is added

18:25 justin_smith: what kind of database?

18:25 tmtwd: oh, I suppose I could just call list-contacts in create-new-contact ---

18:25 justin_smith: is it a call to an api?

18:25 tmtwd: justin_smith, postgres via a local api

18:26 justin_smith: OK, then you should make sure the API gives you back its success result before you return from create-new-contact

18:27 or, if it's an AJAX call to the api, you can put (list-contacts) in the callback

18:27 or, you could use core.async

18:28 tmtwd: i see, I put in in (list-contacts), since it is an ajax call

18:35 oddcully: tmtwd: usually in react land you want to "react" on the change

18:35 so request your modification in your button

18:35 tmtwd: okay

18:36 oddcully: but let some centract instance take care of the change

18:36 once the change occurs, depending on your "storage" in the client, it should trigger the re-render of "everything"

18:36 tmtwd: centract?

18:36 oddcully: usually you have some watch on your actual data

18:36 justin_smith: oddcully: so you mean a component

18:37 oddcully: s/centract/concrete/

18:43 hmm to bad, that word is already in use

18:43 i had hoped i found a new one

20:00 domokato: i have a vector created with [] and I'm trying to add more elements to it using for, but instead it creates a sequence inside of the vector. Is there a way to pull the elements out of the sequence and put them into the vector?

20:03 oddcully: ,(let [v []] (into v (for [i (range 3)] i)))

20:03 justin_smith: domokato: into

20:03 clojurebot: [0 1 2]

20:03 justin_smith: domokato: remember that vectors are immutable, so what's really happening is that conj or into returns a new vector that you have to use

20:03 domokato: ah, okay, but there's no way to do it somewhere like part way inside the vector, without breaking it up

20:04 justin_smith: domokato: no, vectors do not support inertion in the middle, you have to do something else (maybe concat)

20:05 domokato: oo okay, into or concat, thanks guys

20:07 justin_smith: ,(let [v [:a :b :c :d :e]] (reduce into (subvec v 0 2) [[1 2 3 4] (subvec v 3 5)])

20:07 clojurebot: #<RuntimeException java.lang.RuntimeException: EOF while reading>

20:08 justin_smith: ,(let [v [:a :b :c :d :e]] (reduce into (subvec v 0 2) [[1 2 3 4] (subvec v 3 5)]))

20:08 clojurebot: [:a :b 1 2 3 ...]

20:08 justin_smith: ,(apply str (let [v [:a :b :c :d :e]] (reduce into (subvec v 0 2) [[1 2 3 4] (subvec v 3 5)])))

20:08 clojurebot: ":a:b1234:d:e"

20:09 justin_smith: domokato: whatever you come up with, you'll likely find subvec helpful

20:09 amalloy: domokato: notably, there is no function to do it because it is impossible to do efficiently. if it's important for you to do it, you can still do so inefficiently, but you should usually reconsider whether vectors are the right data structure

20:10 justin_smith: excellent point

20:10 domokato: i'm trying to create an android layout using neko, which takes a vector

20:13 i think using concat i can preserve the order of ui elements in the code, for readability's sake

20:14 justin_smith: domokato: into does less work, if CPU becomes an issue

20:14 also concat returns a lazy-seq, not a vector

20:15 so you'll have the added cost of constructing a vector at the end, if the API needs a vector

20:15 unless you use into, which preserves the vector format

20:15 oddcully: depending on your work you are doing, there is also mapv

20:16 (only for readability - in it's guts its into)

20:22 domokato: cool, gotcha

20:29 sdegutis: What's an admirable technique for getting the index of a given element in coll, and for getting an element by its index?

20:30 Ah, I see nth for the second part of my question.

20:31 I guess I can make do with map-indexed for the first part, if there's nothing better.

20:48 Hi.

20:54 jwm: hello

20:57 oddcully: hi

22:20 AWizzArd: I have an interface which I would like to reify. This interface has two methods `onFailure` that each take one arg. Those two methods are overloaded by type. How do I translate this into Clojure syntax?

22:21 justin_smith: AWizzArd: type hint the arguments in the declarations iirc

22:24 AWizzArd: Tried that. Got this error message: “Mismatched return type: onFailure, expected: void, had: java.lang.Object”

22:24 Oh okay, seems I need to hint the return type as well.

22:25 justin_smith: makes sense I guess - in for a penny, in for a dollar?

22:30 oddcully: that is a good rule for any type system

22:45 sg2002: So, type hints work for reify? AFAIK they don't work for proxy.

22:47 waynr: can anyone recommend a function in clojure that will pretty print just the structure of a deeply nested data structure?

22:51 turbofail: what does the "structure" mean?

22:54 mistaBIZ: google'd to find "the arrangement of and relations between the parts or elements ..

22:54 waynr: i guess i mostly just don't want to look at all the dictionaries in each list since I know each dictionary has the same structure, i want to be able to see the entire structure at once so I can have confidence that i am accessing values correctly

22:56 mistaBIZ: as in how many branches of the tree it is in?

22:57 * 19:47

22:59 justin_smith: mistaBIZ: you could do a clojure.walk/postwalk that turns instances of map m into :my/m

23:00 ,(require '[clojure.walk :as walk])

23:00 clojurebot: nil

23:02 justin_smith: ,(require '[clojure.walk :as walk])

23:02 clojurebot: nil

23:02 justin_smith: ,(walk/postwalk #({{:a 0 :b 1} :my/m} % %) [{:a 0 :b 1} {:x {:a 0 :b 1}} [:f {:z {:a 0 :b 1 :c {:a 0 :b 1}}}]])

23:02 clojurebot: [:my/m {:x :my/m} [:f {:z {:a 0, :b 1, :c :my/m}}]]

23:03 justin_smith: mistaBIZ: is that addressing what you want at all?

23:04 mistaBIZ: thats deep

23:04 justin_smith: mistaBIZ: it just finds all duplicates of a specific value and replaces them with a shorthand

23:45 rpaulo: \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'

Logging service provided by n01se.net