Structs that masquerade as channels

20 views
Skip to first unread message

David Storrs

unread,
May 22, 2020, 6:03:17 PM5/22/20
to Racket Users
Is there a way to make a struct that can seamlessly pretend to be a channel the same way one can pretend to be an output-port?  I'm pretty sure the answer is no but wanted to confirm.

Example:

(struct person (name to) #:property prop:output-port (struct-field-index to))
(displayln "yay" (person 'bob (current-output-port)) )
"yay"  ;<==== actual result

(struct animal (name to) #:property ??? (struct-field-index to))
(define fido (animal 'dog (make-channel)))
(channel-put fido 'yay)
(channel-get (animal-to fido))
'yay  ; <=== desired result

Is there something that can go in ??? to make this work, or some other way of doing it?  I looked at impersonators but those don't seem to be it.
Reply all
Reply to author
Forward
0 new messages