yrazlik
yrazlik

Reputation: 10777

What is wrong with the following piece of code in prolog?

I am new to prolog and trying a very simple example on http://www.compileonline.com/execute_prolog_online.php . Here is my code:

:- initialization(main).
main :- 

female(ayse).
?- female(ayse).

But it gives an error saying that:

/web/com/136989421322328/main.pr:5:4: syntax error: . or operator expected after expression
1 error(s)
compilation failed

where line 5 is the line starts with ?. What is wrong here? Can anyone help?

Thanks.

Upvotes: 0

Views: 380

Answers (1)

User
User

Reputation: 14873

This code works:

:- initialization(hello).
hello :- write('hello').

Lines:

  1. you say you want to have a predicate called hello that will be specified in the following lines that shell be executed when everything is loaded.

  2. you declare the predicate.

    "hello implies write('hello') is true"

What you wanted to write is

:- initialization(main).
female(ayse).

main :- female(ayse), write('ayse is female').

Upvotes: 2

Related Questions