🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #2653

Re: cut for meta-interpreter

#2653
From: raf
Date: Fri, 24 Apr 1987 19:00
57 lines
2177 bytes
> Does anybody know how to implement PROLOG meta-circular interpreter
> with cut without using ancestor cut? Is there a clean way to implement
> (both at PROLOG level and at meta-interpreter level) ancestor cut?
> 

% I have solved the question I have posed, so never mind.
% Here is the meta-circular PROLOG interpreter which includes 
% both "cut" and "ancestor cut". (For explanation of what
% "ancestor cut" is see Sterling and Shapiro book
% "the art of prolog"). A proof of correctness is going
% to appear elsewhere.

%----------------------------------------------------------
% meta-circular interpreter which includes 
% "cut", "ancestor cut", "or" and "not" at the meta-level. 
%----------------------------------------------------------
% Author: Rafail Ostrovsky                    4/23/1987
%----------------------------------------------------------
%
solve(G) :- solve(G,_).
solve(!,X) :- var(X);X=cut.
solve(ancestor_cut(Pred),X) :- var(X);X=Pred.
solve(not(A),C) :- not solve(A,C).
solve((A,B),C) :- solve(A,C),solve(B,C).
solve((A;B),C) :- solve(A,C);solve(B,C).
solve(A,C) 
  :-  nonvar(C);
      (system_pred(A),!,A);
      (  clause(A,B),
         solve(B,C1),
         (  var(C1); 
            (nonvar(C1),functor(A,C1,_),!,fail); 
            (C1==cut,!,fail); 
            (nonvar(C1),C=C1))).

system_pred(clause(_,_)).
system_pred(true).
system_pred(solve).
%----------------------------------------------------------
Example:

test(X) :- p(X),q(X).
test(X) :- q(X).

p(1).
p(2).
p(3) :- ancestor_cut(test).
p(4).

q(1).
q(2).
q(3).
q(4).

?- solve(test(X)) will succeed with X = {1,2,3}.

/raf
Technical Details
Message-ID: <6937@bu-cs.BU.EDU>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!rutgers!mit-eddie!bu-cs!raf

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!rutgers!mit-eddie!bu-cs!raf
From: raf@bu-cs.UUCP
Newsgroups: comp.lang.prolog
Subject: Re: cut for meta-interpreter
Message-ID: <6937@bu-cs.BU.EDU>
Date: Fri, 24-Apr-87 14:00:14 EST
Article-I.D.: bu-cs.6937
Posted: Fri Apr 24 14:00:14 1987
Date-Received: Sat, 25-Apr-87 19:28:00 EST
Organization: Boston U. Comp. Sci.
Lines: 57
Keywords: cut,ancestor cut,meta-interperter
Summary: solution