Fargo

From Esolang
Jump to navigation Jump to search

Fargo (Function argument-o) is an esolang created by User:PythonshellDebugwindow.

Overview

Fargo is a functional esolang. Each line is either a function definition, a function call, a blank line, or a comment.

Memory

Fargo uses an input number, an integer which is defined by the interpreter (typically to be a user-input number) before the program begins. It also uses an output number, which can be output at any time in the program.

Syntax

Function calls

A function can be called by typing its name followed by a space, then its (space-separated) arguments, which are evaluated from left to right.

Function definitions

Function definitions are rather unorthodox in Fargo. Each definition takes up exactly one line (excluding comments). The first token of a function definition is its name (redefining an existent function is an error); the rest of the tokens are its arguments and its code. The divide between arguments and code is fairly unusual: the first defined name is the first code token, and the previous token is the final argument. Defined names are built-in functions, user-defined functions (including the function being defined), and the arguments of the function currently being defined.

Functions must contain exactly one outer function call (e.g., myFn x y z otherFn x thirdFn ​y z is legal while myFn x y z otherFn x y z anotherFn x and myFn are not; even though the first example calls thirdFn, it doesn't do so at the top level).

Colons

If a token begins with a : colon, it either represents a raw function (as opposed to a function call), which can be used as an argument to a function, if it is not a function argument; or marks a function argument as being a raw function, rather than a value.

Literals

Literals are binary integers matching the regex /[0-1]+/.

Comments

Comments are declared by using #, and last until the end of the line.

Built-in functions

  • < x returns x right-shifted by 1
  • > x returns x left-shifted by 1
  • & x y returns x bitwise-AND y
  • | x y returns x bitwise-OR y
  • ^ x y returns x bitwise-XOR y
  • [] x returns an array with only x in it
  • +[] x y returns the array x concatenated with the array y
  • [?] x y returns the yth element of the array x
  • @ x returns the xth bit of the input number (LSB = 0th bit)
  • % x y sets the xth bit of the output number to y (LSB = 0th bit)
  • $ outputs the output number in base-10
  • : x y does y iff x is unequal to zero

Examples

Truth-machine

one ​^ $ one
​% 0 @ 0
: @ 0 one
$