Re: [racket] Example of using a struct as a port

2012-04-25 Thread Matthew Flatt
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. Occas

Re: [racket] Example of using a struct as a port

2012-04-21 Thread Chad Albers
Interesting...that worksbut in this case, the struct is purely a port, since it has no other fields. an-i is not really an instance of a struct i, but a definition that returns the value of an instance of a struct that takes as its sole field value a port. IOW, it doesn't take as its only fi

Re: [racket] Example of using a struct as a port

2012-04-21 Thread Eric Hanchrow
How about #lang racket (struct i (x) #:property prop:input-port 0) (define (an-i str) (i (open-input-string str))) (read (an-i "hello")) ;; yields 'hello ? On Sat, Apr 21, 2012 at 9:43 AM, Chad Albers wrote: > I was thinking more along the lines of: > > #lang racket > (struct i (x) #:property

Re: [racket] Example of using a struct as a port

2012-04-21 Thread Chad Albers
I was thinking more along the lines of: #lang racket (struct i (x) #:property prop:input-port 0) (define an-i (i "hello")) (read an-i) ;; yields 'hello 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 try

Re: [racket] Example of using a struct as a port

2012-04-21 Thread Matthias Felleisen
On Apr 21, 2012, at 11:52 AM, Chad Albers wrote: > Hi, > > I'm looking for an example of treating a struct like a port, which appears to > be possible: > http://docs.racket-lang.org/reference/portstructs.html?q=struct#(def._((quote._~23~25kernel)._prop~3ainput-port)) > > Apparently, this is a

[racket] Example of using a struct as a port

2012-04-21 Thread Chad Albers
Hi, I'm looking for an example of treating a struct like a port, which appears to be possible: http://docs.racket-lang.org/reference/portstructs.html?q=struct#(def._((quote._~23~25kernel)._prop~3ainput-port)) Apparently, this is a lot easier that using make-custom-port. What I would like to do