Question

I am a novice at programming in prolog.

I want to change the value returned by a prolog program such that it returns true / false instead of the standard yes or no.

Consider a very simple example : E.g. simple.P

node(1).

isNode(X) : node(X)

on the prolog command line if I type isNode(1) it returns with yes like:

isNode(1).

yes

My question is :

How do i change this from yes to true?

Was it helpful?

Solution

Prolog attempts to find a proof of your query. If your query has variables, it prints a value that makes them true.

Q: Are there any prime numbers that are even? A: Yes - 2 is even and prime

It'll keep giving you more proofs as long as you type ; Eventually it'll run out, and respond false.

Q: Are there any prime numbers that are even? A: Yes - 2 is even and prime Q: Are there any more? A: false.

What you want is for your program to perform output. There's a number of library predicates to do this. The most flexible is format/2

myprogram :-
   my_old_program, !,
   format('yup, that sure is right!~n', []).
myprogram :-
   format('nope, nope, no way in heck!~n', []).
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top