MagiStack

From Esolang
Jump to navigation Jump to search

MagiStack is a stack-based esoteric programming language created by Katrina Scialdone. It is based loosely on Unefunge (a one-dimensional offshoot of Befunge) and uses some similar or identical commands. It is no longer in development as of version 1.2.

Commands

In MagiStack, each character is a command. Any unrecognized characters are ignored. Line breaks and tabs are stripped from the program before execution.
Commands may be clarified in this table by parenthesized pseudocode; each value used from the stack used will be represented by a letter, starting from "a".

Command Version Added Description
0-9 v1.0 Pushes the number's value to the stack
+ v1.0 Pops the top two values from the stack and pushes the sum (a+b)
- v1.0 Pops the top two values from the stack and pushes the difference (b-a)
* v1.0 Pops the top two values from the stack and pushes the product (a*b)
/ v1.0 Pops the top two values from the stack and pushes the quotient (b/a)
% v1.0 Pops the top two values from the stack and pushes the remainder (b%a)
! v1.0 Pops the top value from the stack and pushes the inverse (!a>0)
` v1.0 Pops the top two values from the stack and pushes whether (b>a)
: v1.0 Duplicates the top value from the stack
\ v1.0 Swaps the top two values from the stack
$ v1.0 Pops the top value from the stack and discards it
. v1.0 Pops the top value from the stack and outputs it as an integer
, v1.0 Pops the top value from the stack and outputs it as the ASCII character its value represents (in range 0-127)
= v1.0 Pops the top two values from the stack and skips the next character (Note: includes non-command characters! Be careful!) if they are not equal
# v1.0 Skips forward to the next occurence of #, |, or ], or the end of the program
@ v1.0 Skips backward to the last occurence of @, |, or ], or the beginning of the program
] v1.0 Terminates forward skipping (Note: # can be used, but it risks starting an unintended skip, especially with conditionals; | can be used, but is not direction-dependent)
[ v1.0 Terminates backward skipping (Note: @ can be used, but it risks starting an unintended skip, especially with conditionals; | can be used, but is not direction-dependent)
| v1.0 Terminates skipping in either direction (Note: see #, @, [, and ] to see other options and direction-dependency)
? v1.1 Pushes the size of the stack onto the stack (i.e. [3,2,1] -> [3,2,1,3])
^ v1.1 Waits for input, then pushes it onto the stack as a signed integer (pushes 0 on invalid input)
& v1.1 Waits for input, then pushes it onto the stack as ASCII values (pushes each character separately)
_ v1.1 Exits the program
" v1.2 Enters string mode until the next occurrence of "; while in string mode, each character will be pushed as an ASCII value
{ v1.2 Pops an integer from the stack and pushes each digit in it as an ASCII value
> v1.2 Skips to the final occurrence of |, or to the end of the program
< v1.2 Skips to the first occurrence of |, or to the start of the program
~ v1.2 Reverses the stack (i.e. [3,2,1] -> [1,2,3])
; v1.2 Pops the bottom value off the stack and pushes it on top (i.e. [3,2,1] -> [2,1,3])

Computational class

As MagiStack's memory is only limited by its implementation (rather than by the language itself), it is possible that it is Turing-complete. However, versions up to v1.1 have been proven to almost certainly not be Turing-complete, and beyond that have not been definitively proven or disproven.

Examples

Note that these example programs may not be the most efficient implementation possible (and probably aren't).

Hello, world!

v1.0:

89*,25*2*5*1+,25*2*5*8+,25*2*5*8+,25*2*5*9+2+,92+4*,48*,96+8*1-,25*2*5*9+2+,25*2*5*9+5+,25*2*5*8+,25*2*5*,92+3*,

v1.1:

33687682798732447976766972|\91+*+,?0=#@|

v1.2+:

"Hello, world!"~|,?0=#@

99 bottles of beer

v1.0+:

91+:*|1-::::::::.48*,92+6*,91+8*1-,91+8*4+:,,91+8*4-,91+7*1-,1=#91+8*3+,]48*,91+8*1-,91+7*,48*,92+6*,91+7*1-:,,91+8*2+,48*,91+8*1-,91+8*2-,48*,91+8*4+,91+7*2+,91+7*1-,48*,91+9*3-,91+6*5+,91+8*4-:,,92+4*,91+,.48*,92+6*,91+8*1-,91+8*4+:,,91+8*4-,91+7*1-,1=#91+8*3+,]48*,91+8*1-,91+7*,48*,92+6*,91+7*1-:,,91+8*2+,92+4*,91+,91+8*4+,91+6*5+,91+7*5+,91+7*1-,48*,91+8*1-,91+8*2-,91+7*1-,48*,91+7*2-,91+8*1-,91+9*3-,91+8*2-,92+4*,48*,91+,91+8*,91+6*5+,91+8*3+:,,48*,91+7*3+,91+8*4+,48*,91+6*5+,91+8*2+,91+8*1-,91+8*5+,91+8*2-,91+7*2-,92+4*,91+,1=#1-.#91+8*2-:,1+,]48*,92+6*,91+8*1-,91+8*4+:,,91+8*4-,91+7*1-,2=#91+8*3+,]48*,91+8*1-,91+7*,48*,92+6*,91+7*1-:,,91+8*2+,48*,91+8*1-,91+8*2-,48*,91+8*4+,91+7*2+,91+7*1-,48*,91+9*3-,91+6*5+,91+8*4-:,,91+4*6+,91+:,,1=#@|

v1.2+:

91+:*|1-:{" bottle"~:~;1=#"s"|" of beer on the wall,"91+~:~;{" bottle"~:~;1=#"s"|" of beer,"91+"Take one down, pass it around,"91+~:~;1-:0=#{#$"No more"|" bottle"~:~;1-1=#"s"|" of beer on the wall."91+:;~|,?1=#@|:1=#<

Factorial

v1.0+:

78\91+*+,85\91+*+,77\91+*+,66\91+*+,69\91+*+,82\91+*+,58\91+*+,48*,^:1`1=#_|:1-:1=#@|*?1=#@|70\91+*+,65\91+*+,67\91+*+,84\91+*+,79\91+*+,82\91+*+,73\91+*+,65\91+*+,76\91+*+,58\91+*+,48*,.

Raw version (no input prompt, number is hardcoded at beginning of program):

5:1`1=#_|:1-:1=#@|*?1=#@|.

Cat program

v1.2+:

&~|,?0=#@

External resources