Prolog program to traverse a list

  • Traverse a list:
  • domains
    	namelist = name*
    	name = symbol
    predicates
    	traverse(namelist)
    clauses
    	traverse([]).
    	traverse([Head|Tail]):-
    		write(Head),nl,
    		traverse(Tail).
    

    Also try with:

    domains
      namelist=symbol*
    predicates
      member(symbol,namelist)
      club_member(symbol)
    clauses
      member(X,[X|_]).
      member(X,[_|Tail]):-
      member(X,Tail).
      club_member(Name):-
      member(Name,[a,b,c,d,e]).
    

    Leave a Reply

    Please log in using one of these methods to post your comment:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out /  Change )

    Google photo

    You are commenting using your Google account. Log Out /  Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out /  Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out /  Change )

    Connecting to %s