RHOVL

From Esolang
Jump to navigation Jump to search
RHOVL
Paradigm(s) Imperative
Designed by User:Sλλλ1(210)
Appeared in 2021
Computational class Turing complete
Reference implementation Github
File extension(s) .txt


RHOVL (Register, Heap, One Variable Language) is an esolang created by Andrew Phillips in 2021. RHOVL is a simplistic imperative language that utilizes 26 variable registers a-z for data storage, a heap for function storage, and a single variable position for manipulating data. All data in RHOVL is u8, although the python implementation does not abide by this.

Specification

In the table below, the characters a, b, c are used to represent values that may only be registers (that is, a literal letter), while x, y, z are used to represent values that may be registers or constant literals (such as 3).

Feature Overview
Code Explanation
3 set the variable to a constant
a set the variable from a register
= a put the variable value into a register
+ x modify the variable by an operation
< x set the variable to 1 or 0 depending on a comparison
+= a modify a register by the variable value
# get an ASCII-decoded value from stdin and put it in the variable
$ print the variable as ASCII to stdout, or as a number with various format options
(EXPR1:EXPR2) "if EXPR1 then EXPR2;" perform EXPR1, then perform EXPR2 if the variable is nonzero.
(EXPR1;EXPR2) "while EXPR1 do EXPR2;"
(EXPR) do EXPR, then restore the variable to the value it had before EXPR.
[xyz: EXPR] do EXPR for each of the constant/register values before the colon
[abc; EXPR] do EXPR for each of the register values before the colon, then store each result back in the same register
[xyz: EXPR :abc] do EXPR for each of the constant/register values before the colon, then store each result back in the corresponding register behind the second colon
["hello":$] a (possibly escaped) "string" compiles into a list of ASCII constants that can be iterated over
{ EXPR } put a new function on the heap, and store the pointer to it in the variable
@x run the function pointed to by the register/constant x

Operations

RHOVL implements the standard operations + - * / %, as well as ^ for exponentiation.

A register-modifying expression such as -=r places the register on the LHS of the operation, which means it is different from (-r=r) so long as the operation is noncommutative. Neither or these expression change the value of the pass-through variable.

Additionally, RHOVL implements the bitwise operators & (and) | (or) ~ (xor). These may also be used with the register-modifying syntax above.

RHOVL also implements the logical comparison operators < > <= >= == != , but these cannot be utilized with the register-modifying syntax.

Output formatting

When outputting with $, the number is usually treated as an ASCII code. This behavior can be modified by suffixing the $ operator:

  • $' as a number without an ending
  • $` as a number followed by a newline
  • $_ as a number followed by a space
  • $, as a number followed by a comma and a space

When taking input with #, there are three variants:

  • # takes the next character input as ASCII
  • #_ takes the next non-whitespace character input as ASCII (consuming skipped input as well)
  • #' matches the input with /\s*(\d+)/ for numeric input

Examples

Hello world

["hello world":$]

Cat

(#;$)

Note that when eof is reached, # puts 0 into the variable, ending the loop

Truth machine

#'($';)

For and while loops

list and loops tests

while loop and fancy list printing
10 (; $,-1)

for loop and string printing
["Blast Off!":$] 10$ prints newline

use for-put to move & modify data
["the first four squares are: ":$]
[1 2 3 4::abcd] initialize list
[abcd:^2:efgh] map list and store somewhere else
[efgh:$_] 10$

build a list with for-modify
3 = x
[abcdefg; x+2=x]
["built list: ":$][abcdefg:$_] 10$
[abc;-3] alter the first three items
["built list: ":$][abcdefg:$_] 10$

sum a list with for
0 = x
[abcdefg: +x=x]
["sum of the list is ":$] x$' 10$

Note that writing in files simply causes registers to be loaded uselessly, so it can be used as a (perhaps costly) comment.

Function with branching

if and function tests

{= y
    (x > y: x$'[" is greater than ":$]y$')
    (x < y: x$'[" is less than ":$]y$')
    (x== y: x$'[" is equal to ":$]y$')
    10$ (a newline)
} = f

3 = x
[1 2 3 4 5: @f]

Factorial

{(1=j)(;*=j-1)j} = factorial

[1 2 3 4 5:
    (["factorial of ":$])
    $' ([" is ":$])
    @f $`
]

Interpreter

The creator of the language has put a python interpreter and several examples on GitHub