Reputation: 830
Having this snippet
foo :- getVar(X).
How can I do a really simple thing such as: "if the variable X comes out of getVar instatiated, call bar/1
else call baz/1
Thanks!
Upvotes: 1
Views: 36
Reputation: 18663
You can use an if-then-else control construct and the nonvar/1
standard built-in predicate. For example:
foo :-
get_var(X),
( nonvar(X) ->
bar(X)
; baz(X)
).
Upvotes: 2