E
E
Evgeny Nikolaev2017-12-15 09:00:37
Prolog
Evgeny Nikolaev, 2017-12-15 09:00:37

How to work with lists in prolog?

Guys who worked with the prologue? Show me how it works.
There is such a task:
* In the list of characters S1, S2, ..., Sn find all occurrences of the specified word, if the separator between words is one or more spaces.
Found this code somewhere

count(X,X,1):-!. 
count(_,Y,0):-atomic(Y),!. 
count(X,Y,N):- 
        Y=..[_|Subs], 
        count_list(X,Subs,N).        
count_list(_,[],0):-!. 
count_list(X,[H|T],N):- 
        count(X,H,N1), 
        count_list(X,T,N2), 
        N is N1+N2. 

start:-readln(S),read(Sl),count_list(Sl,S,N),write('N = '),write(N).

So, how can you run it? What to write on the query panel?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question