Search code examples
prologclause

Prolog: How to produce a multiple answer output?


Given:

fruitid('Apple', 'Granny Smith', 1).

How would I go about creating the clause:

print_fruit_details(FruitID) :-

Which would output 'Apple' and 'Granny Smith' given the input 1.

Thanks,

JAS


Solution

  • Try this:

    print_fruit_details(FruitID) :- fruitid(X, Y, FruitID), write(X), write(Y).
    

    And welcome to StackOverflow :)