SpellCast
Spell Cast is an esoteric programming language that uses fantasy-themed syntax to perform standard programming operations. It draws inspiration from magical incantations, making code resemble spellcasting rituals.
Overview
In Spell Cast, variables are referred to as "spells," and operations are performed using phrases that mimic magical commands. The language supports basic arithmetic, control flow, input/output, and character manipulation, all expressed through a whimsical syntax.
Syntax and Semantics
Variables
Variables are created using the phrase:
create a new spell named [variable] with the power of [value]
For example:
create a new spell named magicNumber with the power of 42
Output
To display output:
shout the many cries of [expression]
Example:
shout the many cries of magicNumber
Input
To receive input:
find the source of the messages
Example:
create a new spell named userInput with the power of find the source of the messages
Arithmetic Operations
Spell Cast uses descriptive phrases for arithmetic:
- Addition:
combine the power of [a] and [b]
- Subtraction:
remove the power of [b] from [a]
- Multiplication:
duplicate the power of [a] [b] times
- Division:
split the power of [a] [b] times
Control Flow
Conditional statements:
cast only if the spell [condition] is true
do
[statements]
else
[statements]
done
Loops:
whilst the spell [condition] is true
do
[statements]
done
Conditional Expressions
is [first] equal to [second]
is [first] not equal to [second]
is [first] greater than [second]
is [first] less than [second]
Character Manipulation
- To get the ASCII value of a character:
may the sorcerers cast their spells on [character]
- To get a character from an ASCII value:
get the character from the spell [number]
Examples
Hello, World!
create a new spell named greeting with the power of "Hello, World!" shout the many cries of greeting
Calculator
shout the many cries of "Enter in first number: "
shout the many cries of
get the character from the spell 10
create a new spell named first with the power of
find the source of the messages
shout the many cries of "Enter in second number: "
shout the many cries of
get the character from the spell 10
create a new spell named second with the power of
find the source of the messages
shout the many cries of "Enter in operator (+ - * /): "
shout the many cries of
get the character from the spell 10
create a new spell named op with the power of
find the source of the messages
cast only if the spell is op equal to "+" is true do
shout the many cries of
combine the power of first and second
else do
cast only if the spell is op equal to "-" is true do
shout the many cries of
remove the power of second from first
else do
cast only if the spell is op equal to "*" is true do
shout the many cries of
duplicate the power of first second times
else do
cast only if the spell is op equal to "/" is true do
shout the many cries of
split the power of first second times
else do
shout the many cries of "Invalid Operator!"
done
done
done
done
99 bottles of pop on the wall!
create a new spell named pop with the power of 99
whilst the spell is pop greater than 1 is true do
shout the many cries of pop
shout the many cries of " bottles of pop on the wall!"
shout the many cries of
get the character from the spell 10
shout the many cries of pop
shout the many cries of " bottles of pop!"
shout the many cries of
get the character from the spell 10
shout the many cries of "Take one down, pass it around, "
set the power of pop to remove the power of 1 from pop
done
shout the many cries of 1
shout the many cries of " bottle of pop on the wall!"
shout the many cries of
get the character from the spell 10
shout the many cries of 1
shout the many cries of " bottles of pop!"
shout the many cries of
get the character from the spell 10
shout the many cries of "Take one down, pass it around, "
shout the many cries of "no more bottles of pop on the wall!"
Cat program
create a new spell named userInput with the power of find the source of the messages shout the many cries of userInput
External Resources
See Also
- LOLCODE
- Chef