
block(+Goal, ?Tag, +Recovery)

   Similar to call(Goal) if Goal succeeds or fails.  If an exit_block/1 is
executed inside Goal, whose argument unifies with Tag, then Recovery is
executed.



Arguments
   +Goal               An atom or a compound term.
   ?Tag                An atom, integer or variable.
   +Recovery           An atom or a compound term.

Type
   Control

Description
   First Goal is called from the current module and if this succeeds then
   block/3 succeeds.  If Goal fails then so does the call of block/3.  If,
   however, during the execution of Goal there is a call of
   exit_block(TagExit) such that Tag unifies with TagExit, then block/3
   calls the goal Recovery, and succeeds or fails according to whether
   Recovery succeeds or fails.  If Tag does not unify with TagExit, the
   system continues looking for an earlier invocation of block/3.




Resatisfiable
      No.

Fail Conditions
      Fails if Goal fails, or if Recovery fails.



Exceptions
     4 --- Either Goal or Recovery is not instantiated.
     5 --- Goal is neither an atom nor a compound term.
     5 --- Tag is not an atomic type.
     5 --- Recovery is neither an atom nor a compound term.
    68 --- Either Goal or Recovery is an undefined predicate.

Examples
   
Success:
      block(a_goal, label, true).
        % similar to a label for a 'goto'
      exit_block(label).
        % the associated 'goto' statement.
      [eclipse]: [user].
       go:-
             getval(i,2) ->
             exit_block(hello).
       user compiled 100 bytes in 0.02 seconds
      yes.              % go/0 exits with Tag 'hello' if
                        % the global variable i is 2.
      [eclipse]: setval(i,1), block(go, hello, write(hello)).
      no.
      [eclipse]: setval(i,2),block(go,hello,writeln(hello)).
      hello
      yes.

Fail:
      block(exit_block(t), t, 3 = 2).

Error:
      block(go, hello, Recovery).      (Error 4).
      block(Goal, any, thing).         (Error 4).
      block(go, hello(X), problem).    (Error 5).
      block(go, hello, "a").           (Error 5).
      block(nonex, t, write(bye)).     (Error 68).





See Also
   exit_block / 1
