| OCR Text |
Show I* ------------------ Sample Funlog Programs ---------------- *I I* definition for if- then - else *I cond(true, X, Y) ==> X. cond(false, X, Y) ==> Y. I* the function reductions are supported directly *I generator(N) ==> N ~ generator(s(N)). select(O, L) ==> [] . select(s(N), A~ L) ==>A~ select(N, L). first_n(N) ==> select(N, generator(O)). I* to invoke the interpreter, type a goal, for example *I ?:- reduce(first_n(s(s(s(O)))), L). I* Call it from Funlog top level *I I* A goal is a list of atomic formulas. *I I* Parentheses can be omitted when it is a single formula. *I ?:- funlog( reduce(first_n(s(s(s(O)))), L) ). I* the user can direct the interpreter to do simplication by *I I* explicitly replacing the predicate "reduce" at the place *I I* he or she wants a function term to be reduced. For example, *I I* since the process of answer-collector is not built into *I I* the interpreter, if the user wants the bindings under *I I* concern to be simplified, he can do so. The following *I I* example illustrates this *I same(X, X). ?:- funlog( (same(plus1(plus1(0)), Y), reduce(Y, Answer)) ) . I* The Lucky Numbers problem presented in Section 6.3 *I gen(N) ==> N ~ gen(s(s(N))). sift(M ~ L, N) ==> M ~ sift(sieve(L, M, N), s(N)). sieve(A ~ L, M, N) ==> cond(eq(M, N), sieve(L, M, s(O)), A ~ sieve(L,M, s(N))). truncate(O, Infinite, []). truncate(s(N), A ~ Infinite, A ~ Finite) truncate(N, Infinite, Finite). 138 |