Slam

From Esolang
Jump to navigation Jump to search

Slam is an esoteric programming language made by User:ArthroStar11 Its syntax is meant to resemble slam poetry (hence the name) It is somewhat similar in concept to Beatnik, Length and Enjamb

Syntax

The syntax of Slam is built around generating numbers from user-defined strings. Each line represents a command/argument.

the numbers are generated using the following logic (where n is the number of space separated strings in a line and number is the length of each string)

number(1) X number(2) ... X number(n-1) X number(n)

for extra clarity here's the generation represented in python where each index of words is the length of a space separated string in a line

for x in words:
    if x == 0:
        opcode = words[x]
    else:
        opcode *= words[x]

for example the following would generate the numbers 15 and 18 respectively

123 12345
12 123 123

Each stanza in your poem represents a subroutine. Stanza 0 (the top one) represents your main routine (similar to int main() in C) other subroutines can be called using the gosub command (mentioned later) subroutines are full block statements so attempting to enter a subroutine without a call will throw an error. The return command (mentioned later) or letting the subroutine reach its end will return you to the call site. Stanzas are separated with a blank line (opcode 0) using return in Stanza 0 will throw an error, you instead need to let it reach its end.

loops will continually run if the Boolean cell (mentioned later) is true. Loops can be nested

Data Structure

Infinite array of signed integers (reference implementation uses an array with 30000 32-bit signed integers)

hold cell

Boolean cell

Commands

For ease of creativity all opcodes are composite numbers if a command takes arguments it will read the next <no. of args> lines to retrieve the arguments

  • 4: gosub (1 arg)
    • calls subroutine <arg1>
  • 6: return (0 args)
    • returns from a subroutine, can also just let subroutine end naturally
  • 8: loop (0 args)
    • defines start point of a loop, returns here if loop ends with Boolean cell true
  • 9: end loop (0 args)
    • defines end of a loop, jumps here if loop begins with Boolean cell false
  • 10: equal (2 args)
    • sets Boolean cell to true if variable <arg1> and variable <arg2> are equal
  • 12: greater than (2 args)
    • sets Boolean cell to true if variable <arg1> is greater than variable <arg2>
  • 14: less than (2 args)
    • sets Boolean cell to true if variable <arg1> is less than variable <arg2>
  • 15: not (0 args)
    • inverts Boolean cell
  • 16: add (2 args)
    • stores variable <arg1> + variable <arg2> into hold cell
  • 18: subtract (2 args)
    • stores variable <arg1> - variable <arg2> into hold cell
  • 20: multiply (2 args)
    • stores variable <arg1> * variable <arg2> into hold cell
  • 21: divide (2 args)
    • stores variable <arg1> / variable <arg2> into hold cell
  • 22: modulo (2 args)
    • stores variable <arg1> % variable <arg2> into hold cell
  • 24: input number (0 args)
    • stores input number into hold cell
  • 25: input character (0 args)
    • stores input character into hold cell
  • 26: output number (0 args)
    • outputs hold cell as a number
  • 27: output character (0 args)
    • outputs hold cell as an ASCII character
  • 28: store (1 arg)
    • copies hold cell into variable <arg1>
  • 30: retrieve (1 arg)
    • copies variable <arg1> into hold cell
  • 32: constant (1 arg)
    • stores <arg1> into hold cell

Sample Programs

Prints "HI"

Oh to be nice
Lovely!! greetings
Hey you be!
Beloved is me
Hark
Love blindly!
I
Hate noone!!
Hark!
To be nice
Hark
Hark!
How you are

Truth Machine (shows subroutines)

walk sluggish
I
seek traitor
hey
betray home
seek traitor
hey!
greet us
eat
dust
kill us
cant
I
Nevermore
cakes rot me
down
my stomachache!!
 
clams gurgle
hark
my dinnerplate!!

prints numbers 99 to 1

hi n' welcome!
salutations wanderer!
secrets held
before
fled before!!
I
fled before!
tomorrow
see there
you by 'self
before
to seek
your lie
my lie
my life
my salutations!!
to the day
my try
my cry!
secrets held
you be
secretive

Implementation

ArthroStar11's Interpreter (C++ source)