From 4ea1a5527e85bff0fc4694fe19926385db41922d Mon Sep 17 00:00:00 2001 From: Simon Forman Date: Mon, 15 Jul 2019 11:20:13 -0700 Subject: [PATCH] nullary combinator as definition. That eliminates all the recursive calls to thun/3 (outside of thun itself, which is tail recursive.) That means that this Joy interpreter is now fully CPS. All state is contained in the stack and expression, nothing is hidden in the Prolog "call stack". --- thun/thun.pl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/thun/thun.pl b/thun/thun.pl index bce598f..e1b98b5 100644 --- a/thun/thun.pl +++ b/thun/thun.pl @@ -83,8 +83,6 @@ literal(_/_). Functions */ -func(nullary, [P|S], [X|S]) :- thun(P, S, [X|_]). % Combinator. - func(cons, [A, B|S], [[B|A]|S]). func(swap, [A, B|S], [B, A|S]). func(dup, [A|S], [A, A|S]). @@ -159,6 +157,7 @@ ii ≡ [[dip], dupdip, i]. infra ≡ [swons, swaack, [i], dip, swaack]. make_generator ≡ [[codireco], ccons]. neg ≡ [0, swap, -]. +nullary ≡ [stack, popd, [i], infra, first]. of ≡ [swap, at]. pm ≡ [[+], [-], cleave, popdd]. popd ≡ [[pop], dip].