Thread View: net.lang.prolog
1 messages
1 total messages
Started by Ran Ever-Hadani
Sun, 31 Aug 1986 12:24
Answer to fixed-points query of #41
Author: Ran Ever-Hadani
Date: Sun, 31 Aug 1986 12:24
Date: Sun, 31 Aug 1986 12:24
46 lines
1948 bytes
1948 bytes
In pure prolog, it is not possible to construct a single clause, self/1 with non-empty body that yields any answer to a query; it can either fail or go into infinite loop. If the clause is Head:-Body then the initial goal is Head, and no reduction can ever produce the empty goal. self/1 with no body is also not possible, since it will have to contain itself. The sollution below is a procedure is self/2, which contains two clauses and is true when fed these clauses as parameters. self(Y,self(Y,0)) :- self(Y,0). self((self(Y,self(Y,0)):-self(Y,0)),0). This it not perfect, since if we ask ?- self(A,B). then apart from A=.. clause1 .. B=.. clause2 .. which is the sollution we want, we also get A=.. clause1 .. B=0 (by unifying directly to clause2). This can only be avoided using a cut (which is not pure prolog) as shown in a slightly different version of self/2 below: Script started on Sun Aug 31 14:58:20 1986 % cprolog C-Prolog version 1.4a | ?- [user]. | | self(Y,self(Y,0)) :- self(Y,0), !. | | self((self(Y,self(Y,0)):-self(Y,0),!),0). | ^D user consulted 416 bytes 0.116667 sec. yes | ?- self(A,B). A = self(_9,self(_9,0)):-self(_9,0),! B = self((self(_9,self(_9,0)):-self(_9,0),!),0) ; no | ?- ^D [ Prolog execution halted ] % Script done on Sun Aug 31 14:59:33 1986 -- Ran Ever-Hadani raan@techunix.BITNET
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads