Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

print all records using query in prolog

Tags:

prolog

lectures(monday, nolecture).
lectures(tuesday, vp).
lectures(tuesday, se).
lectures(tuesday, ddbms).
lectures(wednessday, ds).
lectures(wednessday, mpl).
lectures(thursday, vp).
lectures(thrusday, se).
lectures(friday, ds).
lectures(friday, mpl).
lectures(saturday, ai).
lectures(saturday, ddbms).

?- lectures(friday, X), write(X),nl.

the query print only first record as ds only, I want to print all record on particular day i.e Friday, the result should be ds and mpl.

update me!

like image 337
Shahid Ghafoor Avatar asked Nov 26 '25 11:11

Shahid Ghafoor


1 Answers

Add fail. to the end of your query:

| ?- lectures(friday, X), write(X), nl, fail.
ds
mpl

no
| ?- 

Also see this very similar question so try to use search a little bit more before asking a new question.

like image 181
aqua Avatar answered Nov 28 '25 01:11

aqua



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!