1
votes

I am trying to get my feet wet with some Prolog, as I have a project due in it relatively soon. How would I do something simple such as displaying some output text to the console? I am using the SWI shell, and attempting to consult a .pro file that looks like this

write_to_screen():-
    write("Hello World").

However, when I try and consult this file, I come across compile errors. Anyone know how you would call this function from the SWI shell?

*the error I am getting is 'Syntax error: Illegal start of term'

1

1 Answers

4
votes

Prolog syntax it's a little unusual: you can't write *some_term()*, i.e. the arguments' list cannot be empty. Write your parameter less procedure without parenthesis:

write_to_screen :-
    write("Hello World").

Note you need to change the quote codes from double to single: double quotes are a shortcut for characters' list: i.e.

?- write("Hello World").
[72,101,108,108,111,32,87,111,114,108,100]

while

?- write('Hello World').
Hello World