Hello.
loop_entry(A,[Head|List],X) :-
print(List),
Head == A,
loop_entry(A,[List],X).
?- loop_entry(a,[a,a,a,a,b,c,d,e,f],X).
I get the result:
[a,a,a,b,c,d,e,f][]
false.
But I want the result:
b,c,d,e,f
I want to delete all a’s at the beginning of the list.
I think : Head == A,
is the problem.
Does not work, too:
loop_entry(A,[H|L],V) :-
L \== A.
loop_entry(A,[Head|List],X) :-
print(List),
loop_entry(A,[List],X).
L == A. For some reason He cannot compare characters?
Thanks
| PrologAxel
October 23 |
Hello.
`
loop_entry(A,[Head|List],X) :-
print(List),
Head == A,
loop_entry(A,[List],X).
`
?- loop_entry(a,[a,a,a,a,b,c,d,e,f],X).
I get the result:
[a,a,a,b,c,d,e,f]
false.
But I want the result:
b,c,d,e,f
I want to delete all a’s at the beginning of the list.
I think : Head == A,
is the problem.
Does not work, too:
loop_entry(A,[H|L],V) :-
L == A.
loop_entry(A,[Head|List],X) :-
print(List),
loop_entry(A,[List],X).
L == A. For some reason He cannot compare characters?
This should be “Head = A”, not “Head == A”.
Cheers
Volker
1 Like
The following seems what you have in mind. If so, I’m happy.
% ?- loop_entry(a, [a,a,a,b,c], X).
%@ X = [b, c].
% ?- loop_entry(a, [b,c], X).
%@ X = [b, c].
loop_entry(A, [ A | List ], X) :-!, loop_entry(A, List, X).
loop_entry(_, List, List).
K.M.
1 Like
Thank you. This was exactly what I was looking for.