Fork me on GitHub
#off-topic
<
2017-06-22
>
pesterhazy10:06:48

Is there something like a modern inetd, which listens to a port and spawns a process connected to the tcp connection via stdin/stdout?

pesterhazy10:06:19

I'd like a variant that can be run from the command line, not as a daemon, and works on macos.

qqq11:06:20

what's a neat way to generate all chars in [a-zA-Z0-9] ?

a1311:06:33

(map char (range from to))

a1312:06:15

(reduce 
             (fn [acc [from to]]
               (concat acc
                       (mapv char (range (int from) (inc (int to))))))
             []
             [[\a \z][\A \Z][\0 \9]])

a1312:06:30

(\a \b \c \d \e \f \g \h \i \j \k \l \m \n \o \p \q \r \s \t \u \v \w \x \y \A \B \C \D \E \F \G \H \I \J \K \L \M \N \O \P \Q \R \S \T \U \V \W \X \Y \0 \1 \2 \3 \4 \5 \6 \7 \8)

gaverhae12:06:14

You'll want (inc (int to)) as range does not include its upper bound

a1312:06:32

oh, yeah, thanks!

gaverhae12:06:54

Also, in this case I'd go for mapcat rather than reduce

gaverhae12:06:50

(mapcat (fn [[from to]] (map char (range (int from) (inc (int to))))) [[\a \z][\A \Z][\0 \9]])

a1312:06:04

Yep, but reduce looks like more functional way to do it to me 🙂

gaverhae12:06:47

for some reason reduce feels more low-level (i.e. more general and more flexible) to me so I tend to avoid it when there's another function that seems more specialized to the task at hand

gaverhae12:06:01

I don't have any real argument for it though 🙂

a1313:06:26

Using reduce with an accumulator is a pretty common pattern, I just had a thought if there ws a wrapper like:

(defn wtf
              [f combiner coll]
              (reduce
               (fn [acc v]
                 (combiner acc (f v)))
               coll))
so we can just do (in our case)
(wtf 
             (fn [[from to]]
               (mapv char (range (int from) (inc (int to)))))
             concat
             [[\a \z][\A \Z][\0 \9]])

gaverhae13:06:41

Well that's pretty much (defn wtf [coll combiner f] (->> coll (map f) (reduce combiner))))

gaverhae13:06:47

that's the general shape of reduce calls I guess; in this specific case (mapcat f coll) is roughly (->> coll (map f) (reduce concat)) so it feels appropriate

a1315:06:52

mapcat is

([f & colls]
     (apply concat (apply map f colls)))