syndicate-rkt/syndicate/assertions.rkt

25 lines
788 B
Racket

#lang racket/base
(provide message-struct
assertion-struct
(struct-out observe)
(struct-out seal)
(struct-out inbound)
(struct-out outbound))
;; Thin veneers over `struct` for declaring intent.
(define-syntax-rule (assertion-struct item ...) (struct item ... #:prefab))
(define-syntax-rule (message-struct item ...) (struct item ... #:prefab))
(assertion-struct observe (specification))
;; Seals are used by protocols to prevent routing from examining
;; internal structure of values.
(struct seal (contents) ;; NB. Neither transparent nor prefab
#:methods gen:custom-write
[(define (write-proc s port mode)
(fprintf port "#{~v}" (seal-contents s)))])
(struct inbound (assertion) #:prefab)
(struct outbound (assertion) #:prefab)