Article View: comp.lang.prolog
Article #3385NU-Prolog "pure" declarations
From: Lee Naish
Date: Thu, 19 May 1988 02:37
Date: Thu, 19 May 1988 02:37
59 lines
2827 bytes
2827 bytes
> tell us more about what declaring a predicate "pure" in
>NU-Prolog means and does? How much is assumed, how much checked?
Declaring a predicate pure takes away meaning rather than adding it.
Without pure declarations predicates have a procedural meaning and
(possibly) a declarative one. Predicates which are declared pure have
no well defined procedural meaning (and if they use non-logical predicates
such as cut, var and assert they have no meaning :-). The compiler
doesnt check for "pure" predicates calling non-logical predicates but
"nit" (a program checker like lint) does so.
Currently, pure declarations do not have much effect. They result in a
slightly different transformation of clause bodies containing constructs
relating to negation. An example appears in "Parallelizing NU-Prolog":
% check list of clauses in cl/4 form can be made deterministic:
% for all clause heads H, all previous clauses PrevCL whose
% heads HP unify with H must have cuts
?- pure check_det/1. % enable optimization
check_det(CL) :-
all PrevCL.H.HP.GP
( append(PrevCL, cl(H, _, _, _)._, CL),
member(cl(HP, _, GP, _), PrevCL),
unify(H, HP)
)
=>
GP ~= $nocut.
Without the pure declaration the body would be transformed into
the following (plus some code to delay it until CL is ground):
\+ ( append(PrevCL, cl(H, _, _, _)._, CL),
member(cl(HP, _, GP, _), PrevCL),
unify(H, HP),
\+ GP ~= $nocut
).
With the pure declaration it is transformed into
\+ ( GP = $nocut,
append(PrevCL, cl(H, _, _, _)._, CL),
member(cl(HP, _, GP, _), PrevCL),
unify(H, HP)
).
Some time is saved by removing the "double negation" and potentially
much more time is saved by reordering the conjuncts so failure occurs
before unify/2 is called. Unify/2 uses $VAR(N) to represent variables
so it is relatively expensive.
(Astute readers will note that the use of $nocut indicates BAD DATA
STRUCTURE DESIGN.)
When declarations are also used by a preprocessor (nac) which adds
control information to NU-Prolog programs. It reorders clause bodies
and adds when declarations (which cause suspension of calls). Since
these changes are not always desirable (especially with non-logical
code), nac only changes predicates with pure declarations.
Lee Naish
Technical Details
Message-ID:
<2777@mulga.oz>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!munnari!mulga!leeReferences:
<983@cresswell.quintus.UUCP> <2772@mulga.oz> <989@cresswell.quintus.UUCP>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!munnari!mulga!lee From: lee@mulga.oz (Lee Naish) Newsgroups: comp.lang.prolog Subject: NU-Prolog "pure" declarations Message-ID: <2777@mulga.oz> Date: 19 May 88 02:37:38 GMT References: <983@cresswell.quintus.UUCP> <2772@mulga.oz> <989@cresswell.quintus.UUCP> Reply-To: lee@mulga.UUCP (Lee Naish) Organization: Comp Sci, Melbourne Uni, Australia Lines: 59