[ ECLiPSe Predicate Database built-in.|Group Index| Full Index]

compile_term(+Clause)

Compile specified clause or list of clauses Clause.

+Clause
A valid Prolog clause, or list of clauses.

Description

Compiles the specified Prolog clause or list of clauses. Any existing static procedures with the same functor as the ones in Clause are redefined.

If Clause is a list, the list elements are taken as static Prolog clauses and compiled as if they occurred in a file. Otherwise, if Clause is an atom or a compound term, it is itself compiled as a Prolog clause. This predicate works exactly as if all the clauses in the list were written into a file and this file was then compiled using compile/1. The difference between compile_term/1 and assert/1 is that the predicates for which clauses are compiled are not necessarily dynamic with compile_term/1, unless explicitly declared as such. Therefore clauses compiled with compile_term/1 usually replace the existing ones for the same predicate, moreover their source form is not available. On the other hand, compile_term/1 is faster than assert/1. Therefore, it can be used instead of assert/1 if the properties of dynamic procedures are not required.

Unlike compiling a file, when an event occurs which is not just a warning, the following clauses are not compiled, the compilation is aborted.

Fail Conditions

None.

Resatisfiable

No.

Exceptions

(4) Instantiation fault
Clause is a partial list.
(5) Type error
Clause is a list whose tail is neither nil nor a variable.
(66)
A system predicate is being redefined.
(130)
The head of Clause is not an atom or a compound term.
(131)
A subgoal in the body of Clause is not an atom or a compound term.
(134)
Clause is a list of clauses where clauses of one procedure are not consecutive.
(135)
Trying to redefine a protected procedure.
(137)
A procedure which was previously referenced as built-in or external is now defined as a regular one, or vice versa. Error 143 --- One of the clauses was a query and it failed.
(270)
Trying to compile delay clauses without switching on the coroutine state.
(275)
Trying to add delay clauses to a built-in or external procedure.

Examples


Success:
   compile_term([p(a), p(b), q(1), r("abc")]).
   compile_term([:- coroutine, delay p(X) if var(X)]).
   compile_term(p(X) :- q(X)).

   [eclipse]: compile_term([[a]]).                  (Error 66).
   warning: modifying a system predicate in '.' / 2

   yes.
   [eclipse]: [X].       % The system predicate was redefined.

   X = a
   yes.

   % Compile_term/1 can be used for conditional compilation:
   :- (exists('/usr/ucb') -> S = bsd; S = sysV),
      compile_term(os(S)).

   % Even a whole procedure can be conditionally compiled:
   :- os(bsd) ->
    compile_term([
        (pred1(X) :- pred2(X), pred3(X)),
        (pred1(Y) :- ...           )]).


Error:

   compile_term([p|X]).        (Error 4).
   compile_term([a|b]).        (Error 5).
   compile_term("a").          (Error 130).
   compile_term(["a" :- b]).   (Error 130).
   compile_term([p(X) :- 1]).  (Error 131).
   compile_term([a, b, a]).    (Error 134).
   compile_term(!).            (Error 135).
   compile_term([(p :- write(a)), write(b)]).      (Error 137).
   compile_term(:- var(a)).    (Error 143).
   compile_term(delay functor(A, _, _) if var(A)). (Error 275).


See Also

compile / 1, compile / 2, . / 2, compile_stream / 1, assert / 1, set_flag / 2, dbgcomp / 0, nodbgcomp / 0