I have recently discovered what is code poetry on this blog presenting the new book ./code --poetry by Daniel Holden and Chris Kerr.
Code poetry is built on a simple premise: it is a single text that reads as poetry and executes as code.
The book uses many languages but I don’t know if Fortran is included as I did not find the table of contents of the book. So I tried to play with this concept as I think it can be interesting to explore the particularities of Fortran in this context.
With this first attempt I have obtained an executable program that can be read as a text, although it is not totally satisfying as it prints nothing really pretty or poetic… But I am sure people here could improve it or write a more interesting one!
! O Fortranner,
program with_your_mind
!, so
logical :: a = .true. !computer!
such_a_task: do it = 1, 1000000000 ; fast = &
cos(real(it)) !is
if (a) print *, "occurs in ", it
end do such_a_task !again without torment
end program with_your_mind !with eternal delight, Fortranner!
A few remarks:
- One advantage of Fortran is that indentation is free, like in modern poetry. It can be useful to ease the text reading, or to sculpt it with a specific geometrical shape.
- I must admit it is the first time in my career I use implicit typing in Fortran and it is really useful for code poetry (no bashing please !). Here I included
logical
in my text, but I was happy to avoid declaringit
andfast
. - I used some phonetic tricks:
cos
must be pronounced 'cause andend
must be pronounced and. This last one is very useful in Fortran as all blocks of instructions are terminated with anend something
: you can use it to obtain a kind of refrain. Labels can also help for this. - Comments are of course very useful for words outside of Fortran vocabulary.
- With
;
and&
you can manage line feed more freely. - And probably the fact that there is no reserved word in Fortran can help.
Of course, torturing Shakespeare’s language (sorry…) is easier but probably it is also possible to write something in European languages sharing roots with English. For example in English the verb:
!to
program
would become in Molière’s language (don’t read the space):
program mer
In other languages, it may be much harder but maybe not impossible in some of them (and implicit typing could save the situation… ). After all, constraints are known to stimulate creativity. In classical poetry, we have for example rhymes, forms, metrics…
Don’t hesitate to hack the vocabulary of your favorite poets or singers, whether it’s William Blake or Jim Morrison, if it helps opening the do.or.s
of perception. I think it can be interesting to explore in this post the features of Fortran that could be useful in code poetry. And it would be great to obtain some truly poetic programs writing or drawing something poetic or artistic in the terminal, and maybe using an artistic typography.