Home For Fiction – Blog

for thinking people

There are no ads, nor any corporate masters
How to show support


July 18, 2020

A JavaScript Poem Shuffler

Programming

creativity, defamiliarization, javascript, meaning, poetry, programming

0 comments

As I’ve mentioned many times on the blog, meaning is a very fluid concept in literature. This fact inspired me to see what happens when we completely distort the author’s original intention, while still maintaining some minimal cohesion. This JavaScript poem shuffler was the result.

As the name perhaps implies, my JavaScript poem shuffler takes a poem and randomly reorganizes its lines.

Now, you might have two questions about this:

Amazingly, both these questions have the same answer, as we’ll see in more detail. Briefly, let me just say that this little coding exercise also provides us with excellent teaching material in terms of affective power and, indeed, the creation of meaning in literature.

JavaScript Poem Shuffler
Apparently chaotic patterns can still hold meaning – if they are predicated on affect. This JavaScript poem shuffler is a good example of this

A JavaScript Poem Shuffler: the Program

Before we talk about the meaning behind it all, let’s take a look at the heart of this JavaScript poem shuffler; how it works.

As a matter of fact, the program is incredibly simple. It simply takes the lines of the poem (arranged as an array), randomizes them, and prints them on the screen.

After you click on the button of the poem you want to randomize, you’ll first see how many permutations – possible ways to rearrange the lines of the text – there are. Scroll down to see the newly arranged poem. Clicking on the button again gives you a different random order.

Click to run the program

Note: The program is hosted on raw.githack. Since it’s a free service, 100% uptime cannot be guaranteed. If the program doesn’t appear above, please try later.

As you can see, the number of permutations is mindbogglingly high. “Darkness” has 10123 permutations. This is even higher than the Shannon Number, describing the conservative lower bound of the game-tree complexity of chess.

In other words, if you could arrange one million computers, all hitting refresh once per second (and if we assumed, for argument’s sake, they wouldn’t repeat the same result), they would need about ten billion years to display all the possible rearrangements of “The Destruction of Sennacherib”, the shortest of the three poems this JavaScript poem shuffler “ships with”.

But what’s that got to do with the two questions I referred to in the introduction?

From Chaos to Order: the True Meaning of Affect and Literature

Let me repeat the two questions, for our convenience.

First of all, let’s agree on something: if the (new) poem is not meaningless, then we should most definitely care – and we’ll see why.

So, is each new rearrangement of the poem meaningless?

I would argue that it is not. Each new iteration is meaningful.

The code shuffles on the line level, which means lines themselves are unaltered. It’s only their order that is randomized. Fair enough, Lord Byron’s intention was

The Assyrian came down like the wolf on the fold,
And his cohorts were gleaming in purple and gold;
And the sheen of their spears was like stars on the sea,
When the blue wave rolls nightly on deep Galilee.

But we can see meaning in something like

The Assyrian came down like the wolf on the fold,
When the blue wave rolls nightly on deep Galilee.
And there lay the rider distorted and pale,
And there lay the steed with his nostril all wide

Rhyme, Meter, Affect

In my post on translating poetry, I mentioned how my “priority checklist” in translating poems involves, in order of importance: rhyme, meter, affect, meaning – “meaning” referring to the literal, word-by-word meaning; what the narrative talks about.

For our purposes here, let’s forget about this literal meaning. We are not translating, after all. Rather, we seek to see if we have a different affect and therefore a different impactive meaning – not what the narrative talks about, but what the narrative feels like.

And so, in each new rearrangement, meter has remained the same because lines themselves are unaffected. Rhyme is distorted – though some random rhymes can still appear. Take a look at this magnificent example the program returned:

The Assyrian came down like the wolf on the fold,
And the widows of Ashur are loud in their wail,
And his cohorts were gleaming in purple and gold;
And there lay the rider distorted and pale,
With the dew on his brow, and the rust on his mail:

What about affect and what I coined as impactive meaning?

Again, I would argue that each new iteration brings a new instance of affect; a new kind of reaction – perhaps even more accentuated than the original, precisely because the literal meaning is no longer as obvious.

In other words, lacking its original linearity, each new iteration “forces” us to discover – or rather create meaning, inspired by this new instance of affect.

A poem – certainly not as stable, clear-cut a narrative as prose – becomes even more destabilized in this process. Effectively, this JavaScript poem shuffler is a defamiliarization program!

home for fiction

Next Steps for this JavaScript Poem Shuffler

In the end, this isn’t anything too special as a program. It’s perhaps a fancier, more complex version of my Shakespearean sonnet mixer. It’s certainly not anything remotely connected to AI writing.

But its power lies in what it tells us about literature, affect, and meaning. As I often say, plot is unimportant; affect is everything.

I also entertained the idea of making the program interactive. That is, allowing the user to upload their own poem and see different combinations. Conceivably, this would allow some interesting ideas related to imagination and creativity to emerge. Perhaps I’ll implement this in some future version. Update: You can now find such an interactive version following this link. For a full list of my available programs, see the relevant page on the main site.

Another idea for this JavaScript poem shuffler would be a way to save the results – that is, one easier than copy/pasting/saving.

Looking for the code? You can find it on the relevant page on my GitHub.

How about another version of this program, made by ChatGPT?

And if you want to read the original poems – all by Lord Byron – there you go:

Parenthetically, I’ve talked about “The Destruction of Sennacherib” in my post on the future of poetry. I’ve also written a post offering an analysis of “Prometheus”.

Punning Walrus shrugging

Comments are closed for posts older than 90 days