This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-03-04
Channels
- # announcements (4)
- # asami (38)
- # babashka (20)
- # beginners (188)
- # cider (1)
- # clara (11)
- # clj-kondo (103)
- # cljs-dev (15)
- # cljtogether (1)
- # clojure (138)
- # clojure-australia (5)
- # clojure-europe (33)
- # clojure-france (1)
- # clojure-losangeles (5)
- # clojure-nl (4)
- # clojure-norway (11)
- # clojure-serbia (3)
- # clojure-uk (11)
- # clojurescript (45)
- # community-development (3)
- # conjure (22)
- # core-async (18)
- # datomic (44)
- # defnpodcast (4)
- # deps-new (1)
- # depstar (49)
- # events (2)
- # fulcro (33)
- # girouette (2)
- # honeysql (37)
- # jackdaw (5)
- # jobs-discuss (16)
- # kaocha (3)
- # leiningen (4)
- # lsp (77)
- # malli (55)
- # membrane (4)
- # off-topic (61)
- # polylith (5)
- # quil (5)
- # reagent (33)
- # reitit (12)
- # remote-jobs (1)
- # reveal (4)
- # rewrite-clj (2)
- # sci (16)
- # shadow-cljs (22)
- # sql (1)
- # test-check (27)
- # tools-deps (44)
Equal length strings?
generate a string of more than n characters, generate a vector of n characters and indices, then fmap over both of those producing a pair of the string, and the string with characters swapped at the indices
You could also generate edit operations
What I've done so far is generate a string, and then edit out parts of it at random start and end positions using subs, joins and replace
Random meaning calling rand-int or similar?
Tied together with bind and fmap?
in order for the generator to work at all, you need to at the base to be able to turn 1 string in to a pair of strings
I think generating edits is pretty easy, though it might be harder to aim for exactly N differences if you need that
Generating edits would shrink nicely I think
If you want to shrink toward fewer differences
;; written but not run
;; assuming strings of length 5 and differences of 3 characters
(gen/fmap
(fn [string edits]
(loop [[[shift index] & es] edits
s (vec string)
editted #{}]
(if e
(let [i (mod index (count s))]
(if (contains? editted i)
(recur (cons [shift (inc index)] es) s editted)
(recur es
(update-in s [i] (fn [c]
(char (+ 32 (mod (+ offset (- (int c) 32)) 126)))))
(conj editted i))))
(apply str s))))
(gen/tuple (gen/resize 5 gen/string-ascii)
(gen/tuple
(gen/tuple s-pos-int s-pos-int)
(gen/tuple s-pos-int s-pos-int)
(gen/tuple s-pos-int s-pos-int))))
I thought I had run into not being able to recur from the first branch of if but I may well be getting mixed up with recur within try