diff --git a/imperative/assertions.rkt b/imperative/assertions.rkt index c91e42d..6719a57 100644 --- a/imperative/assertions.rkt +++ b/imperative/assertions.rkt @@ -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"=+")))) diff --git a/imperative/examples/broker-chat-client.rkt b/imperative/examples/broker-chat-client.rkt index 7e10808..b49deb3 100644 --- a/imperative/examples/broker-chat-client.rkt +++ b/imperative/examples/broker-chat-client.rkt @@ -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)