From ea356a539aa2bff831b9a64f1ba0913f63840d19 Mon Sep 17 00:00:00 2001 From: Simon Forman Date: Tue, 5 May 2020 15:52:40 -0700 Subject: [PATCH] `primrec` combinator in Prolog Ticket #40375 --- thun/thun.pl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/thun/thun.pl b/thun/thun.pl index aa6190a..f4699f7 100644 --- a/thun/thun.pl +++ b/thun/thun.pl @@ -372,6 +372,15 @@ combo(genrec, [R1, R0, Then, If|S], [ Else, Then, If|S], E, [ifte|E]) :- append(R0, [[If, Then, R0, R1, symbol(genrec)]|R1], Else). +combo(primrec, [list(_), list(B), int(N)|S], S, E, Eo) :- + N #=< 0, + append(B, E, Eo). +combo(primrec, [list(R), list(B), int(N) |S], + [list(R), list(B), int(M), int(N)|S], E, Eo) :- + N #> 0, + M #= N - 1, + append([symbol(primrec)|R], E, Eo). + /* This is a crude but servicable implementation of the map combinator.