Far

From Esolang
Jump to navigation Jump to search
Far
Paradigm(s) imperative
Designed by User:GibsonGeorge
Appeared in 2018
Computational class Turing complete
Major implementations Reference
File extension(s) .far

Far is a stack-based esoteric programming language designed to have many higher-level functions, yet still take a long time to write simple programs in. All programs are made up of a series of 1 character commands, and most will also use expressions to allow more complex tasks to be written.

Overview

In Far, data can be stored in two places: the stack or a register. The stack is an infinitely-large (bound by memory) series of basic types; there are three registers (R1, R2, and R3) and they can each hold one of each of the basic types.

There are three basic types in Far, which are (almost) the only data structures:

Octet A byte
Number An integer
Boolean A truthy/falsey value

Far also supports strings, which are sequences of bytes enclosed in double-quotes. Strings can be stored in registers, but cannot be pushed to the stack.

An if statement uses the syntax

?
 ...
q

(... will only be executed if Stack0 is true)

Functions are declared using a similar syntax of

@<id> <arity>
 ...
q

and then called with

$<id> [args]

Functions share the stack, but have their own registers which are initialised to the arguments passed (argument 1 -> R1, argument 2 -> R2, etc.)

Commands

Command Function
p <value> Push <value> to the stack
g Get the top element of the stack
d Delete the top element of the stack
c<n> Cycle the top <n> elements of the stack
e Empty the stack
s <r> <value> Set register <r> to <value>
%<r> Get the value of register <r>
t <r> <type> Set register <r> to type <t>
r <value> Return <value> (function only)
q Terminate the current block
o Write the top element of the stack to STDOUT
i Read a line from STDIN (string)
'<char> Gets the hex value of <char>. <char> must be a printable ASCII character
l Declare a label
j Jump to the most recent label
! Returns NOT Stack0
& Returns Stack0 AND Stack1
Returns Stack0 OR Stack1
^ Returns Stack0 XOR Stack1
= Returns true if Stack0 equals Stack1, false otherwise
+ Returns Stack0 + Stack1
- Returns Stack1 - Stack0

Any unrecognised character should be ignored.

Examples

Hello, World!

This program prints the string "Hello, world!"

p '!
p 'd
p 'l
p 'r
p 'o
p 'W
p x20
p ',
p 'o
p 'l
p 'l
p 'e
p 'H
ododododododododododododod

It is possible to write a print function, but doing so would take longer than manually pushing the string.

Print function

@1 1
	s R2 0
	l1
	p :%R2%R1
	o
	d
	p %R2
	p 1
	s R2 +
	d
	d
	p X00
	p :%R2%R1
	p =
	p !
	?
		d
		d
		d
		d
		j1
	q
	d
	d
	d
	d
	p X0A
	o
	d
q

External resources