upsidedown

IA Prolog Part 2

Sep 12th, 2012
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 4.61 KB | None | 0 0
  1. predicates
  2.         bigger(symbol,symbol)
  3. clauses
  4.         bigger(elephant,horse).
  5.         bigger(horse,donkey).
  6.         bigger(donkey,dog).
  7.         bigger(donkey,monkey).
  8.  
  9.  
  10.        Files       Edit       Run       Compile       Options       Setup
  11. +---------------------- Editor ----------------------++-------- Dialog --------+
  12. ¦  Line 8     Col 1     D:\1080P\ELEPHA~1.PRO  Indent¦¦Goal: bigger(monkey,elep¦
  13. ¦predicates                                          ¦¦hant)                   ¦
  14. ¦        bigger(symbol,symbol)                       ¦¦No                      ¦
  15. ¦clauses                                             ¦¦Goal: bigger(elephant,ho¦
  16. ¦        bigger(elephant,horse).                     ¦¦rse)                    ¦
  17. ¦        bigger(horse,donkey).                       ¦¦Yes                     ¦
  18. ¦        bigger(donkey,dog).                         ¦¦Goal: bigger(elephant,
  19. ¦        bigger(donkey,monkey).                      ¦¦onkey)                  ¦
  20. ¦                                                    ¦¦No                      ¦
  21. ¦                                                    ¦¦Goal:                   ¦
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28. predicates
  29.         bigger(symbol,symbol)
  30.         is_bigger(symbol,symbol)
  31. clauses
  32.      is_bigger(X, Y) :- bigger(X, Y).
  33.      is_bigger(X, Y) :- bigger(X, Z), is_bigger(Z, Y).
  34.  
  35.      bigger(elephant,horse).
  36.      bigger(horse,donkey).
  37.      bigger(donkey,dog).
  38.      bigger(donkey,monkey).
  39.  
  40.        Files       Edit       Run       Compile       Options       Setup
  41. +---------------------- Editor ----------------------++-------- Dialog --------+
  42. ¦  Line 5     Col 1     D:\1080P\ELEP2.PRO  Indent  I¦¦Goal: bigger(monkey,elep¦
  43. ¦predicates                                          ¦¦hant)                   ¦
  44. ¦        bigger(symbol,symbol)                       ¦¦No                      ¦
  45. ¦        is_bigger(symbol,symbol)                    ¦¦Goal: bigger(elephant,ho¦
  46. ¦clauses                                             ¦¦rse)                    ¦
  47. ¦     is_bigger(X, Y) :- bigger(X, Y).               ¦¦Yes                     ¦
  48. ¦     is_bigger(X, Y) :- bigger(X, Z), is_bigger(Z, Y¦¦Goal: bigger(elephant,
  49. ¦                                                    ¦¦onkey)                  ¦
  50. ¦     bigger(elephant,horse).                        ¦¦No                      ¦
  51. ¦     bigger(horse,donkey).                          ¦¦Goal: is_bigger(elephant¦
  52. ¦     bigger(donkey,dog).                            ¦¦,monkey)                ¦
  53. ¦     bigger(donkey,monkey).                         ¦¦Yes                     ¦
  54. ¦                                                    ¦¦Goal:                   ¦
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63. predicates
  64. location(string,string)
  65. go
  66.  
  67. clauses
  68. go:-
  69. writef("%-10 %5 \n" ,"CITY", "STATE"),
  70. fail.
  71. go:-
  72. location(City,State),
  73. writef("%-10 %2\n", City,State),
  74. fail.
  75.  
  76. location("jackson","MS").
  77. location("washington","dc").
  78. location("Raliegh", "NC").
  79.  
  80.        Files       Edit       Run       Compile       Options       Setup
  81. ┌────────────────────── Editor ──────────────────────┐╔════════ Dialog ════════╗
  82. │  Line 1     Col 1     D:\1080P\ELEPHA~2.PRO  Indent│║rse)                    ║
  83. │predicates                                          │║Yes                     ║
  84. │location(string,string)                             │║Goal: bigger(elephant, m║
  85. │go                                                  │║onkey)                  ║
  86. │                                                    │║No                      ║
  87. │clauses                                             │║Goal: is_bigger(elephant║
  88. │go:-                                                │║,monkey)                ║
  89. │writef("%-10 %5 \n" ,"CITY", "STATE"),              │║Yes                     ║
  90. fail.                                               │║Goal: go                ║
  91. │go:-                                                │║CITY       STATE        ║
  92. │location(City,State),                               │║jackson    MS           ║
  93. │writef("%-10 %2\n", City,State),                    │║washington dc           ║
  94. fail.                                               │║Raliegh    NC           ║
  95. │                                                    │║No                      ║
  96. │location("jackson","MS").                           │║Goal:                   ║
Advertisement
Add Comment
Please, Sign In to add comment