[personal profile] codedot
The `test.mlc' file changed in MLC source codes. Now it represents sample syntactic sugar defined in a different way than earlier. Namely, the new version aims at more readable and transparent form of basic combinators. For each definition, there have also been added comments meant to provide some rationale.

--- Identity, the simplest combinator
I = x: x;

--- Select either first or second
TRUE = first, second: first;
FALSE = first, second: second;

--- If cond1 then cond2 else FALSE
AND = cond1, cond2: cond1 cond2 FALSE;
--- If cond1 then TRUE else cond2
OR = cond1, cond2: cond1 TRUE cond2;
--- Swap arguments for TRUE to become FALSE and vice versa
NOT = cond: (first, second: cond second first);

--- Pair of head and tail
LIST = head, tail: (x: x head tail);
--- List operations are postfix
LISTOP = op: (list: list op);
--- Select first part of pair
HEAD = LISTOP TRUE;
--- Select second part of pair
TAIL = LISTOP FALSE;
--- Ignore both parts of pair and return FALSE
NULL = LISTOP (first, second: FALSE);
--- Pseudo-list that ignores list operation and returns TRUE
NIL = x: TRUE;

--- Lists of identity terms ended with NIL
N0 = NIL;
N1 = LIST I N0;
N2 = LIST I N1;
N3 = LIST I N2;
N4 = LIST I N3;
--- Increment list length
SUCC = LIST I;
--- Decrement list length
PRED = TAIL;
--- If N0 then TRUE else FALSE
ZERO = NULL;

--- Fixed point combinator by Turing
A = self, func: func (self self func);
Y = A A;

--- Addition defined recursively for any numeral system
PLUSR = self, m, n: (ZERO m) n (SUCC [self {PRED m} n]);
PLUS = Y PLUSR;
--- Multiplication define recursively for any numeral system
MULTR = self, m, n: (ZERO m) N0 (PLUS m [self {PRED m} n]);
MULT = Y MULTR;
--- Traditional factorial function example
FACTR = self, n: (ZERO n) N1 (MULT n [self {PRED n}]);
FACT = Y FACTR;

--- Evaluate factorial of four
FACT N4

Profile

Anton Salikhmetov

November 2018

S M T W T F S
    123
45678 910
11121314151617
18192021222324
252627282930 

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Sep. 20th, 2025 06:37 pm
Powered by Dreamwidth Studios