vurl

From Esolang
Jump to navigation Jump to search

vurl (viba's useless rudimentary language) is a programming language created by User:Viba in 2022, for no reason other than to cure their own boredom. it is designed to feel vaguely like Scratch, but text-based.

vurl logo

overview

syntax

a vurl program consists of lines. each line consists of a command name followed by any number of arguments, all separated by spaces. an argument may be a string literal, variable reference, or embedded command.

string literals are sequences of characters. strings may be enclosed with quotation marks, but this is only necessary if the string contains spaces, is an empty string, or is enclosed in square brackets or parentheses (and would thus otherwise have a different syntactic meaning).

a variable reference represents the value of a variable. it is written as a variable name enclosed in square brackets.

an embedded command is a command followed by arguments, enclosed in parentheses. it represents the return value of that command.

a line starting with # is a comment.

values

values in vurl are primarily stored as strings. even "numbers" are actually stored as their string representations (eg. 23 is stored as the string "23"). commands that deal with numbers, such as add sub mul div mod, will first try to interpret their inputs as numbers, then perform the operation, and then return the result as a string. if such an input cannot be interpreted as a number, that is an error.

vurl also has lists, which can be created like so: set myList (list). unlike in Scratch, an item in a list can itself be a list (eg. push myList (list)). note that commands that work with lists take in a variable name at which a list is stored (eg. pop myList). (before 2022-05-17, such commands took a variable reference instead, eg. pop [myList])

in addition to strings and lists, variables in vurl can also store functions, via the define command. vurl functions can have local variables, whose names must start with .. functions may be called with arguments, which are stored as a list in that function's local [.args] variable. below is an example of a function being defined and called:

define printSquare
    set .x (index .args 1)
    print (mul [.x] [.x])
end

call printSquare 7

indexes start from 1. boolean values are represented as the strings "1" and "0".

commands

vurl commands
command description
set [var] [value] sets the value of the variable [var] to [value].
list [item] [item] ... returns a list where the items are the arguments, if any.
push [list] [item] pushes [item] onto [list] (adds it at the end of the list).
pop [list] pops the top item from [list]. returns the popped item.
insert [list] [index] [item] inserts [item] into the position [index] of [list].
remove [list] [index] removes the item at index [index] from [list]. returns the removed item.
index [list] [index] returns the item at index [index] of [list].
replace [list] [index] [value] replaces the item at index [index] of [list] with [value].
add [x] [y] ... returns the sum of all the arguments, or 0 if none are given.
sub [x] [y] returns [x] - [y].
mul [x] [y] ... returns the product of all the arguments, or 1 if none are given.
div [x] [y] returns [x] / [y].
mod [x] [y] returns [x] % [y].
join [x] [y] ... returns the concatenation of all the arguments, or an empty string "" if none are given.
len [x] returns the length of the string or list [x].
substr [string] [start] [end] returns a substring of [string] from indexes [start] to [end] inclusive.
eq [x] [y] returns whether the two values are equal.
gt [x] [y] returns whether [x] is greater than [y].
lt [x] [y] returns whether [x] is less than [y].
gte [x] [y] returns whether [x] is greater than or equal to [y].
lte [x] [y] returns whether [x] is less than or equal to [y].
and [x] [y] returns whether both [x] and [y] are true.
or [x] [y] returns whether either [x] or [y] are true.
not [x] returns whether [x] is not true.
if [x] begins a code block that executes if [x] is true.
while [x] begins a code block that executes repeatedly while [x] is true.
end ends a code block.
define [name] defines a block of code labelled as [name] that may be executed later. when called, arguments will be stored in the list [.args].
call [name] ([arg] [arg] ...) calls a predefined code block and passes arguments into it.
print [value] outputs a value.
input returns user input.

examples

hello world

print "Hello, world!"

truth machine

set x (input)

if (eq [x] 0)
    print 0
end

if (eq [x] 1)
    while 1
        print 1
    end
end

collatz sequence

set x (input)
print [x]

while (not (eq [x] 1))
    set c (eq (mod [x] 2) 0)
    if [c]
        set x (div [x] 2)
    end
    if (not [c])
        set x (add (mul [x] 3) 1)
    end
    print [x]
end

see also

  • vurlrs, a dialect of vurl written in Rust with added features, made by taswelll
  • VurlG, an extension of vurl for audiovisual interactive content

external links