CherryBlossom
I don’t know what it is about haikus that makes them so neat. Maybe it’s because they’re made up of prime numbers (3 lines, 5 syllables, 7 syllables, 5 syllables, a total of 17 syllables), or maybe it’s because you have so much beauty, artistry and emotion neatly packaged in just three lines. Either way, I think they are pretty neat.
I think I first got the idea to write a language based on haikus around two weeks ago when I was reading about esoteric languages. I was going over the Shakespeare Programming Language (SPL) (which I first heard about from a slashdot post a few years ago) when I started thinking about variations on the same theme (that is, prose or poetry as program code). I then thought "What if a haiku could also be program code?". Thus, the idea of CherryBlossom was conceived. Initially, I was stumped as to how I could transform a haiku into program code. The structure of a haiku is rather rigid, and I couldn’t think of an easy way to make a language (with variables, functions, and flow-control) because of that rigidity. In comparison, SPL is much more free-flowing since it’s prose. In haiku, you are limited to the number of syllables and lines. Then I thought, "What if the language was minimalistic?". In that case, all I need to do is figure out a way to map words to a small instruction set! When talking about languages with small (although not too small) instruction sets, there is no better candidate than Brainfuck, which is a Turing-Complete language with only eight instructions. With that in mind, I finally had an idea about CherryBlossom's implementation.
Like I mentioned before, the idea behind CherryBlossom is pretty simple. Brainfuck instructions are mapped to words that convey the meaning or essence of the Brainfuck instruction. For example, the > instruction, which moves the pointer forward conveys an essence of moving forward, or up. Hence it makes sense to map it to words that convey a similar meaning. With that idea, I came up with the following mappings:
| Instruction | Mapped Words |
|---|---|
> (move pointer forward) |
above, ahead, atmosphere, bird, birds, flew, flies, flight, float, floated, floating, floats, fly, flew, flying, forward, front, heaven, heavenly, height, high, higher, hill, hillside, hilltop, mountain, mountainside, mountaintop, push, pushed, pushes, pushing, rise, rises, rising, sky, top, up, upward, upwards (words that convey a sense of forward or upward motion, flying, or height) |
< (move pointer backward) |
back, backward, backwards, behind, below, dip, down, downwards, earth, fall, falling, falls, fell, ground, grounded, land, landed, landing, lands, low, lower, lowered, lowering, lowers, pull, rain, rained, rainfall, raining, rains, reverse, sink, sinking, sinks, snake, snow, snowed, snowfall, snowing, snows, valley, waterfall (words that convey a sense of backward or downard motion, falling, or depth) |
+ (increment value at current memory location) |
alive, add, added, adding, adds, beautified, beautifies, beautiful, beautify, beautifying, beauty, butterfly, butterflies, big, bigger, bloom, bloomed, blooming, blooms, blossom, blossoming, blossoms, caress, caressed, caresses, caressing, cherry-blossom, cherry-blossoms, dawn, day, daybreak, days, dove, doves, dream, dreaming, dreams, dreamy, fat, fattening, fatty, field, fields, fire, flower, flowered, flowering, flowers, fragrance, fragrant, gain, gained, gains, get, gets, getting, good, grew, grow, growing, grows, had, happiness, happy, have, having, heal, healed, healing, heals, heat, heated, heats, hot, jasmine, learn, learning, learns, life, live, love, loved, lovely, loves, loving, lush, many, money, more, morning, new, own, owned, owning, owns, pleased, pleasing, pleasure, positive, pretty, rainbow, rainbows, remember, remembered, remembering, remembers, rose, roses, rosy, smile, smiled, smiles, smiling, spring, steam, steamed, steams, steamy, summer, sun, sunlight, sunlit, sunray, sunrays, sunshine, sweet, sweeten, sweetened, sweeter, sweetly, sweets, warm, warmth, wealth (words that convey a sense of gaining, beauty, increasing, or anything positive) |
- (decrement value at current memory location) |
alone, autumn, anger, angry, bad, barren, break, broke, broken, cold, cool, chill, chilled, chills, chilly, cried, cry, crying, dark, darkening, darker, dead, death, desolate, desolation, depressed, depressing, desert, deserts, die, dies, dusk, dying, evening, evil, fear, fearful, few, fog, fogged, foggy, forget, forgetful, forgetting, forgot, forgotten, forsake, forsaken, freeze, freezing, freezes, froze, frozen, fright, frighten, frightened, frightening, gloom, gloomy, greed, greedy, ice, icy, less, lessen, lessened, lone, lonely, lonesome, lose, losing, loss, lost, melancholy, miss, missed, misses, missing, mist, mistake, mistaken, misted, mists, misty, moon, moonlight, moonlit, moonshine, nothing, night, nightfall, nightmare, old, pain, painful, poor, poverty, rage, remove, removes, removing, sad, sadness, scream, screamed, screams, screaming, shrank, shrink, shrinking, shrinks, shrunk, small, smaller, sorrow, sorrowful, tear, tearful, teary, thin, thins, thinned, thinning, ugliness, ugly, winter, wither, withering, withers, wound, wounded, wounds (words that convey a sense of loss, sadness, decreasing, or anything negative) |
[ (jump forward past the matching ] if the value at the pointer is zero) |
if, why, when, where, how, who, what, inspect, puzzle, question, mull, riddle, decide, branch, branched, branches, branching, mulled, mulling, mulls, decides, deciding, decided, contemplate, contemplating, contemplation, contemplated, contemplates, think, thinking, thought, thinks, choose, chose, choosing, chooses, wonder, wondered, wondering, wonders (words that convey a sense of introspection or conditionality) |
] (jump backward to the matching [ unless the value at the pointer is zero) |
return, home, reunite, returns, returned, returning, reunited, reunites, reuinting, acknowledge, acknowledges, acknowledged, acknowledging, acknowledgement, homecoming, retreat, retreating, retreats, retreated, restore, restoring, restored, restores, revisit, revisited, revisiting, revisits, rebound, rebounded, rebounding, rebounds, boomerang (words that convey a sense of returning) |
. (print the ASCII character represented by the value at the pointer) |
answer, answered, answering, answers, art, artist, author, birdsong, book, brook, creek, display, displaying, displays, flow, flowing, flows, gave, give, giving, laugh, laughed, laughing, laughs, laughter, letter, melodious, melody, music, paint, painter, painting, paints, picture, poem, poet, present, respond, result, river, riverside, said, say, saying, says, show, showed, showing, shows, sang, sight, sing, singer, singing, sings, speak, speaker, speaking, speaks, spoke, stream, view, views, window, word, words, write, writer, writes, writing, wrote (words that convey a sense of speaking or saying) |
, (input a value and store the ASCII character of that value at the pointer) |
absorb, absorbed, absorbing, absorbs, accepted, accepting, accepts, annex, annexed, annexes, annexing, ask, asked, asking, asks, attract, attracted, attracting, attracts, conquer, conquered, conquering, conquers, ditch, fill, filled, filling, fills, hear, hearing, hears, hole, in, indoor, indoors, inside, knew, know, knowing, knowledge, knows, learn, learned, learning, learns, lesson, lessons, question, questioned, questioning, questions, read, reader, reading, reads, receive, received, receives, receiving, suck, sucked, sucking, sucks, taken, takes, taking, taught, teach, teacher, teaching, took, vortex, whirlpool (words that convey a sense of questioning, learning or taking something in) |
NOP (instructions that don’t do anything) |
about, all, and, am, an, at, a, any, are, because, be, by, came, can, come, could, did, do, does, every, everything, for, from, go, he, her, hers, here, him, his, in, i, is, it, man, me, mine, my, no, now, of, one, on, or, our, ours, she, should, some, such, that, them, then, the, their, theirs, there, they, this, to, to, us, was, went, were, will, with, woman, would, yes, you, your, yours (these are words that I added so that it would be easier to write haikus, since it’s hard to construct sentences or phrases without these words) |
Yes, the list is entirely subjective. But that’s what poetry is! So how do you actually write programs in CherryBlossom? Well, it’s pretty simple. Imagine that you’re writing in brainfuck, but instead, use words that map to the brainfuck instruction that you want to use. However, you have to make sure that you are conforming to the rules of haiku. What this also means is that the smallest CherryBlossom program will be three lines long. It also follows that in every CherryBlossom program, the number of lines will always be a multiple of three. Now let’s look at some actual code! First, we have the obligatory "Hello World!" program. Let’s look at the brainfuck version:
+++ +++ +++ +
[
> +++ +++ +
> +++ +++ +++ +
> +++
> +
<<< < -
]
>++ .
>+.
+++ +++ +.
.
+++ .
>++ .
<<+ +++ +++ +++ +++ ++.
>.
+++ .
--- --- .
--- --- --.
>+.
And now, the prettier CherryBlossom version:
beautiful jasmine
your lovely fragrance heals me
every morning
remembering you,
dreaming of your lovely smile,
when will you come here?
floating butterflies
sunshine and summer flowers
a lovely morning
blossoming hillside
on a fragrant summer day
blooming, flowering.
I can remember
my happy dreams of summer
it was beautiful
flying doves, sunrays
beauty flying in sunshine
rain in the valley.
snow falls in moonlight,
returns to the mountainside.
lovely, beautiful.
view from mountaintop
is a beautiful painting,
in summer sunshine.
the fragrant flowers
and the pretty butterflies
spring by singing creek.
beautiful morning
butterflies by riverside
floating in sunshine.
such a lovely sight,
the valley waterfall is
in the spring sunshine.
sunrays and sunshine,
the butterflies and flowers
loving the new spring.
the pretty flowers
are dreaming of a summer
with the smiling sun.
music from heaven,
is melodious and sweet,
dreamy and happy.
the river is cold
and misty in the moonlight,
in the autumn chill.
winter riverside,
lonely, icy, and chilly
darkening evening
the lonely winter,
barren riverside ahead
a dreaming poet
Here is another listing of the same code. This time I’ve highlighted the words that map to brainfuck instructions. See if you can figure out how they map :) It’s pretty easy:
beautiful jasmineyour
lovely fragrance heals meevery
morningremembering you,dreaming of your lovely smile,when will you come here?floating butterfliessunshine and summer flowersa
lovely morningblossoming hillsideon a
fragrant summer dayblooming flowering.i can
remembermy
happy dreams of summerit was
beautifulflying doves, sunraysbeauty flying in sunshinerain in the valley.snow falls in moonlight,returns to the mountainside.lovely, beautiful.view from mountaintopis a
beautiful painting,in
summer sunshine.the
fragrant flowersand the
pretty butterfliesspring by singing creek.beautiful morningbutterflies by riversidefloating in sunshine.such a
lovely sight,the
valley waterfall isin the
spring sunshine.sunrays and sunshine,the
butterflies and flowersloving the new spring.the
pretty flowersare
dreaming of a summerwith the
smiling sun.music from heaven,is
melodious and sweet,dreamy and happy.the
river is coldand
misty in the moonlight,in the
autumn chill.winter riverside,lonely, icy, and chillydarkening eveningthe
lonely winter,barren riverside aheada
dreaming poet
Color key:
increment (+)
decrement (-)
forward (>)
backward (<)
loop ([ ])
output (.)
As far as the interpreter is concerned, it has two modes: strict and non-strict. In strict mode, the interpreter only recognizes the standard list of words (the words I listed earlier) and will halt if it encounters any unrecognized words. In non-strict mode, it will accept words that are not part of the standard list. There is a slight drawback here, however. I use the Lingua:EN::Syllable perl module to count syllables. It is accurate about 85% percent of the time. For words where the number of syllables aren’t correct, I had to maintain an "exceptions" list. A way to get around this would be to use a more robust syllable-detection algorithm.
Writing code in CherryBlossom is not easy and it isn’t meant to be! I have long felt that programming is more than a mere engineering effort; it is a creative and artistic effort as well. CherryBlossom combines the programmer and poet (into a poegrammer? progroet? I digress…) into one single entity that produces haikus that are not just creative and aesthetically-pleasing objects, but functional as well! Haikus and code go well together. Good code must have no distractions and must get to the heart of the matter. At the end of execution there must be closure. Similarly, a good haiku also has no distraction and does not stray from its subject matter. When one reads such a haiku one has a sense of peace and closure and feels that all is right in the world. Indeed, the uniting of program code and haiku is quite zen and the programmer/poet must be united with the problem that he or she is trying to solve.*
Here is another example for you to meditate and contemplate over:
hear the birdscaressed by warmth of the sundreaming of summerdreaming that I amcontemplating in rainfallabout all my
lossfreezing, desolate.lonely desert in winterall is
forgottenautumn is aheadthe
winter is returning.and it
conquers all.how can the rainfallso
beautify the hillsidethat was so
barrenreturning rainfallsings as it falls to the earthand all is
alive
Here’s a link to the interpreter. It’s written in perl and requires the Lingua::EN::Syllable module.
*Yes, this is all tongue-in-cheek!