Fork me on GitHub
#clojure
<
2017-02-22
>
nrayapati04:02:10

Oops wrong window

danielgrosse07:02:21

How can I merge to vectors to return a vector with each value of both vectors joined into a subvector?

["a" "b" "c"] ["1" "2" "3"] -> [["a" "1"] ["b" "2"] ["c" "3"]]

residentsummer07:02:45

improving on mpenet’s solution to precisely match the spec: use mapv instead

residentsummer07:02:33

so (mapv vector ["a" "b" "c"] ["1" "2" “3”])

danielgrosse07:02:39

Thank you. So easy.

mpenet07:02:54

issue advertising: if you care about spec -> swagger support (among other things) you might want to vote on http://dev.clojure.org/jira/browse/CLJ-2112

zugnush08:02:16

I'm looking for a way to cycle paren style round, curly, square in emacs, can't see anything obvious in cljr

qqq08:02:15

you mean change a pair of () to [] to {} ?

qqq08:02:25

@zugnush: I need to do that too; when you figure it out, please let me know 🙂

ddrbt08:02:24

I have a lazy sequence of hash-maps. I want to return the best hash-map found within some time limit when reducing the sequence. Any ideas on the simplest way to do this?

qqq08:02:11

@ddrbt: you could use a recur/loop, which keeps track of time + cur best

ddrbt08:02:53

Ah, and return when current time exceeds start by some limit.

qqq08:02:23

precisely, technically you do this inside a (reduce ... ) too if you put the time checking into the reducer function and use something called "reduced" (which I belive short circuits the rest of the list)

qqq08:02:47

@ddrbt: https://clojuredocs.org/clojure.core/reduced also causes short circuiting if you absolutely want to use 'reduce' in stead of loop/recur

ddrbt08:02:25

Thanks. I’ll try that out. I was scratching my head thinking about atoms and channels 😬

qqq09:02:22

well, above suggestion = single threaded, if you want to do a multi threaded search for opt, you proably need channels or queues

ddrbt09:02:26

@qqq hmmm… thanks. I’ll try out the loop/recur method first and see if it’s fast enough

kaffein09:02:05

hey guys, my brain somehow tries to relate clojure agents to scala actors. Am I building the right mental model for it or should I just forget that similarity to not screw things up ?

mpenet09:02:53

they are totally different things

placeboza09:02:39

They are both not simple 😛

placeboza09:02:18

maybe Im wrong about agents, so ignore me

igrishaev09:02:20

Hi folks, I'd like to introduce my first Clojure library for browser automation using Webdriver API. If anybody needs to run frontend tests, feel free to use it and and share your ideas regarding to how te make it better. Thanks! https://github.com/igrishaev/etaoin

mobileink16:02:34

igrishaev: that looks very cool. i have not used this kind of tool. can i use it to scrape? e.g. get the list of items in a drop down, so i can select

mobileink16:02:18

one and then click the search button and collect the result?

igrishaev16:02:39

yes you can I think

igrishaev16:02:09

not sure there are all the required functions are implemented

pesterhazy11:02:20

wow that seems like a good idea @igrishaev

pesterhazy11:02:19

I assume the selenium java libs are good quality as selenium is written in java (?) - what prompted you to implement the protocol directly?

souenzzo11:02:33

There's no spec for spec ns? RLY?

igrishaev11:02:51

well, initially, I was wondering how does selenium work under the hood. Once I've found it's just HTTP API, I decided to implement my own version of it. I believe, pure-clojure way makes the code clearer and easier to understand.

igrishaev11:02:32

@pesterhazy and we also had some troubles with clj-webdriver, for example I could not launch our unit tests from Emacs.

pesterhazy11:02:44

@socksy, this may be interesting to you ^^

sveri12:02:37

@igrishaev Do you have the code online?

igrishaev12:02:12

@sveri sorry, what do you mean?

igrishaev12:02:56

@sveri here is a GH link posted above

sveri12:02:01

@igrishaev Sorry, I missed that and yes, thats what I meant

genec12:02:01

David, if you don't mind my asking, what's your background? I'm just starting out with Clojure too, coming from C# / F# / Python. I may be able to recommend some books etc. One thing I still struggle with is a good IDE/Dev setup for Windows. I'm using Lighttable now, but will probably switch to Cursive soon. ps - there's a beginners channel for Clojure too.

davidtpriest13:02:10

genec: Hello! Honestly i am in the midst of a career change and don't really have much experience with programming in general, other than a bit of python to understand the basics. I will gladly accept recommendations for beginners books in Clojure and even books on functional programming in general. Im basically starting from scratch.

tech_hutch13:02:06

I have IntelliJ and Cursive installed (the latter is free for personal use, to my understanding), but I've been using Atom recently.

genec13:02:13

@U46LM0HR6 are you using Atom on Windows?

genec13:02:31

@davidtpriest http://www.braveclojure.com/ and Living Clojure are both very good. Also, Clojure West is coming up next month in Portland and there's a 2 day intro class prior to the conference.

genec13:02:37

@U46LM0HR6 Thanks, and you don't have any issues? When I use proto-repl/Atom repl tends to get stuck. Are you on Win 10?

davidtpriest13:02:00

@U342BD0RG Thanks. Multiple sources have recommended brave clojure as well as living clojure. Will look into them. Unfortunately i live in VA but would totally go if it were in my neck of the woods. 😃

tech_hutch13:02:12

Oh. I have the proto-repl plugin installed, but I haven't actually used it yet. I am on Windows 10, so I'll let you know, when I use it.

sveri12:02:46

+1 for cursive 🙂

ben-long14:02:04

@davidtpriest I came to Clojure from a non-programming background too, and found Nightcode was a good IDE to start off with. If you haven't already been there, also check out http://www.braveclojure.com.

nico14:02:35

Hello 👋

nico14:02:56

clojure beginner here, following the (so far good) braveclojure tutorial

nico14:02:28

and at some point it recommends to implement comp by hand

nico14:02:40

and there's no solution and I'd like someone to look at it 🙊

sveri14:02:14

@nico welcome and good luck on your path. We have the #beginners channel here and also a dedicated #code-reviews channel. I think both are appropriate for your question 🙂

nico14:02:20

oh sorry!

nico14:02:26

will head out there 🙂

jaju14:02:51

@igrishaev - Thanks! I followed the readme example, and it worked like a charm! Brilliant stuff!

igrishaev14:02:24

@jaju thanks, glad to hear it

carocad15:02:22

out of curiosity: why does distinct uses a Clojure's immutable hash set? would it be faster to use java's mutable hashset since no side effects would take place outside of this function? https://github.com/clojure/clojure/blob/clojure-1.9.0-alpha14/src/clj/clojure/core.clj#L4933

rauh16:02:55

(let [x (java.util.HashSet.)]
  (.add x 1N)
  (.contains x 1))
(contains? #{1N} 1)

rauh16:02:00

@carocad ^, one give false, the other true.

joshjones16:02:03

looking at the code for distinct just now, I noticed recur being used in the "then" portion of an if block, and sure enough, when I try to compile this:

(defn distinct'
  [coll]
  (let [step (fn step [xs seen]
               (lazy-seq
                 ((fn [[f :as xs] seen]
                    (when-let [s (seq xs)]
                      (if (contains? seen f)
                        (recur (rest s) seen)
                        (cons f (step (rest s) (conj seen f)))))
                   xs seen))))]
    (step coll #{})))
I get CompilerException java.lang.UnsupportedOperationException: Can only recur from tail position ... so, how is this compiling in clojure.core?

carocad16:02:09

@rauh do you know why?

rauh16:02:21

(= 1 1N)
(.equals 1N 1)

rauh16:02:39

Java uses equals, clojure uses its own equiv. @carocad

timrichardt16:02:01

@joshjones the (fn [[f :as... contains xs and seen, you just slurped in the arguments

joshjones16:02:35

@timrichardt what does that have to do with recur?

timrichardt16:02:49

that makes xs and seen the tail position

timrichardt16:02:57

only seen, to be exact

joshjones16:02:34

i see now why the recur is in a tail position, because if is in the tail position of the function -- but why won't it compile in a repl?

timrichardt16:02:42

a.h> (defn distinct'
  [coll]
  (let [step (fn step [xs seen]
               (lazy-seq
                ((fn [[f :as xs] seen]
                   (when-let [s (seq xs)]
                     (if (contains? seen f)
                       (recur (rest s) seen)
                       (cons f (step (rest s) (conj seen f))))))
                 xs seen)))]
    (step coll #{})))
#'agp.handler/distinct'
a.h> (distinct' [1 2 2 3])
(1 2 3)

timrichardt16:02:50

you just messed up the parenthesis

timrichardt16:02:00

in your example the if is not in the tail position

joshjones16:02:51

actually, parinfer messed up my parens 🙂 thx for clarifying

carocad16:02:27

@rauh so a hashset version that uses equiv in a mutable way would basically be (transient! #{}) right?

rauh16:02:00

@carocad There is a JIRA ticket that's discussing that, yeah.

nottmey16:02:03

mind is blocked right now: how do I apply a function to each key of a map again? oO

nottmey16:02:05

ahh ok, the nasty way

carocad16:02:58

@nottmey a bit less ugly but same result (zipmap (map f (keys foo)) (vals foo))

danielsz17:02:07

@nottmey Have a look at reduce-kv

joshjones17:02:09

@nottmey you can also just depend on [org.clojure/algo.generic "0.1.2"], require [clojure.algo.generic.functor :as f :only [fmap]], and call fmap directly -- (fmap func your-map)

nottmey17:02:45

@clojurebot ewww … was (reduce-kv #(assoc %1 (name %2) %3) {} {:a 1 :b 2 :c 3}) looks alright, ty both

dpsutton17:02:13

ahh, you used the #() function notation?

joshjones17:02:36

sorry bro, i guess "key" and "value" look the same to my eyes 😝

plins17:02:53

is there a 'reverse comp'? instead of (comp b->c a->b) i would (rev-comp a->b b->c)

shader21:02:02

What's the right way to get a date from clj-time to work with nippy? I can manually cast back and forth, but it seems like the kind of thing I should be able to do by extending the serializer

shader21:02:34

all I need to do is use the clj-time.coerce/to-date and from-date functions, since nippy already serializes java.util.Date objects...

shader21:02:58

while I'm asking about this, are there any reasons not to do that particular coercion? Loss of information etc.?

seancorfield22:02:15

@shader If you’re talking about extending the protocol, then be aware that it would apply for all code in your app, not just the pieces you’re thinking about.

tbaldridge22:02:28

@shader one of the main reasons I favor Transit over other marshalers, it's context dependent. i.e. you can override stuff for a single writer.

shader22:02:57

I don't think there should be any problems with extending the protocol in general