3var

From Esolang
Jump to: navigation, search

3var is a language designed by User:LuaGeek2412 with the goal of being as capable as other languages, but being much easier to make an interpreter for. It is heavily inspired by Deadfish. Suggestions are welcome.

Language Overview[edit]

3var has - you guessed it - 3 variables. 2 of the variables are accumulators, and the third is a result. The accumulators will be referred to as A and B, and the result as R. 3var has quite a few commands, all of which are a single ASCII character to fulfill the goal of being easy to interpret. These commands are:

   i   Increments A
   d   Decrements A
   s   Squares A
   p   Prints A
   P   Prints the ASCII character associated with A
   x   Sets A to the absolute value of A
   >   Sets A to R
   a   Increments B
   k   Decrements B
   m   Squares B
   o   Prints B
   O   Prints the ASCII character of B
   0   Sets B to the absolute value of B
   <   Sets B to R
   +   Adds A and B, stores in R
   -   Subtracts B from A, stores in R
   *   Multiplies A and B, stores in R
   /   Divides A by B, stores in R
   ^   Exponentiates A to the Bth power, stores in R
   w   Prints R
   u   Marks a conditional which executes only if a>b
   U   Marks a conditional which executes only if a<b
   =   Marks a conditional which executes only if a==b
   (   Starts an if statement body
   )   Ends an if statement body
   |   Marks a loop which executes while a>b
   _   Marks a loop which executes while a<b
   \   Marks a loop which executes while a==b
   f   Marks a loop which executes a times
   F   Marks a loop which executes B times
   {   Starts a loop which repeats forever
   }   Ends a loop which repeats forever
   [   Starts a marked loop
   ]   Ends a marked loop
   '   Takes a 1 character input from the user and stores the ASCII value of the character in R
   "   Takes a number input from the user and stores it in R
   r   Resets all variables to 0
   @   Resets A to 0
   #   Rests B to 0
   e   Resets R to 0
   $   Toggles comment
   ~   Starts a line comment
   `   Causes the interpreter to ignore the next character

All other characters throw errors, unless enclosed in a comment.

Language Standards[edit]

  • Use of R as a full variable is discouraged, but allowed
  • All variables can contain any number

Computational Class[edit]

3var is Turing-complete if and only if its variables are unbounded. Bounds on the variables are not specified and therefore implementation-dependent.

Examples[edit]

Hello, World![edit]

Legitimate Hello, World! with the exclamation point and everything.

iisssaa/>e
maa->e#
aamam->e#
dddddddddddddddddddddddddPiiiiiiiiiiiiiiiiiiiiiiiii
iiiiPiiiiiiiPPiiiP
r
iis
aamaaaa
*>P
r
iisssaa/>e
maa->e#
aamam->e#
iiiiiiiiiiiiiiiiiiiiiiP
ddddddddP
iiiP
ddddddP
ddddddddP
r
iiss
aa*>
iP

Cat[edit]

This one is shorter. I promise.

{'>P}

Don't ask me to make it accept multiple characters before outputting.

Countdown[edit]

An example of a marked loop. Counts down from 100 to 1.

iiisis 
|[
	pd
]

The first line sets the starting value for A (100). It then sets B to the minimum value. Then, while a>b, it outputs a and decrements it.

Even or Odd[edit]

Takes a number input and calculates if it is even or odd.

"> ~Take a number input and move it to a.
|[ ~While a>b do...
	aa ~b+=2
]
=( ~if a==b...
	riiisisi `1`0`1
	P `e
	r
)
U( ~if b>a...
	riiisia+<*>i `1`1`1
	P `o
	r
)

Pretty self explanatory.

Conditional Cat[edit]

Copies input to output until a newline character is input.

i           ~Set a to 1
|[          ~While a>0 do...
   '<O      ~Read in a character to b and output
   @iiisi   ~Set a to 10
   ->x      ~Set a to |a-b|
   #        ~Set b back to zero for loop condition
]

External resources[edit]