member(X,[X|_]). member(X,[_|Y]) :- member(X,Y).
I understand the idea of a head and a tail. I know that the first part of the code searches for a member in the head. That makes sense to me. The second part is recursive, and I don't really understand it. I know what it's doing (removing the head and making the next item in the list the new head) because that it stated for us, but I don't understand how that code accomplishes that.
Moreover, I have no idea how to actually reverse the list. Normally, I would try to determine how many items are in the list, store each one as a variable and output them in reverse, but in Prolog I don't know how to do most of that. This is homework, so I am not looking for someone to do it for me. Help understanding would be greatly appreciated, though. Thanks.

New Topic/Question
Reply



MultiQuote



|