Far

From Esolang
Jump to: navigation, 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 a single value.

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>
 ...
Q

and then called with

$<id>

Functions share the stack, but have their own registers which are initialised to the main program registers.

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.

External resources