[racket] Example of using a struct as a port
At Sat, 21 Apr 2012 15:32:15 -0400, Chad Albers wrote:
> Otherwise, I
> just don't understand what the use-case is for adding the port property to
> the struct. Might as well just assign one of the struct's fields to be a
> port, rather than the ceremony of setting a property on the struct.
Occasionally, you have to provide a port to some library or callback,
and when you eventually get a port back, you want to recognize the port
as one that you created. For example, `open-output-string' produces an
output port, but `get-output-string' needs to recognize exactly those
ports that are produced by `open-output-string' so that it can extract
an accumulated string.
That use case is not common, however, and as you have sorted out,
`prop:input-port' and `prop:output-port' are not substitutes for
`make-input-port' and `make-output-port'.