MNikolovski

Prolog Part2 - Syntax, Questions and Structs

Oct 28th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. "_" is a wildcard meaning 'whatever'
  2.  
  3. We can use write for printing.
  4. ex1: write(City1).
  5. write('Hello, ), write(Name), nl. ===> nl means new line
  6.  
  7. ex2:
  8. weather(phoenix,hot,summer).
  9. weather(la,warm,summer).
  10.  
  11. warmer_than(C1, C2):-
  12. weather(C1,hot,summer),
  13. weather(C2,warm,summer),
  14. write(C1), write(' is warmer than '), write(C2), nl.
  15.  
  16. Structs are used to simplify or organize the overall look of our code.
  17. ex:
  18.  
  19. course(cse110, mon, wed, 11, 12, 11, 12, holton, bryce, coor105, coor321).
  20.  
  21. course(
  22. cse110,
  23. day(mon),
  24. time(11,12),
  25. prof(holton, bryce),
  26. coor105
  27. ).
  28.  
  29. course(
  30. cse110,
  31. day(wed),
  32. time(11,12),
  33. prof(holton, bryce),
  34. coor321
  35. ).
Add Comment
Please, Sign In to add comment