[Question]
  [
What general tips do you have for golfing in The Shakespeare Programming Language? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to SPL (e.g. "remove comments" is not an answer).
Please post one tip per answer.
  
[Answer]
(Well... since this is my *adopted* language 1, I feel like I'm obliged to add something here)
## Use short variable names
Yeah, yeah, yeah, that's pretty standard to code-golf, you just use one-letter-length variable names, no news here. Or is there? Because the chaps that created SPL were wacky enough not to allow any name for their language's variables: they **must** come from Shakesperian plays which, in terms of character length, is a pain in the royal tush - but, if you're coding in SPL, you already know that. So, my advice would be to use characters with short names, like *Ajax*, *Ford*, *Page* or *Puck*, instead of *The Archbishop of Canterbury*, per instance.
That's all I got, I'm afraid.
---
1- since my Java skills are equivalent of those of a newborn.
[Answer]
# Any Roman numeral is a valid scene number
That means, that instead of:
```
Scene I
Scene II
Scene III
Scene IV
Scene V
```
You can do:
```
Scene L
Scene I
Scene C
Scene X
Scene V
```
[Answer]
(after doing the previous one, I just remembered a few things)
## Choose your code carefully
An example, to try and explain what this mean.
```
Ajax:
 You are as warm as a big red rich fair cute bold cat!
```
and
```
Ajax:
 Thou art as blossoming as an embroidered trustworthy bottomless peaceful charming handsome chihuahua!
```
produce the exact same result, which is make the *character* being spoken to assume the value 64 (since, assuming you [read my long battle with SPL](https://codegolf.stackexchange.com/a/44766/32139), you know that both lines are equivalent to 2\*2\*2\*2\*2\*2\*1); however, the first one has 59 bytes, while the second one has a bytecount of 107.
Still, no one is going to be demented enough to enter a [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") challenge with SPL, so...
[Answer]
# Remove unneeded words
Look at this (inserting newlines and whitespace for readability):
```
Puck:You is a big big cat!
     Open your heart!
Ajax:Be you worse than I?
     If so, let us return to Scene V!
     If not, you is a cat.
     You is the sum of I and the sum of a cat and you
     Speak thy mind!
     [Exeunt]
```
Looks pretty golfed eh? Here's an even more stripped down unintelligible form:
```
Puck:You big big cat!
     Open heart!
Ajax:Be you worse I?
     If solet usScene V!
     If notyou cat.
     You is the sum ofI the sum ofa cat you.
     Speak thy!
```
[Try it online!](https://tio.run/##VY/BCoMwDIbvPkW8Sx/Ay3Cwg6cNhIEMD10Xp9O1YlOmT981m0NXSAnJ9/ejdui9b0T2kFMiTk51icgUQZ6KQqFGbi4HTTgCIyD1DZiqIr7T0ji4tvdPKUlxBL9zHFBDg3JchpxO9whzSLzMaMPLu5XOa7CmRwJnv9pz/LfUhjgYFGKds7y1QA2CdU8wdb7pJcNs2wSKAWUXmDmOFgt/bkKnqfL@DQ)
For reference, here's a list of easily removable words from code:
* **Speak thy mind** -> **Speak thy**
* **Open your heart** -> **Open heart** **\***
* **Listen to thy heart** -> **Listen tothy**
* **Open your mind** -> **Open mind** **\***
* **You is a cat** -> **You cat** **\***
* Only applies to constants such as `big cat`, otherwise you still need the 'is'
* **Let us return to** -> **Let us**
* **Be X [op] than Y?** -> **Be X [op] Y?**
* **You is [op] of X** -> **You is [op] ofX**
* **You is [op] of X and Y** -> **You is [op] ofX Y**
* **[Exeunt]** -> (removed entirely)
Legend:
* `X` and `Y` are constants like `cat`, `I` or `you`
* `[op]` are operations like `nicer`, `the sum of`
* **\*** means you can remove the punctuation if it's the last sentence of the play
If I come across any others I'll add it to the list.
For extra reference, here's the shortest header to start off a program:
```
,.Ajax,.Puck,.Act I:.Scene I:.[Enter Ajax and Puck]
```
[Try it online!](https://tio.run/##Ky7I@f9fR88xK7FCRy@gNDkbSCampwJFkksUPK30gpNT81JBjGjXvJLUIgWQQoXEvBQFkNrY//8B "Shakespeare Programming Language – Try It Online")
Add Page and Ford as extra characters as necessary.
[Answer]
# Use short words
So here they are:
* Use `a` instead of `an` or `the`, except the expressions `the sum of` and similar, since they won't work with `a`.
* Use `am`, `be` or `is` instead of `are` or `art`.
* Use `I` instead of `me` or `myself`.
* Use `you` instead of `thee`, `thou`, `thyself` or `yourself`.
* Use `big` for adjectives.
* Use `cat` for positive numbers.
* Use `pig` for negative numbers.
* Use `zero` for zero.
* Use `worse` for `A < B` (instead of `smaller` or `punier`).
* Use `nicer` for `A > B` (instead of `better`, `bigger`, `fresher`, `friendlier` or `jollier`).
* Character names:
	+ 4 letters: Ajax, Ford, Page, Puck
	+ 5 letters: Egeus, Helen, Julia, Lucio, Mopsa, Paris, Pinch, Priam, Regan, Robin, Romeo, Timon, Titus, Venus, Viola
	+ 6 letters: Adonis, Aegeon, Alonso, Angelo, Arthur, Banquo, Bianca, Brutus, Cicero, Dorcas, Duncan, Emilia, Fenton, Hamlet, Hecate, Hector, Helena, Hermia, Imogen, Juliet, Lennox, Oberon, Olivia, Orsino, Portia, Thaisa, Thurio, Tybalt
	+ 7 letters: Adriana, Aemilia, Agrippa, Antonio, Capulet, Cassius, Claudio, Dionyza, Escalus, Goneril, Horatio, Leonato, Luciana, Macbeth, Macduff, Malcolm, Mariana, Miranda, Octavia, Ophelia, Orlando, Othello, Pantino, Proteus, Publius, Shallow, Shylock, Slender, Solinus, Theseus, Titania, Troilus, Ulysses
	+ 8 letters: Achilles, Beatrice, Benedick, Benvolio, Claudius, Cordelia, Cressida, Dogberry, Don John, Falstaff, Gertrude, Hermonie, Isabella, Lysander, Mercutio, Montague, Pericles, Polonius, Pompeius, Prospero, Rosalind, Stephano
	+ 9 letters: Agamemnon, Antiochus, Autolycus, Balthazar, Brabantio, Cassandra, Cleopatra, Cornelius, Demetrius, Desdemona, Donalbain, Don Pedro, Ferdinand, Francisca, Hippolyta, King John, King Lear, Lychorida, Sebastian, The Ghost, Valentine, Vincentio
	+ 10 letters: Andromache, Cymberline, Fortinbras, Friar John, King Henry
	+ 11 letters: Mark Antony
	+ 12 letters: Doctor Caius, King Richard, Lady Capulet, Lady Macbeth, Lady Macduff, Prince Henry, Queen Elinor
	+ 13 letters: John of Gaunt, Julius Caesar, Lady Montague, Mistress Ford, Mistress Page
	+ 14 letters: Friar Laurence, The Apothecary
	+ 15 letters: Christopher Sly, Octavius Caesar
	+ 17 letters: John of Lancaster, Mistress Overdone, The Duke of Milan
	+ 18 letters: The Duke of Venice
	+ 24 letters: The Abbot of Westminster
	+ 28 letters: The Archbishop of Canterbury
	+ If you really need more, you definitely should consider using the stack of each character.
[Answer]
# Use only one scene
Normally, you can't reuse the first scene of an act, since it always has `[Enter Ajax and Puck]` first thing. However, you can preface this with `[Exeunt]` to be able to reuse the first scene of a play. `[Exeunt]` is one byte shorter than declaring a new scene, and jumping to an Act is two bytes less than jumping to a Scene.
E.g: A simple cat program
```
,.Ajax,.Page,.Act I:.Scene I:.[Enter Page and Ajax]Scene V:.Ajax:Open mind!Speak thy!Let usScene V!
```
[Try it online!](https://tio.run/##Ky7I@f9fR88xK7FCRy8gMT0VyE4uUfC00gtOTs1LBTGiXfNKUosUQJIKiXkpCiC1sRDZMCuwTiv/gtQ8hdzMvBTF4ILUxGyFkoxKRZ/UEoXSYqg6xf//E5OSAQ "Shakespeare Programming Language – Try It Online")
To:
```
,.Ajax,.Page,.Act I:.Scene I:.[Exeunt][Enter Page and Ajax]Ajax:Open mind!Speak thy!Let usAct I!
```
[Try it online!](https://tio.run/##Ky7I@f9fR88xK7FCRy8gMT0VyE4uUfC00gtOTs1LBTGiXStSS/NKYqNd80pSixRAihQS81IUQHpiQYSVf0FqnkJuZl6KYnBBamK2QklGpaJPaolCaTHYLMX//xOTkgE "Shakespeare Programming Language – Try It Online")
[Answer]
# You don't have to switch people in conditionals.
For example,
```
Ajax:Is you better than the sum of a fat fat fat fat cat and a fat cat?
Puck:If so,let us return to Scene I.
```
is longer than
```
Ajax:Is you better than the sum of a fat fat fat fat cat and a fat cat?If so,let us return to Scene I.
```
[Answer]
# Remove redundant spaces
Apart from the trivial ones (two adjacent spaces, adjacent to a punctuation, adjacent to a newline, at the end) (with some exceptions), the space after the following tokens can be removed:
* `the sum of`
* `let us`
* `the ghost` ([like this](https://tio.run/##Ky7I@f9fR88xK7FCRy8kI1XBPSO/uAQokFyi4GmlF5ycmpcKYkS75pWkFinAVSTmpSiANMVygUgrLoXI/FKF5MQSPS6FSiArsShVoQSotrg0VyE/DcRKB@mCM4DK/AtS8xQyUhOLSvT@/09MSgYA)) (but who would use this character anyway)
* `if so` and `if not` (remove the `,` after this, and don't need to add any space. Example: `if solet usact I`)
* `listen to` (so `listen tothy` works, [like this](https://tio.run/##Ky7I@f9fR88xK7FCRy@gNDkbSCampwJFkksUPK30gpNT81JBjGjXvJLUIgWQQoXEvBQFkNpYEM/KJ7O4JDVPoSS/JKNSL78AyMxITSwq@f/f0MgYAA))
* and basically any multi-word [tokens](https://github.com/TryItOnline/spl/blob/master/makescanner.c#L110-L142).
Note: This does not work with the [Perl interpreter](https://metacpan.org/pod/distribution/Lingua-Shakespeare/lib/Lingua/Shakespeare.pod). It's probably just an unintended effect caused by Flex's parsing behavior. The ["language standard"](http://shakespearelang.sourceforge.net/report/shakespeare/) is not clear about that.
[Answer]
# Jumps can be shorter
You can use `return to` even if the scene is ahead, and vice versa. In fact, the interpreter doesn't even care if you omit it entirely. This means these four statements are 100% equivalent:
```
Let us proceed to Scene X.
Let us return to Scene X.
Let us Scene X.
Let usScene X.
```
[Answer]
The "let us return to scene X" can be used even if the character being spoken to is off stage. So instead of:
```
Puck:Am I as fat as the sum of a big big big big big big cat and a cat?
Ajax:If not,let us return to scene III.
[Exit Puck]
[Enter Page]
Ajax:You is a big big big big big big cat.
```
You can do:
```
Puck:Am I as fat as the sum of a big big big big big big cat and a cat?
[Exit Puck]
[Enter Page]
Ajax:If not,let us return to scene III.You is a big big big big big big cat.
```
[Answer]
# `If (so|not)` does not have to immediately follow the comparison.
```
Am I as big as you?You big big big big big cat.If so, you is the sum of you and a big big cat.
```
[Answer]
# Instead of substracting, add constants
```
You is the difference between I and a big cat.
```
is longer than
```
You is the sum of I and a big pig.
```
[Answer]
# Use 'square', 'cube', 'product' and 'factorial'
The operations `the square of`, `the cube of`, `the factorial of` and `the product of` exist but are only mentioned in passing (if at all) in the documentation. They can save you bytes to define (large-ish) constants. For instance, to get the number 64,
```
a big big big big big big cat
```
is 5 bytes longer than
```
the cube ofa big big cat
```
Similarly, the shortest way of getting 49 is with \$49=7^2\$ i.e.
```
the square ofthe sum ofa big big big cat a pig
```
and you can get 24 as \$4!\$ i.e.
```
the factorial ofa big big cat
```
There can be situations where viewing a number as the product of two smaller existing constants can make `the product of` useful.
Finally, note that there is also `the square root of`and `the quotient between`. Both round down, as the only type in SPL is integers: a short way to get 200 is as \$200 = \lfloor \sqrt{8!} \rfloor\$:
```
the square root ofthe factorial ofa big big big cat
```
[Answer]
# Use shorter words
Examples:
`Thy` and `thyself` are shorter than `your` and `yourself`.
`Is` is shorter than `are`.
and more...
[Answer]
# Gotos aren't the only commands usable with `If (so|not)`
```
Am I as big as you?If so,you is the sum of you and a big big cat.If not,you is the sum of you and twice I.
```
[Answer]
# All newlines are ignored
```
,.Ajax,.Puck,.Page,.Act:.Scene:.[Enter Ajax and Puck]Ajax:You Puck.[Exeunt]
```
[Answer]
# You don't need the ending `.` or `!`.
[Try it online!](https://tio.run/##Ky7I@f9fR88xK7FCRy8gMT0VyE4uUfC00gtOTs1LBTGiXfNKUosUQEoUEvNSFECqYkE8q8j8UoXkxJL//xOTkgE "Shakespeare Programming Language – Try It Online")
This can also be used before a `[`. (thanks jimmy23013)
```
,.Ajax,.Page,.Act I:.Scene I:.[Enter Ajax and Page]Ajax:You cat[Exeunt]
```
Examples:
* `,.Ajax,.Page,.Act I:.Scene I:.[Enter Ajax and Page]Ajax:You cat`
* `,.Ajax,.Page,.Act I:.Scene I:.[Enter Ajax and Page]Ajax:Open mind[Exeunt]`
Doesn't work in:
* `,.Ajax,.Page,.Act I:.Scene I:[Enter Ajax]` (right after `Scene {number}:`) (however [this](https://tio.run/##Ky7I@f9fR88xK7FCRy8gMT0VyE4uUfC00gtOTs1LBTIqFKJd80pSixRAahQS81IUQMpiwVwrBf@C1DyFjNTEopL//w0B) works, I don't know why)
* `,.Ajax,.Page,.Act I:.Scene I:.[Enter Ajax and Page]Ajax:Listen to your heart` (and shorter variants)
* `,.Ajax,.Page,.Act I:.Scene I:.[Enter Ajax and Page]Ajax:Let us return to scene I` (and shorter variants)
* `,.Ajax,.Page,.Act I:.Scene I:.[Enter Ajax and Page]Ajax:Recall` (only after empty `Recall`, `Recall x` or `Recall@` etc. works)
* `,.Ajax,.Page,.Act I:.Scene I:.[Enter Ajax and Page]Ajax:Speak thy` (without `mind`)
[Answer]
# Use ‘twice’ and the distributive property
Instead of:
```
You is the sum ofa big big big big cat a big big big cat.
```
Use:
```
You is twice twice twice the sum ofa big cat a cat.
```
This saves 2 bytes per `twice` since 2 uses of `big` is 8 bytes (counting spaces) and `twice` is only 6 bytes.
[Answer]
# Use `<` or `>` instead of `==`
Not applicable to every situation, but it's quite a bit shorter:
### Puck == Ajax
```
Puck:Is I as bad as you?
```
### Puck < Ajax or Puck > Ajax
```
Puck:Is I worse you?
Puck:Is I nicer you?
```
4 bytes shorter for both!
]