Help me answer this Prolog question

%in_stock(stock#, yes/no)

in_stock( id1942 , no ).
in_stock( id2491, yes).
in_stock( id9791, no).
in_stock( id5312, yes).
in_stock( id6132, no).

%book( stock# , title, edition, year). – stock # is a unique identfier

book( id1942, 'The C Programming Language', 1, 1978 ).
book( id2491, 'The C Programming Language', 2, 1988 ).
book( id9791, 'Pride and Prejudice' ,1 , 1813 ).
book( id9791, 'Pride and Prejudice' ,1 , 1814 ).
book( id5312, 'The Wonderful Wizard of Oz', 1, 1900).
book( id6132, 'The Touchstone', 1, 1900).

% Query for “what books are in stock and published in the year 1900?” Give the title.

q1(Title):- book(title, '1900'), in_stock('yes').

While you can ask these type of homework questions here, do not expect an answer here.

I suspect you were the same person asking similar questions on StackOverflow for which the questions were closed and then deleted.

To get started learning Prolog please use one of the free introduction books. :slightly_smiling_face:


A couple of hints:

  • when you defined q(Title), you probably got a “singleton variable” warning.
  • you wrote book(title, '1900') but the book predicate has 4 arguments (similarly, in_stock has 2 arguments but you only gave one.
  • '1900' is an atom; 1900 is a number.
  • 'yes' and yes are both the same atom.