always(+body_term, +body_term)

This predicate executes it's first term as a goal just like call/1. If the first term succeeds then it executes the second term if the first goal fails or when an exception is thrown, the second term is not executed if the first is exited.

If the first term has succeeded and an exception is thrown then it is catced, the second term is executed and then the same exception is thrown again.

This predicate is useful in those situations where it is necessary to always prove a goal after another goal has been proven, like for instance: allocating and deleting instances, matching a call of a goal with another goal.

see also: always/2 call/1 catch/2 catch/3 fail/0 halt/0 halt/1 if-then/2 if-then-else/2 once/1 repeat/0 throw/1 true/0

Example
always( C new_obj Canvas, del_obj C ). If it was possible to create an instance of the class Canvas then the second body_term is also executed to delete the instance.
call( C<-startDraw, C<-stopDraw ). If startDraw/0 does not fail then stopDraw/0 is always executed.

 

Exceptions
- -

 

 

info@trinc-prolog.com