two different approaches of defining 'member' predicate

15 views
Skip to first unread message

sovereig...@outlook.com

unread,
Nov 12, 2016, 10:23:26 PM11/12/16
to SWI-Prolog
case1
member(X,[X|R]).
member(X,[Y|R]) :- member(X,R).

case2
member(X,[_|R]) :- member(X,R).
member(X,[X|_]).

Is there any chance that two approaches would produce different prolog goal beavior? 

Feliks Kluzniak

unread,
Nov 13, 2016, 9:04:48 AM11/13/16
to SWI-Prolog
Yes, for example, if the second argument is an uninstantiated variable.  In case 2 you will immediately go into endless recursion.

--
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 https://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