Implementing Fizz Buzz In SPL – Shakespeare Programming Language

I recently participated in a coding challenge where the goal was to implement the Fizz Buzz problem, a simple programming task, but do this in some unusual way.

My first thought was that I should try to use an Esoteric Programming Language. Given that I didn’t actually know any esoteric languages (esolangs?) I needed to find one that I could learn well enough inĀ  the available time in order to implement Fizz Buzz.

After looking at and rejecting options like Malbolge, which was clearly an attempt to punish someone, Whitespace, a language that only uses space, tab, and linefeed characters, I found the Shakespeare Programming Language (or SPL).

SPL is described as, “A programming language created with the design goal to make the source code resemble Shakespeare plays.”

Boy Howdy, does it ever. Here’s an annotated example of my Fizz Buzz solution, where I print Floof, Bang, or Wham instead. Why, you ask. Those were the requirements.

 

First, we introduce the application name and define some variables. Here, you’ll see that I’m using the Perl module Lingua::Shakespeare, which made running this in windows pretty simple:

The first line is a Perl directive to treat this file as a Shakespeare program.

Following that, we have the name of the program, which starts with “A Play” and continues to the first period.

After the program name, we have the “Dramatis Personae” – the characters who participate in this “play”. Each line defines a variable with a name and an arbitrary description delimited by a comma, and ending with a period.

After this section, we enter the program flow. In Shakespeare programs, there are several concepts that need to be understood:

  1. The actors (variables) can only perform operations when they are “on the stage”
  2. Only two actors can be on the stage at the same time
  3. Program methods/functions appear as Acts and Scenes. The program starts with Act 1 Scene 1, and continues until all characters exit the stage.
  4. Branching can be done by having one actor say to another actor, “Let us proceed to Scene X”, where Scene X is the name of another Scene (aka, another method).
  5. If there is no branching, the Scenes flow linearly from one to another.

Continue reading “Implementing Fizz Buzz In SPL – Shakespeare Programming Language”