FOSMOL

From Esolang
Jump to navigation Jump to search
FOSMOL
Paradigm(s) procedural
Designed by User:Aadenboy
Appeared in 2025
Memory system array-based
Dimensions one-dimensional
Computational class Total
Reference implementation Unimplemented

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 real 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

Irrationals

Certain irrationals are available for use.

  • π
  • e
  • Φ

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
log Logarithm of a number. 100 log 10 = 2
N-th root of a number. 2√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
sin Sine of a single number. sin π = 0
cos Cosine of a single number. cos π = -1
tan Tangent of a single number. tan π = 0
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]

 0 [ 1   2   3 ]
 0 + 1   2   3
     1 + 2   3
         3 + 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.

A fold operation that returns more than one array will instead return an array of the same length with each element modified in relation to the previous one.

ƒ(λpn.[p][p+1]) 0 [1 8 9 3 2 5 0 4] = [1 2 3 4 5 6 7 8]

   0 [ 1   8   9   3   2   5   0   4 ]
 λ(0   1)  8   9   3   2   5   0   4
   0 λ(1   8)  9   3   2   5   0   4
   0   1 λ(2   9)  3   2   5   0   4
   0   1   2 λ(3   3)  2   5   0   4
   0   1   2   3 λ(4   2)  5   0   4
   0   1   2   3   4 λ(5   5)  0   4
   0   1   2   3   4   5 λ(6   0)  4
   0   1   2   3   4   5   6 λ(7   4)
     [ 1   2   3   4   5   6   7   8 ]

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]

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

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

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

 [ 1   3   5 ]
 [ 4   6   8 ]
 +(1)  3   5
  (4)  6   8
   5 +(3)  5
      (6)  8
   5   9 +(5)
          (8)
 [ 5   9   13 ]
   

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

µ(λx.x*2) [1 2 3] [4 5 6] = [1 2 3 4 5 6]
 
 [ 1   2   3 ] [ 4   5    6 ]
 λ(1)  2   3     4   5    6
   2 λ(2)  3     4   5    6
   2   4 λ(3)    4   5    6
   2   4   6   λ(4)  5    6
   2   4   6     8 λ(5)   6
   2   4   6     8   10 λ(6)
 [ 2   4   6     8   10   12 ]

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 µ(λy.1) x      // length: # [1 2 3] = [3]
d x := µ(λy.[y][y]) x      // duplicate items: d [1 2 3] = [1 1 2 2 3 3]
" x := x x                 // duplicate list
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)
E x := ƒ(λpn.[p][p+1]) 0 x      // enumerate: E [1 5 7 8 0] = [1 2 3 4 5]
n index list := ∑ µ* (µ(λy.y=index) E list) list // Nth element in list: n [5] [5 0 9 1 8 2 3] = [8]
_ x := ƒ- (n 1 x)*2 x // subtraction fold with working starting element: _ [3 2 1] = [0]

Example operations

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