please help me what should I do (prolog)

756 views
Skip to first unread message

ali durgun

unread,
Jul 23, 2015, 9:27:50 AM7/23/15
to SWI-Prolog
Hi guys I have just started learn prolog and I'm trying to do some examples and one of them is 

my_write(L):- member(X,L),write(X),nl,fail.

and when I'm trying to run this code I got 


ERROR: Undefined procedure: (:-)/2
ERROR:   Rules must be loaded from a file
ERROR:   See FAQ at http://www.swi-prolog.org/FAQ/ToplevelMode.txt


this errors now I'm trying to solve my problem about it I created new file and in this file I wrote 

[user].
my_write(L):- member(X,L),write(X),nl,fail.
%In here I must write End of File right here. But I couldn't so cause I don't know what character is represents to End of File. So please help me what is the End of File character for prolog ?

and guys I tried to write this code in the program then  
1 ?- [user].

|: my_write(L):- member(X,L),write(X),nl,fail.
|: 
% user://1 compiled 0,00 sec, 2 clauses
true.

2 ?- my_write(L):- member(X,L),write(X),nl,fail.
ERROR: Undefined procedure: (:-)/2
ERROR:   Rules must be loaded from a file


I'm still getting this type of errors getting annoyed. What should I do ? 

Julio Di Egidio

unread,
Jul 23, 2015, 10:02:17 AM7/23/15
to SWI-Prolog, ali.dur...@gmail.com
On Thursday, July 23, 2015 at 2:27:50 PM UTC+1, ali durgun wrote:
<snip>
I'm still getting this type of errors getting annoyed. What should I do ? 

You are using the very same code to define a predicate then to query it: that cannot work, can it?

Here is a working example:

?- [user].

|: my_write(L) :- member(X, L), write(X), nl, fail.
|:
% user://1 compiled 0.00 sec, 2 clauses
true.

?- my_write([1, 2, 3]).
1
2
3
false.

?-

I'd suggest you go through some Prolog *tutorial*, there are plenty online.

HTH,

Julio

Anne Ogborn

unread,
Jul 23, 2015, 10:23:41 PM7/23/15
to Julio Di Egidio, SWI-Prolog, ali.dur...@gmail.com
in Prolog you write rules about how the world works.
Then you make queries about the rules

The rules go in a file.

The querie goes in at the ?- prompt

You're typing the rules in there.

See

http://www.pathwayslms.com/swipltuts/student/index.html#hello

and

http://www.pathwayslms.com/swipltuts/student/index.html#not_repl







________________________________
From: Julio Di Egidio <ju...@diegidio.name>
To: SWI-Prolog <swi-p...@googlegroups.com>
Cc: ali.dur...@gmail.com
Sent: Thursday, July 23, 2015 7:02 AM
Subject: [SWIPL] Re: please help me what should I do (prolog)



On Thursday, July 23, 2015 at 2:27:50 PM UTC+1, ali durgun wrote:
<snip>
I'm still getting this type of errors getting annoyed. What should I do ?

You are using the very same code to define a predicate then to query it: that cannot work, can it?

Here is a working example:

?-[user].

|:my_write(L):-member(X,L),write(X),nl,fail.
|:
%user://1 compiled 0.00 sec, 2 clauses
true.

?-my_write([1,2,3]).
1
2
3
false.

?-

I'd suggest you go through some Prolog *tutorial*, there are plenty online.

HTH,

Julio




--
You received this message because you are subscribed to the Google Groups "SWI-Prolog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swi-prolog+...@googlegroups.com.
Visit this group at http://groups.google.com/group/swi-prolog.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages