<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Apr 21, 2012, at 11:52 AM, Chad Albers wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Hi,<div><br></div><div>I'm looking for an example of treating a struct like a port, which appears to be possible:&nbsp;<a href="http://docs.racket-lang.org/reference/portstructs.html?q=struct#(def._((quote._~23~25kernel)._prop~3ainput-port))">http://docs.racket-lang.org/reference/portstructs.html?q=struct#(def._((quote._~23~25kernel)._prop~3ainput-port))</a></div>
<div><br></div><div>Apparently, this is a lot easier that using make-custom-port. &nbsp; What I would like to do is be able to declare a struct, set it's prop:input-port property, pass an instance of struct to a port procedure, like (read-bytes string-that-acts-like-port), and have the bytes sent to the read-bytes actually contain bytes that were stored in the fields of the struct itself. &nbsp;Is that possible, and is that the reason why one would treat a struct like a port?</div>
<div><br></div><div>Thanks in advance for any examples,</div></blockquote></div><br><div><br></div><div>Do you mean something like this:&nbsp;</div><div><br></div><div><div>#lang racket</div><div>(struct i (x) #:property prop:input-port 0)</div><div>(define an-i (i (open-input-string "hello world")))</div><div>(read an-i) ;; yields 'hello&nbsp;</div></div><div><br></div><div>-- Matthias</div><div><br></div></body></html>