FOSMOL

From Esolang
Jump to navigation Jump to search

FOSMOL (an acronym that stands for Fold Operator Start Map Operator List) is a total esolang created by User:Aadenboy.

Values

FOSMOL operates on lists of numbers. These lists can be assigned to a variable, which becomes immutable immediately after definition.

var = [1 2 3] // list of 3 numbers
foo = [5]     // list of one number, also a single number
bar = []      // invalid

Operations

Lists can be operated on by folding and mapping to produce a new list.

Basic operations

Basic operations are used by lambdas, foldings and mappings.

Operator Description Example
+ Addition of two numbers. 5 + 4 = 9
- Subtraction of two numbers, or unary negation. 5 - 4 = 1
* Multiplication of two numbers. 5 * 4 = 20
/ Division of two numbers. 5 / 4 = 1.25
² Square of a number. 3² = 9
Square root of a number. √9 = 3
% Modulus of two numbers. 5 % 4 = 1
Floor of a single number. ⌊5.9 = 5
Ceiling of a single number. ⌈5.1 = 6
Return the MINIMUM of two numbers—logical AND with 0 and 1. 0 ∧ 1 = 0
Return the MAXIMUM of two numbers—logical OR with 0 and 1. 0 ∨ 1 = 1
= Return 1 if the two are equal, and 0 if they are not. 5=5 = 1
> Return 1 if the left number is greater than the right, and 0 if it isn't. 6>5 = 1
< Return 1 if the left number is smaller than the right, and 0 if it isn't. 6<5 = 1
¬ Return 1 if the number is 0, and 0 if it isn't. ¬1 = 0

Lambdas

Lambdas are used by both folding and mapping, with the syntax λ<args>.<expression>.

You can apply a lambda within a list via the syntax (λ<args>.<expression>)⇒(<args>).

A lambda may return a list itself, which will be expanded to its individual values. It may also return multiple lists.

Folding

Folding (or reducing) allows an operation or lambda to be repeatedly applied to a list until there is only one value left.

ƒ+ 0 [1 2 3] = [6]

ƒ is the "fold" function, + is the operation being repeatedly applied, 0 is the starting value, and [1 2 3] is the list being folded.

Mapping

Mapping allows an operation or lambda to be applied to each element in a list. Mapping also works on multiple lists, for binary operations or multi-argument lambdas.

µ² [1 2 3] = [1 4 9]

µ is the "map" function, ² is the operation being applied, and [1 2 3] is the list being mapped.

µ+ [1 3] [4 6] = [5 9]

If a lambda has less or more arguments than there are lists, it will go through each list iteratively.

µ(λx.x) [1 2 3] [4 5 6] = [1 2 3 4 5 6]

Macros

Macros can be defined, which will be expanded into its expression.

∑ x := ƒ+ 0 x

This allows you to use as a macro.

∑ [1 2 3] => ƒ+ 0 [1 2 3] = [6]

Macros cannot be recursive—you may not set them up in any way that would cause infinite expansion.

Example macros

∑ x := ƒ+ 0 x             // summation: ∑ [1 2 3] = [6]
∏ x := ƒ* 0 x             // product: ∏ [4 5 6] = [120]
# x := ƒ+ 0 µ(λx.1) x      // length: # [1 2 3] = [3]
d x := µ(λx.[x][x]) x      // duplicate items: d [1 2 3] = [1 1 2 2 3 3]
x̄ x := µ(λy.y / (# x)) ∑ x // average of list: x̄ [3 5 10] = [6]
≅ x y := ƒ∧ 1 µ= x y       // congruency (lists are the same): ≅ [1 2 2] [1 2 3] = [0] (false)

Example operations

This is still a work in progress. It may be changed in the future.