WhoScript

From Esolang
Jump to: navigation, search

WhoScript is a Doctor Who-themed esoteric programming language created by Daniel Gentry (MCS-Kaijin).

Commands

The language can be written in either its default form or 'one-line mode.' The following table gives each command and its one-line equivalent along with a description of what each does.

Command One-Line Equivalent Description
# # Pushes the decimal value of the provided hexadecimal to the stack. If more than one value is provided, then they must be separated by spaces.
@ n/a Denotes a comment.
+ + Pops the last two values from the stack pushes the sum.
- - Pops the last two values from the stack pushes the difference between the penultimate and last.
* * Pops the last two values from the stack pushes the product.
/ / Pops the last two values from the stack pushes the quotient of the penultimate divided by the last.
^ ^ Pops the last two values from the stack pushes the penultimate to the power of the last.
! ! Pops the last value and performs a bitwise not on it.
& & Pops the last two values from the stack performs a bitwise and on them.
| | Pops the last two values from the stack performs a bitwise or on them.
x x Pops the last two values from the stack performs a bitwise xor on them.
duplicate e Pushes a copy of the last value on the stack onto the stack.
truncate c Pops the last value and pushes that number rounded down. This number is still a decimal; use integer to make them integers.
integer i Pops the last value and pushes the that number as an integer. Since all operations such as addition and multiplication (but not the bitwise ones) push floating-point numbers to the stack, this is necessary to make them integers again.
switch w Switches the last two values in the stack.
pop > Pops the last value from the stack and stores it in a separate stack.
push < Pops the last value from the extra stack and pushes it to the main stack.
time_vortex v Begins an eternal loop.
paradox d Returns to beginning of time_vortex loop.
opening o Breaks a time_vortex loop.
TARDIS t Controls program flow.
psychic_paper p Controls I/O

WhoScript has two objects: TARDIS and psychic_paper. These two objects control the program flow and I/O respectively. The following tables list their functions and one-line equivalents along with a description of their effects.

TARDIS:

Command One-Line Equivalent Description
_ n/a Pop the last value from the stack and go to that line of the program.
<>= <>= Pop the last two values from the stack and compare the penultimate to the last based on the provided operator and push a 1 to the stack if true and a 0 otherwise.
if i Pop the last value from the stack and execute the following code up to TARDIS else or TARDIS landing if truthy.
else e Pop the last value from the stack and execute the following code up to TARDIS if or TARDIS landing if falsey.
landing l End an if/else statement.

psychic_paper:

Command One-Line Equivalent Description
write w Pop the last value and print it as an ASCII character to the console. If # is added to the end after a space then it prints the number popped.
read r Take input and push its ASCII value to the stack. If # is added to the end after a space then it pushes the number inputted. If no characters are provided then -1 is pushed to the stack.
clear c Clear the stack.
flush f Empty the stack and print all the values as ASCII characters to the console. If # is added to the end after a space then it prints the numbers.

Examples

Hello, World!

# 48 65 6c 6c 6f 2c 20 57 6f 72 6c 64 21
psychic_paper flush

A one-line program must begin with the number 1, must have its commands separated by semicolons, and has the ability to define strings in a much easier way. One-Line Mode is designed for better code-golfing.

1"Hello, World!";pf

Primality Test

# 2
psychic_paper read #
duplicate
time_vortex
	# 2
	TARDIS =
	TARDIS if
		pop
		pop
		# 50 72 69 6d 65 21
		psychic_paper flush
		opening
	TARDIS landing
	duplicate
	pop
	switch
	duplicate
	push
	switch
	TARDIS =
	TARDIS if
		pop
		pop
		# 50 72 69 6d 65 21
		psychic_paper flush
		opening
	TARDIS landing
	switch
	duplicate
	pop
	switch
	duplicate
	push
	switch
	/
	duplicate
	truncate
	TARDIS =
	TARDIS if
		pop
		pop
		# 43 6f 6d 70 6f 73 69 74 65 21
		psychic_paper flush
		opening
	TARDIS landing
	# 1
	+
	integer
	switch
	duplicate
	# 1
	-
	integer
paradox

One-Line Mode:

1#2;pr #;e;v;#2;t=;ti;>;>;"Prime!";pf;o;tl;e;>;w;e;<;w;t=;ti;>;>;"Prime!";pf;o;tl;w;e;>;w;e;<;w;/;e;c;t=;ti;>;>;"Composite!";pf;o;tl;#1;+;i;w;e;#1;-;i;d

An empty program produces the output "Reverse the polarity of the neutron flow!" and exits cleanly, allowing for a relatively large output with no code.

Implementation

MCS-Kaijin's WhoScript Python Interpreter: GitHub