Tarot

From Esolang
Jump to navigation Jump to search

Tarot is a stack-based esolang created by User:Lown in May 2024, where programs appear as sequences of Tarot cards. It is inspired by languages like PokéBattle, Airline Food, and Shakespeare, where ornate phrases or sentences stand in for program instructions, with one difference: because the cards are being drawn from a deck, no card may be used more than once (although card names can appear in the program multiple times as long as they are only played once). One card, Wheel of Fortune, allows the previously played cards to be shuffled back into the deck, but this also resets the stack.

In a manner similar to assembly languages, certain instructions also allow the interpreter to jump back and forwards through the program.

Overview and syntax

Programs are written as a set of Tarot cards, separated by periods. Comments are surrounded by double quotes. Whitespace and newlines are ignored.

Tarot uses an instruction pointer, which begins by pointing to 1 - the first Tarot card in the program. Programs continue until they exit early or come to the end of the list of cards.

Minor Arcana

The Minor Arcana are the cards numbered from Ace to King of the four suits (Swords, Cups, Wands, and Pentacles). Minor Arcana cards all push their card value as an integer to the stack (Ace is 1 and King is 14).

Major Arcana

Card Description
The Fool Push a random integer between 1 and 78 onto the stack.
The Magician Pop every value off the stack and output it, one by one, converting integers to their ASCII values.
The High Priestess Pop A, B, and C off the stack. If A != B, skip C instructions backwards and continue from the instruction immediately before that, i.e. decrement the instruction pointer by C - 1.
The Empress Pop A and B off the stack and push their sum to the stack.
The Emperor Pop A and B off the stack and push their difference to the stack.
The Hierophant Pop A, B, and C off the stack. If A == B, increment the instruction pointer by the value of C.
The Lovers Duplicate the top value on the stack.
The Chariot Pop the top value on the stack and increment the instruction pointer by it.
Strength Pop the top value on the stack. Set the instruction pointer to that value.
The Hermit Pop the top value on the stack. Skip that many instructions backwards and continue from the instruction immediately before that, i.e. decrement the instruction pointer by the value - 1.
Wheel of Fortune Reset the stack and the field of drawn cards, allowing the user to play previously drawn cards again.
Justice Pop A and B off the stack. Push the result of A == B to the stack: either 1 (true) or 0 (false).
The Hanged Man Push the length of the stack onto the stack.
Death Pop A and B off the stack. Push the result of the floor division of A by B on the stack.
Temperance Pop A and B off the stack. Push the result of A < B to the stack: either 1 (true) or 0 (false).
The Devil Pop A and B off the stack. Push the result of A > B to the stack: either 1 (true) or 0 (false).
The Tower Empty the stack.
The Star Ask the user for input, which must be an integer. Push this input on the stack.
The Moon Ask the user for input, which must be an integer. Floor divide this integer by 2. Push the result on the stack.
The Sun Ask the user for input, which must be an integer. Multiply this integer by 2. Push the result on the stack.
Judgement Pop A and B off the stack and push their product to the stack.
The World Exit the program.

Examples

Truth Machine

"How should I write a truth machine program?"
  Five of Cups.    
  Ace of Pentacles. 
  The Star.     
  The Hierophant.
"This is what will happen if the number is zero."
  Knight of Wands.
  Four of Cups.
  Judgement.
  The Magician. 
  The World.
"This is what will happen if the number is one."
  Wheel of Fortune.
  King of Swords.
  Three of Pentacles.
  Judgement.
  Seven of Cups.
  The Empress. 
  The Magician.
  Seven of Swords.
  The Hermit.

Implementations

Python interpreter