Retire the gross hack of upper-case symbols standing for variables.
This commit is contained in:
parent
7e0a6228c9
commit
bab1beb5ec
|
@ -26,6 +26,9 @@
|
|||
topic-subscriber
|
||||
co-role
|
||||
co-topic
|
||||
|
||||
;; Reexported from unify.rkt for convenience
|
||||
wild
|
||||
)
|
||||
|
||||
(struct arrived (who) #:prefab) ;; someone arrived
|
||||
|
@ -122,7 +125,7 @@
|
|||
the-disconnected-evt)
|
||||
|
||||
(define/public (assert!-evt name)
|
||||
(define cname (upper-case-symbols->canonical name))
|
||||
(define cname (canonicalize name))
|
||||
(choice-evt the-disconnected-evt
|
||||
(wrap-evt (channel-put-evt out-ch (arrived cname))
|
||||
(lambda (v)
|
||||
|
@ -132,7 +135,7 @@
|
|||
(sync (assert!-evt name)))
|
||||
|
||||
(define/public (retract!-evt name [why #f])
|
||||
(define cname (upper-case-symbols->canonical name))
|
||||
(define cname (canonicalize name))
|
||||
(choice-evt the-disconnected-evt
|
||||
(wrap-evt (channel-put-evt out-ch (departed cname why))
|
||||
(lambda (v)
|
||||
|
@ -145,7 +148,7 @@
|
|||
(sync (retract!-evt name)))
|
||||
|
||||
(define/public (say-evt who what)
|
||||
(define cname (upper-case-symbols->canonical (freshen who))) ;; TODO freshening is a bit weird
|
||||
(define cname (canonicalize who))
|
||||
(choice-evt the-disconnected-evt
|
||||
(channel-put-evt out-ch (says cname what))))
|
||||
|
||||
|
|
|
@ -14,20 +14,18 @@
|
|||
(standard-thread
|
||||
(lambda ()
|
||||
(define handle (join-room r))
|
||||
(send handle assert! (topic-subscriber 'Any #:virtual? #t))
|
||||
(send handle assert! (topic-publisher 'Any #:virtual? #t))
|
||||
(send handle assert! (topic-subscriber (wild) #:virtual? #t))
|
||||
(send handle assert! (topic-publisher (wild) #:virtual? #t))
|
||||
(let loop ()
|
||||
(define m (send handle listen))
|
||||
;;(write `(robot heard ,m)) (newline)
|
||||
(match m
|
||||
[(arrived who)
|
||||
(write `(robot hears arrival ,who))
|
||||
(newline)]
|
||||
;;[(arrived who) (write `(robot hears arrival ,who)) (newline)]
|
||||
[(says _ "die")
|
||||
(error 'robot "Following orders!")]
|
||||
[(says (topic 'publisher _ _) _)
|
||||
(send handle say (topic-subscriber 'Any) `(robot hears ,m))]
|
||||
[else (void)])
|
||||
(send handle say (topic-subscriber (wild)) `(robot hears ,m))]
|
||||
[_ (void)])
|
||||
(loop))))
|
||||
|
||||
(define (interaction i o)
|
||||
|
@ -39,8 +37,8 @@
|
|||
(newline o)
|
||||
(flush-output o))
|
||||
(let ((handle (join-room r)))
|
||||
(define talk-topic (topic-publisher (list name 'Sink 'speech)))
|
||||
(define listen-topic (topic-subscriber (list 'Speaker name 'speech)))
|
||||
(define talk-topic (topic-publisher (list name (wild) 'speech)))
|
||||
(define listen-topic (topic-subscriber (list (wild) name 'speech)))
|
||||
(send handle assert! talk-topic)
|
||||
(send handle assert! listen-topic)
|
||||
(let loop ()
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
(provide (struct-out variable)
|
||||
(struct-out canonical-variable)
|
||||
wild
|
||||
variables-in
|
||||
unify
|
||||
unify/env
|
||||
|
@ -39,6 +40,11 @@
|
|||
(display "?!" port)
|
||||
(write (canonical-variable-index v) port)))
|
||||
|
||||
;; -> Variable
|
||||
;; Create a fresh (and hence unconstrained) variable.
|
||||
(define (wild [base-name '_])
|
||||
(variable (gensym base-name)))
|
||||
|
||||
;; Any -> Set<Variable>
|
||||
(define (variables-in x)
|
||||
(let walk ((x x) (acc (set)))
|
||||
|
|
Loading…
Reference in New Issue