shortstack

From Esolang
Jump to navigation Jump to search
Note that shortstack is typically lowercased except, often, at the start of a sentence.

Shortstack is a codegolfed language created by User:mmph. It should not be used for codegolfing. Shortstack starts with a tape of which's content is only a 0. Every new instruction, it prints the current value of the tape. Shortstack also has a pointer for both the tape and the instruction pointer. Shortstack is a tape based programming language with only 5 commands.

Command Name Command Action
< Moves the tape pointer left, if outside of bounds, sets it to the top of the tape.
> Moves the tape pointer right, if outside of bounds, appends a 0 at the end of the tape, and sets the tape pointer to new cell.
[ If the cell is 0, sets the instruction pointer to the corresponding "]"
] If the cell is not 0, sets the instruction pointer to the corresponding "["
, Flips the cell at the current tape pointer position. (0 to 1, 1 to 0)

It's point was for its source file to be golfed, and is just a Turing machine at its core.

Source file:

i=open("f","r").read()
s=[]
l={}
for a,x in enumerate(i):
	if x=="[":s.append(a)
	if x=="]":b=s.pop(0);l[b]=a;l[a]=b
t=[0]
p=0
a=0
while a!=len(i):
	x=i[a]
	if x in"<>":
		p+=ord(x)-61
		if p==len(t):t.append(0)
	if x==",":t[p]=1-t[p]
	if x=="["and not t[p]:a=l[a]
	if x=="]"and t[p]:a=l[a]
	print(t)
	a+=1

One example program is one that "prints" "Hi".

,>>>,>>>><<<<<<<,>,>,>,>,<<<<<,

In reality it prints the binary values of "Hi", but only 2 of them. It actually prints:

[1]
[1, 0]
[1, 0, 0]
[1, 0, 0, 0]
[1, 0, 0, 1]
[1, 0, 0, 1, 0]
[1, 0, 0, 1, 0, 0]
[1, 0, 0, 1, 0, 0, 0]
[1, 0, 0, 1, 0, 0, 0, 0]
[1, 0, 0, 1, 0, 0, 0, 0]
[1, 0, 0, 1, 0, 0, 0, 0]
[1, 0, 0, 1, 0, 0, 0, 0]
[1, 0, 0, 1, 0, 0, 0, 0]
[1, 0, 0, 1, 0, 0, 0, 0]
[1, 0, 0, 1, 0, 0, 0, 0]
[1, 0, 0, 1, 0, 0, 0, 0]
[1, 0, 0, 1, 0, 0, 0, 0]
[0, 0, 0, 1, 0, 0, 0, 0]
[0, 0, 0, 1, 0, 0, 0, 0]
[0, 0, 0, 1, 0, 0, 0, 0]
[0, 1, 0, 1, 0, 0, 0, 0]
[0, 1, 0, 1, 0, 0, 0, 0]
[0, 1, 1, 1, 0, 0, 0, 0]
[0, 1, 1, 1, 0, 0, 0, 0]
[0, 1, 1, 0, 0, 0, 0, 0]
[0, 1, 1, 0, 0, 0, 0, 0]
[0, 1, 1, 0, 1, 0, 0, 0]
[0, 1, 1, 0, 1, 0, 0, 0]
[0, 1, 1, 0, 1, 0, 0, 0]
[0, 1, 1, 0, 1, 0, 0, 0]
[0, 1, 1, 0, 1, 0, 0, 0]
[0, 1, 1, 0, 1, 0, 0, 0]
[0, 1, 1, 0, 1, 0, 0, 1]

Which converts to:

����	�$H������������PPpp``hhhhhhi

Truth machine:

This language does not support input, so you have to modify the source file in order to "input" a number.

,[]

Removing the comma, results in you putting in a 0, leaving it is a 1. If it has a 0, it outputs a 0, if it has a 1, it outputs 1 forever.