Article View: comp.lang.prolog
Article #759Re: Compilation of Disjuncts
From: Micha Meier
Date: Thu, 03 Sep 1992 08:08
Date: Thu, 03 Sep 1992 08:08
60 lines
2587 bytes
2587 bytes
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 This method is used e.g. by (as far as I know) Quintus and Sepia and others. Both methods have advantages and disadvantages. I think the latter is more efficient, because no additional environment is created for the auxiliary procedures and the disjunction choice point has always arity zero. There might as well be less branches to make. On the other hand, the former method can be easily done on the Prolog level with a preprocessor, so it is quite easy (well, modulo cut and the like) to do. The in-line expansion, especially if one wants to improve special cases like not/1, once/1 and if-then-else with a simple condition, can very quickly turn into a dangerous adventure. --Micha --- Micha Meier ------------------------------------------------ ECRC, Arabellastr. 17 The opinions expressed above are private D-8000 Munich 81 and may not reflect those of my employer. micha@ecrc.de, Tel. +49-89-92699-108, Fax +49-89-92699-170
Technical Details
Message-ID:
<1992Sep3.080802.21788@ecrc.de>Path:
arc1-ca.pugleaf.net!sparky!uunet!mcsun!Germany.EU.net!ecrc!acrab6!michaReferences:
<MATSC.92Sep2141625@vishnu.sics.se>Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.prolog Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!Germany.EU.net!ecrc!acrab6!micha From: micha@ecrc.de (Micha Meier) Subject: Re: Compilation of Disjuncts Message-ID: <1992Sep3.080802.21788@ecrc.de> Sender: news@ecrc.de Reply-To: micha@ecrc.de Organization: European Computer-Industry Research Centre References: <MATSC.92Sep2141625@vishnu.sics.se> Date: Thu, 3 Sep 1992 08:08:02 GMT Lines: 61