fork download
  1. % 商品データ
  2. % product(商品名, 価格, 評価, レビュー数).
  3.  
  4. product(item1, 3000, 4.8, 20).
  5. product(item2, 1800, 4.2, 200).
  6. product(item3, 5000, 4.9, 5).
  7. product(item4, 2500, 4.5, 80).
  8.  
  9. % 価格が3000円以下の商品
  10. cheap_product(Name, Price) :-
  11. product(Name, Price, _, _),
  12. Price =< 3000.
  13.  
  14. % 評価が4.5以上の商品
  15. high_rating_product(Name, Rating) :-
  16. product(Name, _, Rating, _),
  17. Rating >= 4.5.
  18.  
  19. % レビュー数が50件以上の商品
  20. popular_product(Name, Reviews) :-
  21. product(Name, _, _, Reviews),
  22. Reviews >= 50.
  23.  
  24. % 評価が高く、レビュー数も多いおすすめ商品
  25. recommended_product(Name) :-
  26. product(Name, _, Rating, Reviews),
  27. Rating >= 4.5,
  28. Reviews >= 50.
Success #stdin #stdout #stderr 0.02s 6968KB
stdin
?- cheap_product(Name, Price).
stdout
Standard output is empty
stderr
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit