Reputation: 315
I'm using Strawberry Prolog and when I write
?- write('Hello World'),nl.
it outputs HelloWorld without whitespace but if I change the single quote to a double quote it outputs everything fine why is that?And why is this not a problem with other prolog IDE's?Also why is there a difference between single and double quotes?
Finally if it's no trouble can someone recommend a some guides on prolog?
Upvotes: 0
Views: 275
Reputation:
A good check point, for what a Prolog system should do, is always GNU Prolog (for some issues version 1.3.0 is even better). It is very close to the ISO core standard, and doesn't have a lot of novelties. So you should get something along:
GNU Prolog 1.4.4 (64 bits)
Compiled Apr 23 2013, 16:05:07 with cl
?- write('Hello World'), nl.
Hello World
yes
?- write("Hello World"), nl.
[72,101,108,108,111,32,87,111,114,108,100]
Explanation 1 Single Quotes:
The write/1 predicate should write atoms unquoted. Which means atoms that usually need quotes, will be written without quotes. If you want to show quotes you can use writeq/1. And atom is in single quotes.
Explanation 2 Double Quotes:
Double quotes were traditionally used to denote lists of character codes, so that one can easily define DCG rules. A lot of Prolog systems divert here, and even the ISO core standard allows character atoms instead codes.
But usually you can ask the Prolog system what it does with double quotes, and even modify the behaviour. Just use the Prolog flag double_quotes. Here is what you can do in GNU-Prolog:
?- current_prolog_flag(double_quotes, X).
X = codes
?- set_prolog_flag(double_quotes, chars).
yes
?- write("Hello World"), nl.
[H,e,l,l,o, ,W,o,r,l,d]
Upvotes: 3