Add COUNT aggregate to forward-chaining example

This commit is contained in:
Tony Garnock-Jones 2015-04-25 11:51:55 -04:00
parent e00f079871
commit a1bd9cd482
1 changed files with 15 additions and 0 deletions

View File

@ -7,6 +7,21 @@
(spawn-timer-driver)
(spawn (lambda (e old-count)
(match e
[(? patch?)
(define-values (in out)
(patch-project/set e (compile-projection `(parent ,(?!) ,(?!)))))
(define new-count (+ old-count (set-count in) (- (set-count out))))
(printf "New parent-record count: ~v\n" new-count)
(transition new-count
(list (retract `(parent-count ,?))
(assert `(parent-count ,new-count))))]
[_ #f]))
0
(sub `(parent ,? ,?))
(assert `(parent-count 0)))
(define (insert-record record . monitors)
(printf "Record ~v inserted, depending on ~v\n" record monitors)
(spawn (lambda (e s)