|
48 | 48 | ;; lfe> (gps '(son-at-home) '(son-at-home) (school-ops)) |
49 | 49 | ;; solved |
50 | 50 | ;; |
51 | | - |
52 | 51 | (include-lib "lfe/include/scm.lfe") |
53 | 52 |
|
54 | 53 | ;; Define macros for global variable access. This is a hack and very naughty! |
|
64 | 63 | ;; Module definition. |
65 | 64 | (defmodule gps1 |
66 | 65 | (export |
67 | | - (gps 2) |
68 | | - (gps 3) |
69 | | - (school-ops 0)) |
| 66 | + (gps 2) |
| 67 | + (gps 3) |
| 68 | + (school-ops 0)) |
70 | 69 | (import |
71 | | - (from lists |
72 | | - (member 2) |
73 | | - (all 2) |
74 | | - (any 2)) |
75 | | - ;; Rename lists functions to be more CL like. |
76 | | - (rename lists |
77 | | - ((all 2) every) |
78 | | - ((any 2) some) |
79 | | - ((filter 2) find-all)))) |
| 70 | + (from lists |
| 71 | + (member 2) |
| 72 | + (all 2) |
| 73 | + (any 2)) |
| 74 | + ;; Rename lists functions to be more CL like. |
| 75 | + (rename lists |
| 76 | + ((all 2) every) |
| 77 | + ((any 2) some) |
| 78 | + ((filter 2) find-all)))) |
80 | 79 |
|
81 | 80 | ;; An operation. |
82 | 81 | (defrecord op |
|
98 | 97 | ;; appropriate op for it that is applicable." |
99 | 98 | (defun achieve (goal) |
100 | 99 | (orelse (member goal (getvar *state*)) |
101 | | - (some (fun apply-op 1) |
102 | | - (find-all (lambda (op) (appropriate-p goal op)) |
103 | | - (getvar *ops*))))) |
| 100 | + (some (fun apply-op 1) |
| 101 | + (find-all (lambda (op) (appropriate-p goal op)) |
| 102 | + (getvar *ops*))))) |
104 | 103 |
|
105 | 104 | ;; An op is appropriate to a goal if it is in its add list. |
106 | 105 | (defun appropriate-p (goal op) |
|
131 | 130 | ;; Define a list of operations to use with GPS. |
132 | 131 | (defun school-ops () |
133 | 132 | (list |
134 | | - (make-op action 'drive-son-to-school |
135 | | - preconds '(son-at-home car-works) |
136 | | - add-list '(son-at-school) |
137 | | - del-list '(son-at-home)) |
138 | | - (make-op action 'shop-installs-battery |
139 | | - preconds '(car-needs-battery shop-knows-problem shop-has-money) |
140 | | - add-list '(car-works) |
141 | | - del-list ()) |
142 | | - (make-op action 'tell-shop-problem |
143 | | - preconds '(in-communication-with-shop) |
144 | | - add-list '(shop-knows-problem) |
145 | | - del-list ()) |
146 | | - (make-op action 'telephone-shop |
147 | | - preconds '(know-phone-number) |
148 | | - add-list '(in-communication-with-shop) |
149 | | - del-list ()) |
150 | | - (make-op action 'look-up-number |
151 | | - preconds '(have-phone-book) |
152 | | - add-list '(know-phone-number) |
153 | | - del-list ()) |
154 | | - (make-op action 'give-shop-money |
155 | | - preconds '(have-money) |
156 | | - add-list '(shop-has-money) |
157 | | - del-list '(have-money)))) |
| 133 | + (make-op action 'drive-son-to-school |
| 134 | + preconds '(son-at-home car-works) |
| 135 | + add-list '(son-at-school) |
| 136 | + del-list '(son-at-home)) |
| 137 | + (make-op action 'shop-installs-battery |
| 138 | + preconds '(car-needs-battery shop-knows-problem shop-has-money) |
| 139 | + add-list '(car-works) |
| 140 | + del-list ()) |
| 141 | + (make-op action 'tell-shop-problem |
| 142 | + preconds '(in-communication-with-shop) |
| 143 | + add-list '(shop-knows-problem) |
| 144 | + del-list ()) |
| 145 | + (make-op action 'telephone-shop |
| 146 | + preconds '(know-phone-number) |
| 147 | + add-list '(in-communication-with-shop) |
| 148 | + del-list ()) |
| 149 | + (make-op action 'look-up-number |
| 150 | + preconds '(have-phone-book) |
| 151 | + add-list '(know-phone-number) |
| 152 | + del-list ()) |
| 153 | + (make-op action 'give-shop-money |
| 154 | + preconds '(have-money) |
| 155 | + add-list '(shop-has-money) |
| 156 | + del-list '(have-money)))) |
0 commit comments