🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #763

Re: Compilation of Disjuncts

#763
From: Mats Carlsson
Date: Thu, 03 Sep 1992 15:52
54 lines
2273 bytes
In article <1992Sep3.080802.21788@ecrc.de> micha@ecrc.de (Micha Meier) writes:

   In article 92Sep2141625@vishnu.sics.se, matsc@sics.se (Mats Carlsson) writes:
   >   do you do anything special about this construct, or do you just
   >   consider it as an ordinary predicate with a definition like:
   >   P ;_Q :- P.
   >   _P; Q :- Q.
   >
   >SICStus Prolog does nothing special, and considers it as an ordinary
   >predicate as you describe.

   I guess this is slightly understated, because that would mean that all goals
   inside a disjunction are metacalled, which is not the case in SICStus.

   There are two basic ways to compile the disjunctive constructs, one is with
   auxiliary procedures and the other in-line. If you have a clause

	   p(X, Y) :- q, (r(X); s(Y)), t.

   then the former method (used e.g. in SICStus, KCM, ...) is to transform it into

	   p(X, Y) :- q, aux(X, Y), t.

	   aux(X, _) :- r(X).
	   aux(_, Y) :- s(Y).

   (in case there is a cut involved, one might need to pass additional information
   to aux/2).

   The other method is done at the WAM level, the WAM code looks something like

	   allocate
	   get_variable Y1, A1
	   get_variable Y2, A2
	   call q/0
	   try_me_else L1
	   put_value Y1, A1
	   call r/1
	   branch L2
   L1:	trust_me
	   put_value Y2, A1
	   call s/1
   L2:	deallocate
	   execute t/0

Micha is absolutely right, SICStus of course uses the first method.
I misread the original posting.

The second method would not be readily applicable, since the SICStus
emulator does not have try/retry/trust instructions.
--
Mats Carlsson
SICS, PO Box 1263, S-164 28  KISTA, Sweden    Internet: matsc@sics.se
Tel: +46 8 7521543     Ttx: 812 6154 7010 SICS     Fax: +46 8 7517230
Technical Details
Message-ID: <MATSC.92Sep3165246@vishnu.sics.se>
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!sunic!sics.se!matsc
References: <MATSC.92Sep2141625@vishnu.sics.se> <1992Sep3.080802.21788@ecrc.de>

Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.prolog
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!sunic!sics.se!matsc
From: matsc@sics.se (Mats Carlsson)
Subject: Re: Compilation of Disjuncts
In-Reply-To: micha@ecrc.de's message of Thu, 3 Sep 1992 08:08:02 GMT
Message-ID: <MATSC.92Sep3165246@vishnu.sics.se>
Sender: news@sics.se
Organization: Swedish Institute of Computer Science, Kista
References: <MATSC.92Sep2141625@vishnu.sics.se> <1992Sep3.080802.21788@ecrc.de>
Date: Thu, 3 Sep 1992 15:52:46 GMT
Lines: 54