[ ECLiPSe Control built-in.|Group Index| Full Index]

+Goal1 -> +Goal2

If..Then - succeeds if Goal1 succeeds, and then Goal2 succeeds.

+Goal1
Atom or compound term.
+Goal2
Atom or compound term.

Description

Used to implement the If...Then construct. First Goal1 is called and if this succeeds any further solution of Goal1 is cut out and Goal2 is called.

Note that:

Goal1 must not contain a !/0. If a !/0 appears in Goal2, it cuts through ->/2.

Since ->/2 has a lower precedence than ,/2, a call to ->/2 should always be enclosed in parentheses.

Fail Conditions

Fails if Goal1 succeeds and Goal2 fails, or if Goal1 fails.

Resatisfiable

No.

Exceptions

(4) Instantiation fault
One of the arguments is not instantiated.
(5) Type error
One of the arguments is neither an atom nor a compound term.

Examples


Success:
      [eclipse]: X = 1,(X == 1 -> write(hello)).
      hello
      X = 1
      yes.

Fail:
      X = 2, (X == 1 -> write(bye)).

Error:
      Goal -> write(a).            (Error 4).
      "write(a)" -> true.          (Error 5).


See Also

; / 2, -> / 3, ! / 0