MJ HH
MJ HH

Reputation: 83

SWI Prolog syntax need to write more than one word in term

How can I write more than one word in hypothesize term and other side? For example I want to write small cat

hypothesize(cat) :- cat, !.

I tried to write it with underscore but in the result the underscore appear which I don't want.

This is the full code.

https://www.cpp.edu/~jrfisher/www/prolog_tutorial/2_17.html

Upvotes: 1

Views: 98

Answers (1)

Isabelle Newbie
Isabelle Newbie

Reputation: 9378

Besides underscores (small_cat) you can also write multi-word atoms with single quotes: 'small cat'.

For example:

?- Cat = 'small cat'.
Cat = 'small cat'.

Maybe you don't want the quotes in the output. In this case, the good news is that if you use write for printing your answer, like the code you linked, the quotes will not be printed:

?- write('small cat').
small cat
true.

If you do want quotes when writing such atoms, you can use writeq ("write quoted"):

?- writeq('small cat').
'small cat'
true.

Upvotes: 1

Related Questions