mirror of
https://github.com/anoma/juvix.git
synced 2024-11-30 14:13:27 +03:00
98b1daec7d
Print JuvixCore InfoTable in such a way that it can be parsed back by the JuvixCore parser. * Depends on PR #1832 * Depends on PR #1862 * Closes #1841 * Adds "JuvixCore print" tests which read the files from Core/positive/*.jvc, print them, read them back and check if the evaluation results are preserved. --------- Co-authored-by: Jan Mas Rovira <janmasrovira@gmail.com>
39 lines
744 B
Plaintext
39 lines
744 B
Plaintext
-- builtin natural numbers
|
|
|
|
builtin def nat-plus := \x \y case x of {
|
|
zero := y;
|
|
suc x' := suc (nat-plus x' y);
|
|
};
|
|
|
|
def from_int := \n if n = 0 then zero else suc (from_int (n - 1));
|
|
|
|
def to_int := \x case x of {
|
|
suc x' := to_int x' + 1;
|
|
zero := 0;
|
|
};
|
|
|
|
def even := \x case x of {
|
|
suc x' := case x' of {
|
|
zero := false;
|
|
suc y := even y;
|
|
};
|
|
_ := true;
|
|
};
|
|
|
|
def f := \x case x of {
|
|
suc x' := (\z case z of {
|
|
zero := even x';
|
|
suc y := f y;
|
|
}) x';
|
|
_ := even x;
|
|
};
|
|
|
|
def writeLn := \x write x >> write "\n";
|
|
|
|
def main :=
|
|
writeLn (to_int (if even (from_int 124) then nat-plus (suc zero) (suc (suc zero)) else zero)) >>
|
|
writeLn (to_int (nat-plus (from_int 126) (from_int 10))) >>
|
|
writeLn (f (from_int 65));
|
|
|
|
main
|