musique/examples/church.mq
Robert Bendun 6bc2a1cd38 Context aware clojures
Moved from dynamic scoping to static scoping.
2022-05-22 03:44:15 +02:00

39 lines
979 B
Plaintext

-- PAIR definition
var pair = [x y | [z | z x y]];
var car = [p | p [x y | x]];
var cdr = [p | p [x y | y]];
var x = pair 100 200;
say (car x);
say (cdr x);
-- This two values should be builtin, but currently is not
var true = (1 == 1);
var false = (1 != 1);
-- LIST definition
var null = pair true true;
var is_empty = car;
var head = [list | car (cdr list)];
var tail = [list | cdr (cdr list)];
var cons = [head tail | pair false (pair head tail)];
var for_each = [list iterator |
if (is_empty list) [| nil ] [|
iterator (head list);
for_each (tail list) iterator ]];
var map = [list iterator |
if (is_empty list) [| null ] [|
cons (iterator (head list)) (map (tail list) iterator) ]];
var foldr = [list init folder |
if (is_empty list)
[| init ]
[| foldr (tail list) (folder (head list) init) folder ]];
var range = [start stop | if (start >= stop) [|cons start null] [|cons start (range (start+1) stop)]];
var xs = range 1 5;
say (foldr xs 1 [x y|x*y]);