New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avast ye string handlers #747
Conversation
Lol! Amazing. I don't see a diff on here yet - just some master branch merges. |
Hrm, I botched this PR somehow. Looking into it now. |
Codecov Report
@@ Coverage Diff @@
## master #747 +/- ##
==========================================
+ Coverage 41.67% 43.09% +1.42%
==========================================
Files 79 80 +1
Lines 2294 2369 +75
Branches 84 84
==========================================
+ Hits 956 1021 +65
- Misses 1254 1264 +10
Partials 84 84 |
Those pullll requests duty better when ye make some commits on tha brraanch aforre pushing, brring 'er alongside. Fixed :-D |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall! Wana add any unit tests?
;; think this is pretty straightforward with Slack but I have to give | ||
;; IRC some more thought. TZ might be an input to how we sort | ||
;; recommended locations, for Issue #740 - Weather API migration. | ||
(def local-tz "America/New_York") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. I think I've hardcoded Pacific Time elsewhere but obtaining from Slack user would be clever.
Tests added. This is my first time use Midje, which feels cleaner than clojure.test. I'll update this PR shortly with the refactors you suggested above (thanks!). |
Looks good! Another contributor (@dawsonfi) ported Yetibot's test from clojure.test to Midje awhile back. It seems pretty clean but I'm still on the fence to be honest 😆 Tests in yetibot.core are still using clojure.test. Maybe someday we'll unify and just pick one. |
I believe this is gtg, from my end. Moving TZ and EDN bits would be a separate PR, with associated changes made elsewhere in the code base. |
@jcorrado looks good except there's a test failure! |
Investigating test failure now. Unclear why that passed on my system. I wonder what I might muddied up to skew things. |
I see the problem. Ginning up a fix now... |
The old version of slurrr would randomly suffix 0-2 additional letters (the *slurring*) to all applicable words. This had a nice realistic effect - much better than just slurring all words. However, it also meant there was a chance that none would be slurred, which looked janky and intermittently broke tests. This new approach guarantees *some* (percent + fuzz) or potentials candidates will be slurred.
GTG from my end. |
[s] | ||
(let [words (str/split s #"\b") | ||
sm (mk-slur-map (count (filter slurrable? words)))] | ||
(loop [[word & tail] words, sm sm, accum []] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can replace loop
with reduce
but it's not exactly an improvement.
(def words (str/split "Clojure is a general-purpose programming language with an emphasis on functional programming" #"\s"))
(def sm (mk-slur-map (count (filter slurrable? words))))
(:words-acc
(reduce
(fn [{:keys [sm words-acc]} word]
(let [[should-slur & rest-slur-map] sm]
(if (slurrable? word)
;; possibly slur it while consuming an entry from sm
{:words-acc (conj words-acc (if should-slur (slur-word word) word))
:sm rest-slur-map}
;; just accumulate the word and maintain the slur map as-is
{:words-acc (conj words-acc word)
:sm sm})))
{:sm sm
:words-acc []}
words))
result
["Clllojurre" "is" "a" "generrraalll-purrpose" "programming" "language" "with" "aan" "emphaaasis" "on" "functionaalll" "prrogrrraamming"]
(Note I split on whitespace but of course this doesn't retain the user's original whitespace).
I'm fine with it either way; I'm not suggesting you switch to reduce
as I don't think it's significantly more readable.
If I were to continue refactoring I would probably make the slur-map
vector's length match the length of the words
vector. It would check if a word is slurrable and put in a nil
without affecting overall chance of true
values for slurrables.
The nice part about making the length match is then we could map
them together and simplify the slur logic quite a bit:
(map (fn [word slur?]
(if slur? (slur-word word) word))
words
slur-map)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎊
Hi @devth,
Friday afternoon puttering! This is partly for the fun of it, and partly to kick around some ideas for #740, and general codebase exploration.