once(+body_term)  [ISO]

Executes a goal exactly once, whatever may be the number of solutions. This predicate is defined in the system module. The prolog source of the predicate is: 

once(Goal) :- 
    catch( Goal, type_error(callable, _), throw( type_error(callable, Goal) ) ),
    !.

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

Examples
once( (X = 1 ; X = 2) ). succeeds with substitution X=1
once( repeat ). succeeds
once( fail ). fail

 

Exceptions
body_term is a variable an instantiation_error exception is thrown
goal is neither a variable nor a callable term nor a well-formed body a type_error(callable, Goal) exception is thrown

 

 

info@trinc-prolog.com