I was thinking more along the lines of:<div><br></div><div><div>#lang racket</div><div>(struct i (x) #:property prop:input-port 0)</div><div>(define an-i (i "hello"))</div><div>(read an-i) ;; yields 'hello </div>
<div><br></div><div>I know this doesn't work. IOW, the read operation actually has accesses to a field inside the struct itself. If that's impossible, then I'm trying to understand why structs could be treated like ports, but then the data in the port doesn't really have access to the field-values in the struct.</div>
<div><br></div><div>Thanks for your help,</div>--<br>Chad <br><br>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Apr 21, 2012 at 12:35 PM, Matthias Felleisen <span dir="ltr"><<a href="mailto:matthias@ccs.neu.edu" target="_blank">matthias@ccs.neu.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div class="h5"><br><div><div>On Apr 21, 2012, at 11:52 AM, Chad Albers wrote:</div>
<br><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: <a href="http://docs.racket-lang.org/reference/portstructs.html?q=struct#(def._((quote._~23~25kernel)._prop~3ainput-port))" target="_blank">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. 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. 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></div><div>Do you mean something like this: </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 </div></div><span class="HOEnZb"><font color="#888888"><div><br></div><div>-- Matthias</div><div><br></div></font></span></div>
</blockquote></div><br></div></div>