vfl

From Esolang
Jump to navigation Jump to search

vfl (viba's FALSE-like) is a programming language inspired by FALSE, created by User:Viba1 in 2024. It is designed to retain the minimalist and easy-to-implement spirit of FALSE while being better suited to the whims of its creator.

Key differences from FALSE include:

  • Access to an unbounded array of variables
  • Control flow works differently
  • Add modulo (%) and less-than (<) operators (but sacrifice the unary negation operator)
  • Input/output between different "ports", to facilitate arbitrary implementation defined I/O
  • Uses only ASCII characters

Commands

For a more thorough description of vfl, see the original webpage.

Literals

  • 123 put integer onto the stack
  • 'c put character code onto the stack

Stack

  • $ DUP
  • _ DROP
  • \ SWAP
  • @ ROT
  • ? PICK (duplicate the Nth stack item)

Variables

Programs can access an array of variables addressed with non-negative integers; the size of this array is implementation defined.

  • a-z put corresponding integer 0-25 onto the stack; emulates single-letter variable names
  • : store into a variable: value address:
  • ; read from a variable: address;

Arithmetic

  • +
  • -
  • *
  • /
  • % modulo
  • & bitwise AND
  • | bitwise OR
  • ~ bitwise NOT

Comparison

False is 0. True is all bits set (~0 or -1), so that bitwise NOT is equivalent to boolean NOT.

  • = equals
  • > greater than
  • < less than

Control Flow

  • {...} define and put a lambda onto the stack
  • ! execute lambda
  • (...) if block: condition(true) (any non-zero value is true)
    • if-else can be expressed as: condition$(true)~(false)
  • [...] loop
  • ^ break from loop
    • while loops can be expressed as: [condition~(^)body]
  • # continue (skip to next loop iteration)

I/O

  • . output value to port: value port.
  • , input value from port: port,
  • "string" output each character of a string sequentially to a port: port"string" (may contain embedded newlines and the escape sequences \", \\)

Ports 0-1 always have the following behavior; all other ports may be freely mapped for any I/O purpose by the particular implementation.

  • 0. write character to stdout
  • 0, read character from stdin (-1 for EOF)
  • 1. write value as decimal integer to stdout
  • 1, read decimal integer from stdin

Other

  • `...`: comment
  • whitespace is ignored, but may be needed to separate consecutive integers

Examples

Hello world!

0"Hello world!
"

Below is an alternative without the embedded newline. Note the k0. that prints the newline, where k is a shorter way to write 10 (ASCII for a newline).

0"Hello world!"k0.

Truth-machine

1,([1 1.])0 1.

The need for whitespace can be eliminated by replacing some integers with letters:

1,([b1.])a1.

Collatz sequence

1,a:
[
	a;2%0=$(
		a;2/a:
	)~(
		a;3*1+a:
	)
	a;1. k0.
a;2<(^)]

Shorter version which doesn't use variables:

1,[$2%0=$(\2/\)~(3*1+)$1.k0.$2<(^)]

99 bottles of beer

`
	implemenation from esolangs.org, translated from FALSE into vfl
	https://esolangs.org/wiki/FALSE#99_Bottles_of_Beer
`
99b:
{b;0=(0"No more bottles of beer")b;1=(0"1 more bottle of beer")b;1>(b;1.0" bottles of beer")}a:
[b;0=(^)a;!0" on the wall"k0.a;!k0.0"Take one down, pass it around"k0.b;1-b:a;!0" on the wall"k0.]

Computational class

vfl is Turing-complete, as the command subset $_\{}! is equivalent to the FALSE command subset $%\[]! which is known to be Turing-complete.

vfl's ability to access an "unbounded" array of memory may be a more obvious sign of the language's Turing-completeness, but this is only applicable if vfl values are assumed to be unbounded integers. The original documentation technically states that all values (which includes variable addresses) are 32-bit unsigned integers (though of course many programming languages don't provide such control over data types, so vfl implementations written in such languages may ignore this). This means that vfl programs running in implementations adhering to this cannot possibly address more than 8GB (2^31 variables * 4 bytes) of memory. On the contrary, vfl's main stack and call stack are not bounded in such a way.

External links