strong-gensym

This commit is contained in:
Tony Garnock-Jones 2019-03-24 17:16:57 +00:00
parent 2ee25068b9
commit 25d3656e09
2 changed files with 15 additions and 2 deletions

View File

@ -5,7 +5,12 @@
(struct-out observe)
(struct-out seal)
(struct-out inbound)
(struct-out outbound))
(struct-out outbound)
strong-gensym)
(require (only-in net/base64 base64-encode))
(require (only-in racket/random crypto-random-bytes))
(require (only-in racket/string string-trim))
;; Thin veneers over `struct` for declaring intent.
(define-syntax-rule (assertion-struct item ...) (struct item ... #:prefab))
@ -22,3 +27,11 @@
(struct inbound (assertion) #:prefab)
(struct outbound (assertion) #:prefab)
(define (strong-gensym [head 'g] #:random-bytes [count 16])
(string->symbol
(format "~a~a"
head
(string-trim (bytes->string/latin-1
(base64-encode (crypto-random-bytes count) #""))
#px"=+"))))

View File

@ -8,7 +8,7 @@
(message-struct Says (who what))
(spawn #:name 'main
(field [username (symbol->string (gensym 'chatter))])
(field [username (symbol->string (strong-gensym 'chatter-))])
(define root-facet (current-facet))
(define url standard-localhost-broker/tcp)