-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbdi_top_level.rkt
70 lines (55 loc) · 1.86 KB
/
bdi_top_level.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#lang racket
;;; See README.md for documentation of the operations of basic actions
;;; - assert
;;; - retract
;;; - query
;;; - achieve
;; just a list to start with
;; what it eventually becomes needs thought...
(define *beliefs* '())
(define (ground? belief) #t)
(define (print-beliefs)
(format "Beliefs: ~a" *beliefs*))
(define (add-belief belief)
(unless (ground? belief)
(error "Assertion FAIL. Belief: ~a not ground" belief))
(set! *beliefs* (cons belief *beliefs*)))
(struct event (action term env) #:transparent #:mutable)
(define (make-event action term env)
(event action term env))
(define (sig term)
(if (pair? term)
(format "~a/~a" (car term) (- (length term) 1))
(format "~a/0" term)))
(define (bdi-assert event)
(let* ((term (event-term event))
(s (sig term)))
(add-belief term)))
(define (bdi-retract event) (printf "Retracting ~a in env: ~a\n" (event-env event)))
(define (bdi-query event) (printf "Query ~a in env: ~a\n" event (event-env event)))
(define (bdi-achieve event) (printf "Achieve ~a in env: ~a\n" event (event-env event)))
(define (handle-event event)
(match (event-action event)
['assert (bdi-assert event)]
['retract (bdi-retract event)]
['query (bdi-query event)]
['achieve (bdi-achieve event)]
[_ (printf "WTF: ~a\n" event)]))
;;
;; REPL
;;
(define (test)
(let/ec return
(let loop ()
(let ((input (read)))
(printf "Read: ~a\n" input)
(if (eq? input 'quit)
(return "Quit received")
(let ((a (car input))
(t (cadr input))
(e (caddr input)))
(let ((ev (make-event a t e)))
(printf "Action: ~a Term: ~a Env: ~a Event: ~a" (event-action ev) (event-term ev) (event-env ev) ev)))))
(loop))))
(define event-1 (event 'assert '(foo-bar) 'env))
(handle-event event-1)