We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.

User:MarkFan8901/Sandbox

From Esolang
Jump to navigation Jump to search

FAI

FAI (short for Forth Artificial Intelligence) is a concatenative esolang made by User:MarkFan8901 which is intended to be used in wikipedia:linear genetic programming. The core of the language is inspired by the thought of how functions could be made to work in a GP context, and the idea of 'accidental' control flow (that is, operators which can still 'meaningfully' control the flow of a program, even in a completely random context).

Syntax

Words and numbers are separated by whitespace, as per usual. However, newlines aren't whitespace; they delimit functions, such that each line of a program is a function. Function calls (referred to as 'line calls') are written with a $ followed by the line number being called (starting from 1), for example $4. Comments are written within parentheses.

Words

Stack words

Word Signature Meaning
pop (a -- ) Pops the top value.
dup (a -- a a) Duplicates the top value.
over (a b -- a b a) Duplicates the second-top value.
swap (a b -- b a) Swaps the two top values.
rot (a b c -- b c a) Rotates the top three values.
2pop (a₂ -- ) Pops the top two values.
2dup (a₂ -- a₂ a₂) Duplicates the top two values.
... ... Etc. for the other stack words.

Arithmetic words

Word Signature Meaning
+ (a b -- a+b) Pushes the sum of a and b.
- (a b -- a-b) Pushes the difference of a and b.
* (a b -- a*b) Pushes the product of a and b.
/ (a b -- a/b) Pushes the quotient of a and b.
% (a b -- a%b) Pushes the remainder of a and b.
± (a -- sign(a)) Pushes 1 if a is positive, 0 if a is 0, and -1 if a is negative.

Comparison words

Word Signature Meaning
< (a b -- a<b) Pushes 1 if a is less than b, and 0 otherwise.
= (a b -- a=b) Pushes 1 if a is equal to b, and 0 otherwise.
> (a b -- a>b) Pushes 1 if a is greater than b, and 0 otherwise.
!< (a b -- a!<b) Pushes 0 if a is less than b, and 1 otherwise.
!= (a b -- a!=b) Pushes 0 if a is equal to b, and 1 otherwise.
!> (a b -- a!>b) Pushes 0 if a is greater than b, and 1 otherwise.
! (a -- !a) Pushes 1 if a is 0, and 0 otherwise.

Special words

Word Signature Meaning
empty ( -- a) Pushes an empty (see below).
sleep (a -- a?) If a is 0, pop it and ignore the next line call/sleep.

Semantics

Programs are executed by calling their last line.

The stack is initialized with an infinite number of empties. Empties are the lack of a value, and work as identity values in arithmetic (for example, anything times an empty is itself). Comparing anything with an empty also results in itself. ± and ! don't do anything to empties, however drop, dup, etc. do.

bla bla we'll finish this later

here have a truth machine as a treat

dup $1 (no i/o so dup is used for output instead)
sleep $1 0
0 $2 (replace 0 with your input)

weird fungelike

Command Meaning
0-9 multiply the top of the stack by 10 and add 0-9
/ divide by 9
\ divide by 11