[ Term I/O | The ECLiPSe Built-In Predicates | Reference Manual | Alphabetic Index ]

writeclause(+Stream, +Clause)

The clause Clause is pretty printed on the output stream Stream .
+Stream
Integer (stream number) or Atom (reserved or user-defined symbolic stream name).
+Clause
A Prolog term.

Description

Used to pretty print the clause Clause on the output stream Stream according to the current operator declarations.

When reading Prolog clauses from one file, and then writing to another, the latter part can be done using writeclause/2. This is because the clauses are terminated by a period and a newline, which are not retained by prolog. writeclause/2 replaces these, and flushes the output.

writeclause/1,2 knows about the special meaning of ,/2, ;/2, ->/2, fg -->/2 and :-/2 and prints the clause with the appropriate indentation of subgoals and some (redundant) parantheses to show the clause structure.

Fail Conditions

None.

Resatisfiable

No.

Exceptions

(4) instantiation fault
Clause head is not instantiated.
(5) type error
Clause body goal is not valid.
(4) instantiation fault
Stream is not instantiated.
(5) type error
Stream is not an atom or an integer.
(192) illegal stream mode
Stream is not an output stream.
(193) illegal stream specification
Stream is an illegal stream specification.

Examples

Success:
      [eclipse]: writeclause(output, f(1,2,3)),
      > writeclause(output, h(2,3)).
      f(1, 2, 3) .
      h(2, 3) .
      yes.

      [eclipse]: writeclause(output, X + 2).
      _56 + 2 .

      X = _56
      yes.

      [eclipse]: writeclause(output, a(k):-write(k)).
      a(k):-
              write(k) .
      yes.

      [eclipse]: writeclause(output, (a:-write(k),date(K))).
      a:-
              write(k),
              date(_68) .
      K = _110                   % to top-level output.
      yes.

      [eclipse]: open(file1,update,s), writeclause(s, X + 2),
      > close(s).
      X = _72
      yes.
      [eclipse]: sh('cat file1').
      _72 + 2 .
      yes.

      [eclipse]: set_stream(a,output),
      > writeclause(a, (:- dynamic f/1)).
      :- dynamic f / 1 .
      yes.

      [eclipse]: writeclause(output, (head:-a1,a2;a3,a4->a5;a6)).
      head:-
                (
                    a1,
                    a2
                ;
                    (
                        a3,
                        a4
                    ->
                        a5
                    ;
                        a6
                    )
                ) .
      yes.
Error:
      writeclause(S, a(b,c)).         (Error 4).
      writeclause("string" a(b,c)).   (Error 5).
      writeclause(9, X + 2).          (Error 192).
      writeclause(atom, X + 2).       (Error 193).



See Also

display / 1, display / 2, write / 1, write / 2, writeclause / 1