\$\begingroup\$

The Infamous Shakespeare Programming Language

Shakespeare Programming Language was created in 2001 by two Swedish students, Karl Hasselström and Jon Åslund, and it combines, as the authors proclaim,

the expressiveness of BASIC with the user-friendliness of assembly language.

Answers go from top to bottom. Also, it's common to see me refer to older or previous snippets.

(link for myself: edit)

Factoid:

Shakespeare's code resembles, as one would expect, a Shakespeare play, where the variables are characters on the play and their value changes as they are "insulted" or praised".

Length 1 snippet:

I

Shakespeare's code is divided in Acts, and the acts are themselves divided in Scenes, for "jump-to" causalities. Defining an Act as Act I means that it will be the first piece of the code to be run, per example - but not only.

Length 2 snippet:

as

Used in a comparative between two "characters".

Length 3 snippet:

day

By now, you may be getting the feeling that SPL is very verbose. And weird. And you've seen nothing yet. day , in SPL, is 1. All "positive" and "neutral" nouns are considered as 1 , as well as all "negative" ones are -1 .

Length 4 snippet:

rich

What is rich ? An adjective. In SPL, adjectives make the value of the noun they're attached to multiply by two. See implementation on snippet 14.

Length 5 snippet:

Act I

Implementation of the first snippet. All acts may be given a title, such as Act I: Hamlet must die! , since everything after the Roman numeral is ignored by the parser.

Length 6 snippet:

better

Every language has conditions, and SPL is no exception. Except, since this is a language with a lengthy syntax (and did I mentioned it to be weird?), its conditional statements are going to be long. Having Ophelia ask Juliet Am I better than you? is like having if (Ophelia > Juliet) on most "normal" languages. And, of course, you can ask the other way around: Am I not better than you? is the equivalent of if (Ophelia < Juliet) . And you can already guess how the = is translated to SPL: as good as - usage of code snippet 2.

However, good/better is not the only way to make comparisons in this shakesperian language, you can use any adjective. The same principle of snippet 3 applies here as well, with "positive" adjectives having the value > , while "negative" ones mean < .

Length 7 snippet:

Juliet:

This is the invocation of a variable; after this, his/her instructions/declarations/whatever will follow.

A limitation of SPL is that it has a limited number of variables: Romeo, Juliet, Hamlet, Ophelia, MacBeth and so on are a few examples of "characters" that will appear on a Shakesperian program.

Length 8 snippet:

[Exeunt]

[Exeunt] is placed when all "characters" leave the "stage". Hopefully I can elaborate a bit more later on about the interaction between characters. Generally is the last instruction of any SPL program, although [Exeunt] isn't specifically the terminal "character" of the language. For another example, see snippet 27.

Length 9 snippet:

as bad as

Nine characters just to represent a mere = - using snippet 2. Have I mentioned that SPL is weird? See snippet 30 for examples. (and yes, there's more than one way to output it)

Length 10 snippet:

difference

A fancy way of representing - , a subtraction. You can have math operations on SPL, even though you'll probably need a full day to get it right.

Factoid (since I managed somehow to reach ten snippets of code, let's take a bit of a break and have another factoid about SPL)

If you want to run your shakesperian code in all its glory, there's this site - I'm still testing it, since I discovered it not even five minutes ago. There's also a way to translate it to C using a translator.

Another site for running SPL code is this one that works by internally translating the SPL code to another esoteric language: Oracle PL/SQL.

Length 11 snippet:

[Exit Romeo]

Yes! At last I can talk about the interaction between characters! In order to have its value changed or to interact with others, a "character" must be on stage - entering with [Enter Romeo] . If a character is addressed to but is not present, there's a runtime error and the program stops. Because, in SPL, the value of the variables is set by the amount of names they're praised with - or insulted with - by the other characters on stage. I feel that I should put an example to clear some confusion my lame explanation may create, but perhaps it's best to delay that a few snippets.

Length 12 snippet:

Remember me.

SPL is pretty "basic", alright - but it has stacks! When, per instance, Romeo tells Juliet to "remember him", he's actually telling his loved one to push the Romeo's value into her stack. Popping the value is done with Recall your happy childhood! , or Recall your love for me , or basically any sentence that begins with Recall - the rest is just artistic drivel, like snippet 22.

Length 13 snippet

Let us return

The Shakesperian way of having a goto . And this is where the Acts and Scenes come in handy. If Romeo tells Juliet we shall return to Act II (yes, again, there are multiple ways of write it), the program will jump to that specific part of the code. It's also seen alongside conditional statements.

Length 14 snippet

my little pony

Yes, it was a series back in the 80s. Here, it's 2*1 . Why? Because a pony is a (somewhat) positive noun and little is an adjective. So, remembering snippets 3 and 4, we have little = "2 *" and pony = "1" .

Length 15 snippet

Speak thy mind!

In a SPL program, you'll see this (or Speak your mind! , which is the same) a lot. This basically outputs the value of each "character" in digit, letter or anything else, depending on the character set being used by your computer. There's also Open your mind. that does almost the same thing, albeit only outputting in numeric form.

Length 16 snippet

You are nothing!

When someone tells you this in real life, you'll feel depressed. When Ophelia tells this to Hamlet in Shakespearian programming, Hamlet feels worthless. What does this mean? That Hamlet = 0 .

Length 17 snippet

Ophelia, a wench.

In a screenplay, before the actual play starts, the characters must be presented. In most programming languages, the variables must also be declared before use. Seeing that SPL is a programming language that resembles a screenplay, this is how you declare its variables, by stating which are the ones appearing during the program.

But what does "a wench" mean? Does it mean that it's a specific (and cool) data type name? Well... I hate to disappoint you, but it means nothing: everything after the comma is disregarded by the parser, meaning you can put there the most outrageous drivel you can think of.

Length 18 snippet

lying sorry coward

-4 for all earthly creatures. Why? Because 2*2*(-1) = -4 .

Length 19 snippet

Romeo: Remember me.

At last!!! I can finally output a full correct syntax instruction (albeit a short one)! This is how you use snippet 12: firstly you declare who's talking, then on the next line you write the "dialogue". Normally, only two "characters" are on stage, to avoid making the parser sad and confused. When you need another "character", you take one from the stage and replace him by the new one.

Length 20 snippet

cube of thy codpiece

I wanted to elaborate a bit more for this one, but, truth be told, the things I come up with are still too short for this snippet length. And, so, I bring you this, which ends up being -1 - because (-1)3 = -1 (and codpiece is a "negative" noun, since they're uncomfortable and all). SPL understands a few more elaborate arithmetic operations as some exponentiation and square roots.

Factoid (yet another one, since we've reached another milestone)

The "Hello World Program" in Shakesperian has 89 lines and more than 2400 characters long, as seen here.

Length 21 snippet

Listen to your heart.

In snippet 15 you outputted something; here, you input a number to the program. If you want to input a character, you'll use Open your mind. instead. And, needless to say, this value will be stored in the "character" being spoken to.

Length 22 snippet

Recall your childhood!

Popping an integer from a stack is done with this, as explained on snippet 12. When, per instance, Ophelia tells Hamlet the aforementioned sentence, it causes Hamlet to take an integer from his stack and assume that value.

Of course that, as long as the word recall is starting the sentence, you can fill in the rest with pretty much anything your creative shakesperian mind desires.

Length 23 snippet

Are you better than me?

Implementation of snippet 6. When a "character" makes a question like this to another, what he/she is doing is equivalent to if (x > y) on more common programming languages. The follow-up of this instruction must be delayed until I have more characters available.

Length 24 snippet

[Enter Romeo and Juliet]

Yes, "characters" may enter in pairs. It's not required to have one "character" entering the stage, being followed by another.

Length 25 snippet

remainder of the quotient

25 characters just to write a % . 25 characters to have the remainder of a division. And to use it? Well, that's even bigger - see snippet 75.

Length 26 snippet

Let us return to scene II.

Here it is, a goto in SPL, which works as one would expect in a programming language. A thing is: you can jump between scenes in the same act, and between acts; but you cannot jump between scenes in different acts.

Length 27 snippet

[Exeunt Ophelia and Hamlet]

When more than one "character" leave the stage, instead of Exit , and keeping in tradition with SPL's theatrical nature, the latin word "Exeunt" is used. Sometimes it can be replaced just by snippet 8.

Length 28 snippet

Scene I: Ophelia's flattery.

Declaring a Scene. As you can already expect if you've been coping with me, the important bit is the Scene I , the rest is artistic fluff.

There have been some compilers made (like this one that compiles from SPL to C, written in Python) that instead refer to the text after the numbering of the Act/Scene. While more logical (after all, during a play, having the characters saying lines such as "let us return to Act I" may be deemed silly), I'm sticking to the original way.

Length 29 snippet

You pretty little warm thing!

Yes, yet another constant (since we need way more characters to have arithmetic operations). This one is equal to 8 , because 2*2*2*1 = 8 .

Length 30 snippet

You are as cowardly as Hamlet!

Saying this to, per instance, Romeo, means that Romeo = Hamlet . Like snippet 9.

Factoid (yes, another landmark reached!)

This language was created for an assignment in a Syntax Analysis course - thus, no SPL compiler was created by the authors. More: it seems SPL's authors have severed their ties with their creation, since nothing appears to have been modified in the language since 2001...

Length 31 snippet

Am I as horrid as a flirt-gill?

Yes, I know, it's somewhat repeating snippet 23, although, here, we're comparing the "character" who speaks with a "flirt-gill" (of, if you prefer, if (Ophelia == -1) ). The thing is...

Length 32 snippet

If so, let us return to scene I.

... now I can introduce the then of SPL, and the conditional jump-to, and the Shakesperian way of implementing loops. You can, per instance, make Romeo assume the value 0 , increment his value while doing some other task and stop when he reaches 10, proceeding with the program afterwards.

Length 33 snippet

If not, let us return to scene I.

Just a reminder that, instead, we can instead proceed forward to another scene if the condition we tested for is false.

Length 34 snippet

Open your mind! Remember yourself.

Two instructions in a row, yippie! The first one reads a character, the second one pushes it into the other character's memory stack.

Length 35 snippet

Act I: Death! Scene I: Oh, shit.

The proper way of declaring an Act and a Scene. Add artistic mush tastefully.

Length 36 snippet

Thou art as sweet as a summer's day!

Another way of saying that the "character" being spoken to will receive the value 1 - because summer's days are nice and pleasant.

Length 37 snippet

Art thou more cunning than the Ghost?

Ophelia asking this question to Hamlet means, translating this to a less readable programming language, if (Hamlet > the Ghost) . It's snippet 23 all over again, yeah - but it goes to show you that it's not required to ask the "characters" if they are better than each other: any other question will work too.

Length 38 snippet

[Enter the Ghost, Romeo and the Ghost]

Yes, I'm calling a "character" twice - because I wanted to have the program give me an error. Calling a "character" that's already on stage, or telling one that's absent to exit, will cause great grief to the parser/compiler.

Length 39 snippet

the sum of a fat lazy pig and yourself!

The full instruction is more better looking that this, I'll give you that, but... here's our first arithmetic operation! What does it all mean, actually? Well, pig is a dirty animal (albeit tasty), so it's equivalent to -1 , has two adjectives, meaning fat lazy pig equals 2*2*(-1) = -4 . But what about yourself ? It's a reflexive pronoum, not a name nor an adjective. Well, remember that SPL is based on dialogues between "characters"; thus, yourself refers to the other "character" on stage. So, we arrive at the end and we discover that "the sum of a fat lazy pig and yourself" is, in fact, -4 + x .

Length 40 snippet

the sum of a squirrel and a white horse.

Yes, another sum, but this one is simpler than snippet 39. This is merely 1 + 2 - 3 , if my math is correct.

Factoid (still with me after these forty snippets of artistic fluff? You deserve a prize.)

SPL, in its version 1.2.1, can be downloaded here.

Length 41 snippet

Juliet: Speak thy mind! [Exit Romeo]

Sometimes, "characters" are only called on stage to have their value changed - which, on a real play, would be something quite bizarre. Anyway, here, Juliet makes her beloved Romeo print his stored value, after which he exits the stage.

Length 42 snippet

Speak YOUR mind! You are as bad as Hamlet!

Again two instructions in one line (we can have multiple, but the snippet length doesn't allow it yet); here we have a "character" telling another to output its value and assume whichever value Hamlet has. Confusing? Mayhap.

Length 43 snippet

Am I as horrid as a half-witted flirt-gill?

Juliet asking this doesn't mean she has low-esteem (although it might in real-life); it's simply another if , like snippets 23 and 37. Oh, I almost forgot: this translates to if (Juliet == -2) .

Length 44 snippet

You are as evil as the square root of Romeo!

Yes, square roots are evil, didn't you know? Anyway, this instruction is straightforward enough to understand what it does: attributes the "character" being spoken to the value of the square root of the value stored in Romeo.

Length 45 snippet

Hamlet: Art thou more cunning than the Ghost?

Snippet 37 properly written with the character who's speaking the line.

Length 46 snippet

the product of a rural town and my rich purse.

Okay... anyway, SPL may be the only language in the world that allows you to multiply towns with purses. This means (2*1)*(2*1) which, if I'm not very mistaken, is equal to 4 .

Length 47 snippet

Romeo: Speak your mind. Juliet: Speak YOUR mind!

I'll give you that: it may be one of the most bizarre dialogues in history. But it's what you get when you choose a weird language to showcase. Romeo and Juliet are telling each other, in short, to output their values.

Length 48 snippet

You lying fatherless useless half-witted coward!

Translating it directly, 2*2*2*2*(-1) . -16 , right?

Length 49 snippet

Scene V: Closure. Hamlet: Speak your mind! [Exeunt]

An example of how to terminate a program in SPL. You can declare a scene specifically for it (although it's not required), then Hamlet asks another "character" to output their value, then they all exit the stage. And yes, it's required for all of them to get off the stage.

Length 50 snippet

Othello, a young squire. Lady Macbeth, an old fart.

More "character" presentation, before the proper instructions. As always, the only thing that matters to the compiler is Othello and Lady Macbeth , so the rest of the line is up for grabs...

One more thing: the "characters" don't have to be related to each other in order to appear in a SPL program - so you can have Romeo, Othello and Hamlet on the same play.

Factoid (half-a-century of these things? Phew! After this I think I'm going to loathe William Shakespeare...)

The SPL to C translator, mentioned a while ago and developed by the SPL creators, was based on Flex and Bison.

Length 51 snippet

Othello: Recall your great dreams. Speak your mind!

(So sick of Romeo, Juliet and Hamlet... let's bring in Othello, for a change!)

Recall , as you can guess, is the key here. The "character" Othello is addressing will take a value from his/her stack, assume that value and, afterwards, will output it.

Length 52 snippet

Thou art as pretty as the sum of thyself and my dog!

Another sum. Yawn. Assuming this one is addressed to Hamlet, means that Hamlet = Hamlet + 1 . Or Hamlet += 1 . Or Hamlet++ .

Length 53 snippet

Romeo: You are as vile as the sum of me and yourself!

Ah, yes, something I forgot to mention before: the speaking "characters" can mention themselves on their own lines.

Length 54 snippet

Juliet: Is the sum of Romeo and me as good as nothing?

Another example of the previous snippet, included in a condition. So what we have here is if (Romeo + Juliet == 0) .

Length 55 snippet

Juliet: You are as lovely as the sweetest reddest rose.

So, here, Juliet is praising the "character" she's speaking to (let's assume it's Romeo, for Shakespeare's sake), declaring that he/she is 4. Yes, another assignation of values.

Length 56 snippet

Othello: You lying fatherless useless half-witted coward!

Snippet 48 properly done, with a "character". If you're too lazy to scroll up (like I'd be), this means the one being insulted is receiving the value -16.

Length 57 snippet

Romeo: If not, let us return to Act I. Recall thy riches!

I've already explained how conditions work on SPL on a general basis; however, a more inline analysis is needed. We don't have else in here: per instance, in this example, if the condition failed, the program would return to Act I; but if it were true, it would continue to the next instruction, which is a Recall - a pop from the stack, that is.

Length 58 snippet

Romeo: You are as disgusting as the square root of Juliet!

Grabbing snippet 44 and presenting how the instruction should be presented. If this was a dialogue between Romeo and Othello, then we could translate this to Java as Othello = Math.sqrt(Juliet) .

Length 59 snippet

Othello: You are as vile as the sum of yourself and a toad!

OK, if Othello is talking to Romeo, this would be equivalent to Romeo+(-1) ; Romeo-- , for short. Pretty basic, right? That's SPL for you.

Length 60 snippet

Is the quotient between the Ghost and me as good as nothing?

For short, if (The Ghost/Hamlet == 0) , assuming the "me" belongs to Hamlet.

Length 61 snippet

Thou art as handsome as the sum of yourself and my chihuahua!

Once you peel away the layers and layers of words and insults, you notice that SPL is pretty much a basic thing, without cool functions and stuff. So we have loads and loads of arithmetic functions on the program's body. So, if this one was addressed to Juliet, it would be equivalent to Juliet++ .

Length 62 snippet

twice the difference between a mistletoe and a oozing blister!

Yes, yes, more arithmetic operations. Roughly, these 62 bytes of SPL can be translated to 2*(1-2*(-1)) . This would be a pretty awesome golfing language, right? Right.

Length 63 snippet

You lying stupid fatherless rotten stinking half-witted coward!

Snippet 48 outputted -16, this one is equal to -64: 2*2*2*2*2*2*(-1) .

Length 64 snippet

your coward sorry little stuffed misused dusty oozing rotten sky

From what I understand of SPL, this is perfectly legit. You have a whole lot of insulting adjectives what proceed a "positive" noun. Since adjectives have no special distinction whether they're negative or not (their only value is multiplying the number at their right by two), we can have completely silly sentences like this one. Which is equivalent to 256. Because 2*2*2*2*2*2*2*2*1=256 .

Length 65 snippet

You are nothing! You are as vile as the sum of thyself and a pig.

Hmm, so much hate, isn't it? So, what we have here is equivalent to y=0; y=y+(-1); Probably could have been "golfed" to You are a pig! , but heh.

Length 66 snippet

You are as beautiful as the difference between Juliet and thyself.

So, subtract Juliet from yourself, heh? This one's pretty simple to decode: Romeo=Juliet-Romeo; , assuming it's Romeo who's being spoken to.

Length 67 snippet

Juliet: Am I better than you? Romeo: If so, let us proceed to Act V.

How most conditions work on SPL. You test the expression and, if it's true (or not: see snippet 33), you jump to another part of the program; otherwise, you'll continue on to the next sentence.

Length 68 snippet

The Ghost: You are as small as the sum of yourself and a stone wall!

Yes, yes, I'm getting a bit monotonous. But SPL is like that. As I stated a bit earlier, its expressions are a mixture of arithmetic operations. Thus, this is yet another incrementation - since stone wall is a neutral "noun".

Length 69 snippet

Thou art as disgusting as the difference between Othello and thyself!

Instead of a sum, we have the subtraction between two characters, Othello and whoever is being spoken to.

Length 70 snippet

You are as handsome as the sum of Romeo and his black lazy squirrel!

We return to the additions, yes - call me formulaic, heh. We translate this to Romeo + 2*2*1 .

Length 71 snippet

Scene I: Dialogues. [Enter Juliet] Othello: Speak your mind! [Exit Juliet]

A Scene can be as small as this. Juliet enters the stage, Othello tells her to output her stored value, then she gets off stage again.

Length 72 snippet

twice the difference between a mistletoe and an oozing infected blister!

One more arithmetic operation - because SPL is riddled with them. We can translate this to 2*(1-2*2*(-1)) .

Length 73 snippet

You are nothing! Remember me. Recall your unhappy story! Speak your mind!

Four instructions in a row?! I'm quite proud of myself, actually. Anyway, let's assume this is a dialogue between Romeo and Juliet (and he's speaking): this means that Juliet's value starts at 0; then, Juliet will push Romeo's value into her stack of memory, pop it and output it in its entered form. Simple, right?

Length 74 snippet

You are as sweet as the sum of the sum of Romeo and his horse and his cat!

Yeah, yeah, boring example, I know. But this is X = (Romeo + 1) + 1 .

Length 75 snippet

Is the remainder of the quotient between Othello and me as good as nothing?

Well, this is pretty straightforward. If your decoding skills are malfunctioning, it translates to if (Othello % X == 0) .

Length 76 snippet

Thou art as rich as the sum of thyself and my dog! Let us return to scene I.

The jump from snippet 26 with an expression before it. A goto on SPL isn't always found near a condition, it can be like this - and, of course, this type of goto will always be found at the end of an Act or Scene, since instructions after it will never be compiled/performed. The first instruction is pretty simple: x=x+1 .

Length 77 snippet

[Exit Hamlet] [Enter Romeo] Juliet: Open your heart. [Exit Juliet] [Enter Hamlet]

So, we have Juliet and Hamlet on stage; but we're in need of the value from Romeo. Thus, in order to spare the compiler from a very nasty headache, firstly we remove Hamlet from the stage (though it could have been Juliet the one to go), we tell Romeo to get on stage, Juliet gives him an instruction to output a number (see snippet 21's explanation), then Romeo gets out of the stage and Hamlet returns. Pretty straightforward and simple.

Length 78 snippet

The Ghost: Speak thy mind. Lady Macbeth: Listen to thy heart! Remember thyself.

So, The Ghost (Hamlet's deceased father) is telling Lady Macbeth to output her value, while she orders The Ghost to read a number and push it into his stack.