Coding the Haiku Kata in Smalltalk
Inspired by implementations in Eclipse Collections, Java Stream, & Groovy
Coding the Haiku Kata in Smalltalk
Inspired by implementations in Eclipse Collections, Java Stream, & Groovy

Setup for the Haiku Kata in Pharo Smalltalk 13.0
The Haiku Kata Continues
I have implemented the Haiku Kata in Java previously with Eclipse Collections and Stream. José Paumard has live coded the Haiku Kata in JEP Café Episode 9 on the Java YouTube channel. Paul King implemented the kata in Apache Groovy. You can find the links to all of our previous solutions in the following blog.
Let’s Try a Little Smalltalk
I’ve written a few Smalltalk blogs in the past week, covering various features of the language. I thought I would try something a bit more complicated that requires writing some unit tests instead of just code snippets.
As you can see in the image above, I created a test class named HaikuTest. in a package named Haiku-Tests.
TestCase << #HaikuTest
slots: { #haiku };
package: 'Haiku-Tests'
The HaikuTest has a single variable named haiku which is initialized in the setUp method.
setUp
super setUp.
haiku := '
Breaking Through Pavement Wakin'' with Bacon Homeward Found
---------------- -------- ----------------- --------------
The wall disappears Beautiful pavement! Wakin'' with Bacon House is where I am
As soon as you break through the Imperfect path before me On a Saturday morning Home is where I want to be
Intimidation Thank you for the ride Life’s little pleasures Both may be the same
Winter Slip and Slide Simple Nothings With Deepest Regrets
--------------------- --------------- --------------------
Run up the ladder A simple flower With deepest regrets
Swoosh down the slide in the snow Petals shine vibrant and pure That which you have yet to write
Winter slip and slide Stares into the void At death, won''t be wrote
Caffeinated Coding Rituals Finding Solace Curious Cat Eleven
-------------------------- -------------- ----------- ------
I arrange my desk, Floating marshmallows I see something move This is how many
refactor some ugly code, Cocoa brewed hot underneath What it is, I am not sure Haiku I write before I
and drink my coffee. Comfort in a cup Should I pounce or not? Write a new tech blog.
'
Counting Characters in Smalltalk
The first test that I will implement is the test which counts all of the characters in all of the haiku. The test validates the top three letters in the counts. Just as we did in Eclipse Collections, in Smalltalk we use a Bag type to count.
testTopLetters
| bag sorted |
bag := ((haiku select: #isAlphaNumeric) collect: #asLowercase) asBag.
sorted := bag sortedCounts.
self assert: (sorted at: 1) equals: (Association key: 94 value: $e).
self assert: (sorted at: 2) equals: (Association key: 65 value: $t).
self assert: (sorted at: 3) equals: (Association key: 62 value: $i).
Finding the Distinct Letters
The following test finds the distinct letters in the haiku, and it has to match the encounter order of the letters.
testDistinctLetters
|distinctLetters string|
distinctLetters := (((haiku select: #isAlphaNumeric) collect: #asLowercase)
asOrderedCollection)
removeDuplicates.
string := String streamContents:
[ :stream | distinctLetters do: [ :char | stream nextPut: char ]].
self assert: string equals: 'breakingthoupvmwcdflsy'.
Finding Duplicate and Unique Letters
The following test finds all of the letters that have duplicates and all the letters that are unique. There are no unique letters in the haiku.
testDuplicatesAndUnique
|chars duplicates unique|
chars := ((haiku select: #isAlphaNumeric) collect: #asLowercase) asBag.
duplicates := Bag new.
unique := Bag new.
chars doWithOccurrences: [ :each :occurrences | occurrences < 2
ifTrue: [unique add: each]
ifFalse:[duplicates add: each withOccurrences: occurrences]].
self assert: duplicates equals: chars.
self assertEmpty: unique.
Finding the Top Vowel and Consonant
The following test finds the top vowel and consonant in the haiku.
testTopVowelAndConsonant
|topOccurrences topVowel topConsonant|
topOccurrences := ((haiku select: #isAlphaNumeric) collect: #asLowercase)
asBag sortedCounts.
topVowel := (topOccurrences detect:
[ :pair | pair value isVowel]) value.
topConsonant := (topOccurrences detect:
[ :pair | pair value isVowel not]) value.
self assert: topVowel equals: $e.
self assert: topConsonant equals: $t.
Finding Wordle Words in the Haiku
The following test finds all of the words that can be used in the Wordle game. The words must be five characters long and not have any special characters.
testHaikuWordleWords
|words exclude wordleWords expected|
exclude := ',.-!?' asSet.
exclude add: Character cr;
add: Character tab.
words := (haiku reject: [:each | exclude includes: each])
substrings asOrderedCollection .
self assert: words size equals: 168.
wordleWords := (((words reject: [ :word | word includes: $' ])
select: [ :word | word size = 5 ])
collect: #asLowercase)
asSet.
expected := Set withAll: #('haiku' 'death' 'wrote' 'bacon' 'shine' 'house'
'where' 'thank' 'break' 'which' 'cocoa' 'drink' 'write' 'slide' 'found').
self assert: wordleWords equals: expected.
The Passing Tests
Here are the tests passing in the Smalltalk browser.

Passing Tests
Final Thoughts
While I missed some of the convenience of Eclipse Collections methods when implementing the tests in Smalltalk, most of the implementation code was straightforward to figure out. The one test that gave me a little challenge was finding the distinct letters. I missed having a simple method like makeString.
I left one test incomplete and failing. The haikuMeetsAnagrams test from the original kata. I will save this one for another day and update the blog once I finish it.

Leaving a failing test as a bookmark
The great thing about implementing a kata like this is that it forces you to think about testing up front. There’s no output, just assertions. I love writing tests.
If you want to try the Haiku kata using Java with Eclipse Collections or Java Stream, you can find the kata in the collection of Eclipse Collections Katas.
Thanks for reading!
I am the creator of and committer for the Eclipse Collections OSS project, which is managed at the Eclipse Foundation. Eclipse Collections is open for contributions. I am the author of the book, Eclipse Collections Categorically: Level up your programming game. If you want to learn the full API of Eclipse Collections, the book is the most comprehensive guide available.
메타데이터
- post_id
- a2a3279fbea2
- slug
- coding-the-haiku-kata-in-smalltalk-a2a3279fbea2
- url
- https://medium.com/@donraab/coding-the-haiku-kata-in-smalltalk-a2a3279fbea2
- canonical_url
- https://medium.com/@donraab/coding-the-haiku-kata-in-smalltalk-a2a3279fbea2
- author_url
- https://medium.com/@donraab
- status
- ok
- fetched_at
- 2026-07-09 21:48:21