Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
613 views3 pages

Prolog List Program with Fail Predicate

The document contains three Prolog programs that output lists of cities and states. The first program outputs the cities and states without a header. The second program adds a header to the output. The third program excludes any locations in the state of "DC" from the output.

Uploaded by

Mehedi Hasan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
613 views3 pages

Prolog List Program with Fail Predicate

The document contains three Prolog programs that output lists of cities and states. The first program outputs the cities and states without a header. The second program adds a header to the output. The third program excludes any locations in the state of "DC" from the output.

Uploaded by

Mehedi Hasan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

/* EXP.

NO: 03 */
/* EXP.NAME:The list program with the fail predicate */
/* Date:14/07/08 */

predicates
location(string,string)
go

clauses
go:-
location(City,State),
writef("%-10 %2 \n",City,State),
fail.

go.

location("Jackson","MS").
location("Washington","DC").
location("Raleigh","NC").
/* EXP.NO:04 */
/* EXP.NAME:Adding a header to the list program */
/* Date:14/07/08 */

predicates
location(string,string)
go

clauses
go:-
writef("%-10 %5 \n","CITY","STATE"),
fail.

go:-
location(City,State),
writef("%-10 %2 \n",City,State),
fail.

go.

location("Jackson","MS").
location("Washington","DC").
location("Raleigh","NC").
/* EXP.NO:05 */
/* EXP.NAME:Exclusion using fail */
/* Date:14/07/08 */

predicates
location(string,string)
go
chkstate(string)

clauses
go:-
writef("%-10 %5 \n","CITY","STATE"),
fail.

go:-
location(City,State),
chkstate(State),
writef("%-10 %2 \n",City,State),
fail.

go.

location("Jackson","MS").
location("Washington","DC").
location("Raleigh","NC").

chkstate("DC"):-
fail.

chkstate(_).

You might also like