Code can be thought of as a form of language, and as is, it is possible to write poetry in Python, Perl or any programming language one can think of. This topic has been explored for the first time in 1962, and gains a form of popularity in the 1990s around the Perl programming language.
Code-poetry
Jabberwocky.pl is a noteworthy example of code-poem that makes use of the specificities of the medium of code. It is imagined in 2001 by Eric Andreychek, as a perl “port” of the famous poem by Lewis Carol.
#!/usr/bin/perl
$brillig and $toves{slithy};
for $gyre ( @wabe ) {} for $gimble ( @wabe ) {}
map { s/^.*$/mimsy/g } @borogoves
and $mome{raths} = outgrabe;
if(my $son = fork) { warn "Beware the Jabberwock!";
jaws && bite, claws && catch;
warn "Beware the Jubjub bird" and $shun,
$Bandersnatch{frumious} == 1; }else{
$_{hand} = \$sword{vorpal};
seek FOE, $manxome, (4_294_967_296 * time);
sleep ($tree{Tumtum} = $_);
while (study) { stand }
while (study($uffish)) { $_{stand} == 1; }
unless ($Jabberwock = fork) { $Jabberwock{eyes} = flame,
$Jabberwock{movement} = wiffle, $Jabberwock{location} = $wood{tulgey}
+;
while ($coming=1) { burble }}
(1, 2), (1, 2) and through and through;
$sword{vorpal}{blade} = snicker-snack;
(kill 9, $Jabberwock), $head = (chop $Jabberwock);
sub{ return $_, $head }; }
tell $son, "And hast thou slain the Jabberwock?".
"Come to my arms, my beamish boy! ".
"O frabjous day! Callooh! Callay! ",
$_{joy} = chortle if $son;
$brillig and $toves{slithy};
for $gyre ( @wabe ) {} for $gimble ( @wabe ) {}
map { s/^.*$/mimsy/g } @borogoves
and $mome{raths} = outgrabe;
The program creates three processes that represent the characters, and the kill
command kills the $Jabberwock
process.
Pall Thayer’s Microcodes are a wonderful collection of short poems in Perl. One of which I found to be particularily striking is simply titled “War”, published in 2014:
#!/usr/bin/perl
for($war = 0; $war < inf; $war++) {
kill;
}
In three lines, four if you insist, Thayer proposes a powerful statement about war, emphasizing the idea that the loss of lives is a continuous, ongoing and endless problem. Again, we encounter this idea of processes representing human lives, living in the machine.
AI generated code-poetry ?
With the recent release of the research preview of OpenAI’s ChatGPT, I decided to try and see if the language model could get the complexities of code poetry, since it seems to handle code reasonably well. I first introduced it to the idea of code poetry through Jabberwocky.pl and some other of Thayer’s microcodes. When it seemed like the model produced answers that seemed to indicate that it understood the topic well enough, I asked it to produce a code poem about the waste of life during a war, trying to see if it would come up with something similar to Thayer’s “War”.
Of course nothing is perfect, and it did not produce any ground shattering result. But after a lengthy back-and-forth, we arrived at this result:
#!/usr/bin/perl
@dead = ('innocent', 'brave', 'young');
% waste = ('blood', 'tears', 'dreams');
$ever = 1;
for ($ever) {
for $life (@dead) {
if (my $soul = fork) {
print "Another $life has fallen\n";
print "In the name of what? $waste{$life}\n";
print "What have we gained?\n";
print "We have wasted $waste{$life}\n\n";
kill 9, $soul;
}
}
}
sub peace {
print "But perhaps, one day\n";
print "We will find peace and harmony\n";
}
&peace;
For each paragraph, we have in the background a process that is killed, making use of the metaphor of processes as humans living in the computer space.
If run, the script produces the following output:
Another innocent has fallen
In the name of what? blood
What have we gained?
We have wasted blood
Another brave has fallen
In the name of what? tears
What have we gained?
We have wasted tears
Another young has fallen
In the name of what? dreams
What have we gained?
We have wasted dreams
(never reached because of the infinite loop)
But perhaps, one day
We will find peace and harmony
Or at least, it’s supposed to. Actually, when I tried to run it, it failed. Not being versed in perl myself, I couldn’t really figure it out, and ChatGPT was not of much help there.
I’ll let ChatGPT try to condense the main points of the poems in this quote, as it actually does a fairly decent job, after some directed questioning.
“The code-poem ‘war.pl’ is a creative and powerful use of code as a medium for expressing ideas and themes. The code uses the structure and features of the Perl programming language to create a poem that explores the waste and futility of war in a complex and nuanced way. The use of processes as metaphors, the
– ChatGPTkill
command, and the infinite loop add depth and meaning to the poem, and highlight the personal and human dimensions of the theme of the poem. The code and the output of the code form a complete and coherent poem that conveys the theme of the waste and futility of war in an effective and powerful way.”
I think it’s fair to say ChatGPT has its limitations, but, at the time of writing this article, I am certainly part of this collective enthusiasm around AI. I think the reason ChatGPT attracts so much attention and sparks a passionate debate, is that it looks like Artificial General Intelligence (AGI), a fantasy that has been ingrained our culture for decades. The public debate that has been sparked is a very good thing, allowing our societies to adapt to the emergence of new technologies which have the potential to change the way things are done.
I believe it important to note the important human part in the production of this code poem. If the AI did write every line of it, it was after a long process of trial and error, of discussion, to make the requirements clear. The AI assistant offers an uncannily useful dialogue partner, on which one can bounce ideas off of. It is imperative to make use of critical thinking when delegating thought to such a new, impressive and seemingly useful tool, especially when touching the complex and deeply human subjects of the arts, philosophy, or sociology. In this article, the case study provided is a very peculiar example of the use of such a tool, at the frontier between code generation and poetry.
AI agents are certainly going to become part of our lives in the very near future. One could argue they already are. For now, at least, they are tools we can use to allow us to delegate some tasks. As for any delegation, there must be supervision. AI and its many applications have the potential to change the way we produce not only code, but also our creativity. It can allow us to explore new things quicker. As Lev Manovich wrote, we should not so much be obsessing over the question ‘Can AI be creative?’, and really ask ourselves what we can do with it creatively.
Reply