Shakespeare Programming Language

The Shakespeare Programming Language (SPL ) is a technology developed by Kalle Hasselström and Jon Åslund in 2001 imperative esoteric programming ( Computer Language ), which was implemented in C and is one of the most difficult -to-learn programming languages. Similar to the programming boss sees an SPL program as something quite different from: An SPL program looks at first glance as if it were a play by William Shakespeare and follows its typical structure.

SPL clearly demonstrates that a functional programming concept does not have to follow conventional notions. Structure and keywords must in principle only to a fixed scheme correspond to allow an unambiguous interpretation, regardless of how readable or logically the program text a person appears. Conversely, SPL programs for people who can not program, very easy to read, as a drama. The importance of the ( uninitiated ) people and for the computer, go here completely apart, two meanings overlap. Therefore, SPL is often used in teaching as an example of language design.

In what way are superimposed on the two meanings which elements of the dramas of Shakespeare correspond to which elements of a programming language, is presented below.

Basic knowledge

Shakespeare Programming Language is so special, because they do not like all the other programming from arithmetic and specified character is based, but the developer makes a lot of freedom in his program. Often the developer has the opportunity to rewrite the program in many places in hundreds of other variants that lead to the same result.

In addition, the programming language of Shakespeare is oriented (you can speak to program in dramatic form ), which makes them both unique, but also getting used to.

The following examples are from the first program in SPL - the ( in computer science so often programmed ) Hello world program.

Operation

The title

The first line of each " dramas play" in SPL is the title. This can be chosen freely and gives the piece a little more order and clarity. Since it can be freely selected, the compiler recognizes him only as a comment and let him out at compile time. Consequently, the title is optional, the developers give out, however, that a program without a title so poorly written as a drama without a title was poorly written.

Example:

The Infamous Hello World Program The characters ( dramatis personae )

As in any Shakespearean drama also need to be established at the beginning of the first people. These are the first to be recognized by the compiler and must be recognized for the compile takes place. Listed are all the characters of the play, which always is a brief description.

Example:

Romeo, a young man with a remarkable patience. Juliet, a young woman of remarkable grace Likewise. Ophelia, a remarkable woman much in dispute with Hamlet. Hamlet, the flatterer of Andersen Insulting A / S. The characters are similar to (signed integer ) variables. The following description of the character is mandatory, but is ignored by the parser (Source: Official documentation ). Can be used only characters that play a role in Shakespeare's plays and mostly Romeo, Juliet, Hamlet, Othello, Macbeth, King Lear, etc.

Acts and scenes

After the "Declaration" and " initialization " of the variables of the sequence of a drama " I Act" and "Scene I", which are each provided with titles follow accordingly. As with the title they will not be judged by the compiler; "Act" and "Scene " are thus Keywords for comments. Also entitled are not necessarily comparable acts and scenes for successful compilation. However, they are not optional in the sense of the programmer, since every programmer is virtually forced into SPL to divide their program into acts and scenes - comparable to programming conventions ( indenting ) in ordinary languages.

Example:

Act I: Hamlet 's insults and flattery. Scene I: The insulting of Romeo. Enter, Exit and Exeunt

Each scene in each act is enclosed by key words, which open or close the scene. These hot like real drama at the start [Enter ], [ Exit] and [ Exeunt ]. To announce a character and to ensure that the program does something, the characters, according to the logic must be on stage. Characters which respond already standing on the stage characters with " you", " thou " or any other pronoun of the second person, must also be placed on the stage. On the stage characters come through in the determination of their [Enter ] command as a " parameter".

Example:

[Enter Hamlet and Romeo ] Accordingly, they also come off again. This is done with the [ Exit] - or [ Exeunt ] command. Occurs from a figure, it must be mentioned behind the [Exit ], eg [Exit Romeo ]. If two or more characters at the same time from which Exeunt command must be used. Special case: At the end of the scene often arise from any person depicted. In this case, a single [ Exeunt ] is sufficient without any parameters to inform the compiler. Are you a character that is already on the stage, an Enter command or an absent character exit, so the compiler will report a runtime error.

Example:

[ Exeunt ] [ Exeunt Hamlet and Romeo ] dialogue

As in the real drama of the dialogue is also in SPL mostly based on calculation, input and output, and Goto. A dialog part of a single character consists of a character's name, a colon and one or more sets with the aid of, for example, held a calculation.

Example:

Hamlet: You lying stupid fatherless big smelly half-witted coward! You are as stupid as the difference in between a handsome rich brave hero and thyself! Speak your mind! constants

Constants are also set very clear in SPL. Each number and all calculations be written in English, not in arithmetic expressions. So there are some rules for constants:

  • Each noun is basically a constant with a value of 1 or -1.
  • This depends on whether the noun is " good" or " bad".
  • "flower ," for example, is a constant with a value of 1; " pig" or " negation " would have a corresponding -1.
  • When in doubt, are as it were neutral noun (value 1), such as " tree" is neutral and also has the value 1
  • Each forward -switched adjective the noun multiplied by 2 So to multiply a noun value of 4, you can switch two adjectives before the noun.
  • In the further course can be carried out to tender arithmetic expressions count the numbers, such as "the sum of a tree and a glittering flower is ..." would then be the expression 1 2 = ... correspond.

Another, more complicated example:

" the difference in between the square of the difference in between my little pony and your big hairy hound and the cube of your sorry little codpiece " First, we replace the constants by numbers. The rate is thus changed in:

" the difference in between the square of the difference in between 2 and 4 and the cube of -4" Now, the difference 2-4 give (-2 ) and the third power of ( -4) is is (-4) ³ = -64. Since the square of ( -2) = 4, we come to " the difference in between 4 and -64 ", which is exactly 68 the bottom line.

Thus, " the difference in between the square of the difference in between my little pony and your big hairy hound and the cube of your sorry little codpiece " = 68

Swell

725673
de