Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PROLOG QUERY: write_descendant_chain .Later chapters examine the special predicates write and nl, which can be used to produce output other than just the values of

PROLOG QUERY: write_descendant_chain

.Later chapters examine the special predicates write and nl, which can be used to produce output other than just the values of variables. For example, if there is a clause

write_child(X,Y) :write(X), write( is a child of ), write(Y), nl.

then the query write_child(john_smith,sue_jones) will always succeed and will also print john_smith is a child of sue_jones on one line. Include this predicate in your program, and write the clauses for a predicate write_descendant_chain(x,y) that prints a chain from x to y when x is a descendant of y but prints nothing when x is not a descendant of y.

For example, if John Smith is a descendant of William Brown, then write_descendant_chain(john_smith,william_brown) should print a sequence of lines something like this: john_smith is a child of sue_jones

sue_jones is a child of harvey_jones

harvey_jones is a child of davy_jones

davy_jones is a child of anna_brown

anna_brown is a child of william_brown

Hint: You will not be able to use the descendant predicate you de?ned for this. Use the child predicate together with write_child. Also, work down from y rather than up from x

write_child(X,Y):- write(X), write(' is a child of '), write(Y), nl.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

More Books

Students also viewed these Databases questions

Question

What role do earnings expectations play in selecting stocks?

Answered: 1 week ago

Question

Can readers easily determine what is heading and what is text?

Answered: 1 week ago