Flux (Esolangist)

From Esolang
Jump to navigation Jump to search

Flux is a 2D esolang by User:Esolangist.

Flux (Esolangist)
Paradigm(s) Imperative
Designed by User:Esolangist
Appeared in 2025
Memory system Stack-based
Dimensions Two dimensional
Computational class Unknown
Reference implementation Unnamed implementation in Common Lisp
Influenced by Befunge
File extension(s) .flux, .flx

Syntax

A Flux program's conformation ensues from the notion of the Befunge playfield: a two-dimensional Cartesian grid of characters, these either serving as instructions, the arguments of which are obtained from the memory stack, or, if not assigned to a particular purpose, representing no-operations (NOPs).

The playfield designates its cells via zero-based x-y-coordinates, the upper left corner entertaining the origin point (0, 0), with the x-axis augmenting towards the dextral side, and the y-axis incrementing downwards. Coordinates outside of these boundaries wrap around along the respective edges to the obverse side.

Inwith this structure, an instruction pointer (IP), endowed with both a bidimensional location, and a direction, operates; its former attribute assumes, at the execution's inchoacy, the point (0, 0), the latter a sinistrodextral perambulation. If traversing beyond a grid edge, the instruction pointer wraps around to the other side, without a modulation in the second axis.

Memory

Flux employs a stack of signed integer numbers, imposing no bournes in their magnitude, for the data storage. Consanguinous to Befunge, this stack, if empty, responds to any request with a zero (0) value.

Commands

The following tabulation shall ostend the available commands and their causata:

Command Effect Stack modification (bottom ◀ top)
NAVIGATION
v Redirects the instruction pointer downwards.  
^ Redirects the instruction pointer upwards.  
< Redirects the instruction pointer leftwards.  
> Redirects the instruction pointer rightwards.  
[ Pops the top of the stack; if this element equals 0, redirects the instruction pointer leftwards; otherwise does not apply any effect. xT → ∅
] Pops the top of the stack; if this element equals 0, redirects the instruction pointer rightwards; otherwise does not apply any effect. xT → ∅
( Pops the top of the stack; if this element equals 0, redirects the instruction pointer upwards; otherwise does not apply any effect. xT → ∅
) Pops the top of the stack; if this element equals 0, redirects the instruction pointer downwards; otherwise does not apply any effect. xT → ∅
- Reflects the instruction pointer on a horizontal mirror: If the pointer is currently traversing upwards, the direction is set to downwards; if it moves downwards, the new direction constitutes upwards; otherwise does not apply any effect.  
| Reflects the instruction pointer on a vertical mirror: If the pointer is currently traversing leftwards, the direction is set to rightwards; if it moves rightwards, the new direction constitutes leftwards; otherwise does not apply any effect.  
? Randomly assigns a direction to the instruction pointer.  
NUMERICAL OPERATIONS
0 Pushes the number 0 onto the stack ∅ → 0
1 Pushes the number 1 onto the stack ∅ → 1
2 Pushes the number 2 onto the stack ∅ → 2
3 Pushes the number 3 onto the stack ∅ → 3
4 Pushes the number 4 onto the stack ∅ → 4
5 Pushes the number 5 onto the stack ∅ → 5
6 Pushes the number 6 onto the stack ∅ → 6
7 Pushes the number 7 onto the stack ∅ → 7
8 Pushes the number 8 onto the stack ∅ → 8
9 Pushes the number 9 onto the stack ∅ → 9
r Pushes a random integer number x, with 0 ≤ x ≤ 255, onto the stack ∅ → x
ARITHMETIC OPERATIONS
+ Pops the top stack element, a, the new top stack element b, pushes the result of (b + a) onto the stack. b a(b+a)
S Pops the top stack element, a, the new top stack element b, pushes the result of (b - a) onto the stack. b a(b-a)
* Pops the top stack element, a, the new top stack element b, pushes the result of (b * a) onto the stack. b a(b*a)
/ Pops the top stack element, a, the new top stack element b, pushes the result of (b / a) onto the stack. If the divisor a equals 0, an abortive error entailing the message Don't divide by 0 is signaled. b a(b/a)
% Pops the top stack element, a, the new top stack element b, pushes the result of (b modulo a) onto the stack. If the divisor a equals 0, an abortive error entailing the message Don't divide by 0 is signaled. b a(b%a)
LOGICAL OPERATIONS
= Pops the two top stack elements; if these are are equal, pushes the value 1, otherwise pushes 0. b a(0 or 1)
! Pops the top stack element; if it equals 0, pushes the value 1, otherwise pushes 0. a(0 or 1)
STACK MANIPULATION
~ Pops and discards the top stack element. a → ∅
: Duplicates the top stack element. aa a
x Pops the top stack element, n, and duplicates the n top values. x1 x2xn nx1 x2xn x1 x2xn
$ Swaps the two top stack elements. x1 x2x2 x1
{ Rotates the stack up. x1 x2 x3x3 x1 x2
} Rotates the stack up. x1 x2 x3x2 x3 x1
c Clears the stack. x1 x2xn → ∅
INPUT AND OUTPUT
. Pops the top element a and prints it in its numeric form. a → ∅
, Pops the top element a and prints the character whose ASCII code matches its value. a → ∅
& Queries the standard input for a signed or unsigned integer number a and pushes it onto the stack. ∅ → a
' Queries the standard input for a character a and pushes its ASCII code onto the stack. ∅ → a
" Toggles the string mode: Pushes the ASCII code of every character x1 through xn betwixt this and the next " token onto the stack, excluding the terminating " symbol from this insertion. Please heed that this replicates the character codes in their reverse order on the stack. ∅ → x1 x2xn
STACK-PLAYFIELD COOPERATION
g Pops the top stack element x and the new top element y, retrieves the character in the playfield located at the coordinates (x, y), and pushes its ASCII code onto the stack. y x(playfield[x,y])
p Pops the top stack element x, the new top element y, and the subsequent new top item z, and writes the character whose ASCII code matches the value of z to the playfield cell amenable to the coordinates (x, y). z y x → ∅
CONTROL FLOW
# Skips the next instruction.  
£ Peeks, without removing, the top stack element a; if the same does not equal 0, skips the next instruction; otherwise applies no further effect. aa
j Pops the top stack element x and the new top element y, and relocates the instruction pointer to the playfield cell located at the coordinates (x, y). y x → ∅
m A NOP, but useful for a return via the R, which please consult below.  
R Returns to the most recently encountered m instruction, while retaining the instruction pointer's direction.  
l Peek without removing the top stack element a; if the same equals 0, moves forward past the next e symbol on the playfield; otherwise advances as usual. aa
e Peeks without removing the top stack element a; if the same equals 0, moves back to the matching l symbol on the playfield; otherwise advances as usual. aa
@ Immediately halts the program.  

Examples

Hello world

This program issues the message “Hello, World!” to the standard output:

>0"!dlroW ,olleH"l,e@

A second variant harnesses the wrapping behavior along the playfield edges for its obviation of the actually requisite reversed string replication:

<v"Hello, World!"
 >l,e@

Cat

This cat program perpetuates until a null character has been committed:

>'l:,'e@

Truth machine

This one by User:Esolangist uses m and R.

&m£vv
 l 0R
 1 .
 :  
 . @
 e

XKCD random number

>4.@
Chosen by fair dice roll
Guaranteed to be random

Random Number Generator

The following piece of code prints a random integer number from the closed interval [1, 4]:

>32j
> > >v
  2  v
^1?3 >.@
  4  ^
  > >^

Random ASCII Text

This program selects in an aleatory fashion eight characters from the extended ASCII range [0, 255] and prints these:

24*lr,1Se@

Interpreter

  • Common Lisp implementation of the Flux programming language. Please note that the concrete character set deployed constitutes a dependency on the Common Lisp implementation; in corollary, Unicode support may or may not be a feature incorporated in the personal environment. The interpreter at hand has been developed and tested with Steel Bank Common Lisp (SBCL) version 1.1.4 as part of the Lisp Cabinet 0.3.5 bundle.