Prolog program to demonstrate the fail predicates and cut predicates. - Artificial intelligence

No comments
  • Program to demonstrate the fail predicates.
Program:
predicates
               start
               info(string,string)
clauses
               start:-
               info(Name,City),
               writef("%-10%2\n",Name,City),
               fail.
               start.
               info("Dharmik","Ahmedabadbad").
               info("Krutik","gandhinagar").

Output:
Goal: start 
Dharmik Ahmedabad 
Krutik Gandhinagar

  • Program to demonstrate the cut predicates.
Program:
predicates
               start
               info(string,string)
               cut(string)
clauses
               start:-
               info(Name,City),
               cut(Name),
               writef("%-10%2\n",Name,City),
               fail.
               start.
               cut("Rutu"):-
               !,fail.
               cut(_).
               info("Dharmik","Ahmedabadbad").
               info("Rutu","himmatnagar").
               info("Krutik","gandhinagar").

Output:
Goal: start 
Dharmik Ahmedabad 
Krutik Gandhinagar

No comments :

Post a Comment