Fork me on GitHub
#beginners
<
2017-03-02
>
payal00:03:37

hello all

payal00:03:51

I am trying to remove white spaces including new lines from the string, which is the best way to achieve it? should I write a function or use some function which is already available

donaldball01:03:43

clojure.string has some fns you probably could use. trim, trim-newlines, or replace might be good ones to look at.

payal01:03:03

cool let me try those . thanks !

vinai09:03:53

Connecting to the port from the command line the connection is accepted but then immediately closed again. My guess is that by calling accept on server-sock again the client sock is automatically closed. If so there must be a known way to deal with that, but how? (I'm not fluent in Java). Or is it the with-open macro?

vinai09:03:44

Ah yes! It IS the with-open macro!

vinai09:03:08

Thanks for listening 🙂

schmee10:03:04

vinai yup, this should be of interest 🙂 https://stuartsierra.com/2013/03/29/perils-of-dynamic-scope

vinai10:03:50

Thank you @schmee, reading

schmee10:03:26

tap no, you’re thinking of when

tap10:03:38

yeah, you’re right. Sorry. Deleted my message

vinai10:03:35

@schmee Thanks for that link, very relevant.

Sam H14:03:07

anyone know if there is an easier way to do this:

given:
[:a :b :c 1 2 3] => [:a 1 :b :2 :c 3]
currently I'm thinking the easiest way is:
(interleave (take 3 [:a :b :c 1 2 3] ) (drop 3 [:a :b :c 1 2 3]))

chronno14:03:07

Maybe something like: (apply zipmap (partition-by type [:a :b :c 1 2 3]))

Sam H14:03:52

how about if all the values are strings?

Sam H14:03:01

the end goal is really to create a map

Sam H14:03:53

["a" "b" "c" "1" "2" "3"] => {"a" "1" "b" "2" "c" "3"}

schmee14:03:07

shan

user=> (apply zipmap (split-at 3 ["a" "b" "c" "1" "2" "3"]))
{"a" "1", "b" "2", "c" “3”}

Sam H14:03:09

this is what I got in the end

(defn vec->map [v]
  (let [num-pairs (/ (count v) 2)
        ks (take num-pairs v)
        vs (drop num-pairs v)]
    (clojure.walk/keywordize-keys (apply hash-map (interleave ks vs)))))

Sam H14:03:37

@schmee your version is nicer

(defn vec->map-2 [v]
  (let [num-pairs (/ (count v) 2)]
    (clojure.walk/keywordize-keys (apply zipmap (split-at num-pairs v)))))

chronno14:03:49

@shan When you have one sequence of keys and another of values I think zipmap is the right tool for the job. If you know how many items there should be in the resulting map, you can use partition to get the keys and values sequences: (apply zipmap (partition 3 ["a" "b" "c" "1" "2" "3"])).

joshkh15:03:36

@lgessler thanks, that might do the trick!

lgessler18:03:44

@joshkh keep me posted, I think I'll have to write code like yours soon and I'd be curious to know if it works 🙂

josh.freckleton21:03:19

what are the recommended libs for doing relational operations on data, eg JOIN, SELECT, or stuff like you'd find in SQL? iirc, specter isn't for this kind of thing, or is it?

Alex Miller (Clojure team)21:03:34

clojure.set has ops for that

Alex Miller (Clojure team)21:03:55

they don’t go real deep, but depending what you need, it might be sufficient

josh.freckleton21:03:51

i'll check em out thanks