<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div>I don’t know if you can do it with generic interfaces (as in racket/generic), </div><div>but you can make classes whose instances have struct-type properties such as prop:procedure and prop:sequence</div><div>(using interfaces as in racket/class, not racket/generic)</div><div><br></div><div><div><font face="Courier New">#lang racket</font></div><div><font face="Courier New"><br></font></div><div><font face="Courier New">(define proc<%></font></div><div><font face="Courier New"> (interface* ()</font></div><div><font face="Courier New"> ([prop:procedure</font></div><div><font face="Courier New"> (lambda (this . args)</font></div><div><font face="Courier New"> (send/apply this proc args))])</font></div><div><font face="Courier New"> proc))</font></div><div><font face="Courier New"><br></font></div><div><font face="Courier New">(define proc%</font></div><div><font face="Courier New"> (class* object% (proc<%>)</font></div><div><font face="Courier New"> (super-new)</font></div><div><font face="Courier New"> (define/public (proc x)</font></div><div><font face="Courier New"> (displayln "this is the proc method of proc%")</font></div><div><font face="Courier New"> x)))</font></div><div><font face="Courier New"><br></font></div><div><font face="Courier New">(define seq<%></font></div><div><font face="Courier New"> (interface* ()</font></div><div><font face="Courier New"> ([prop:sequence</font></div><div><font face="Courier New"> (lambda (this)</font></div><div><font face="Courier New"> (send this get-sequence))])</font></div><div><font face="Courier New"> get-sequence))</font></div><div><font face="Courier New"><br></font></div><div><font face="Courier New">(define seq%</font></div><div><font face="Courier New"> (class* object% (seq<%>)</font></div><div><font face="Courier New"> (super-new)</font></div><div><font face="Courier New"> (define/public (get-sequence)</font></div><div><font face="Courier New"> (list 1 2 3))))</font></div></div><div><font face="Courier New"><br></font></div><div><div><font face="Courier New">> (define p (new proc%))</font></div><div><font face="Courier New">> (p 1)</font></div><div><font face="Courier New">this is the proc method of proc%</font></div><div><font face="Courier New">1</font></div><div><font face="Courier New">> (define s (new seq%))</font></div><div><font face="Courier New">> (sequence-for-each displayln s)</font></div><div><font face="Courier New">1</font></div><div><font face="Courier New">2</font></div><div><font face="Courier New">3</font></div></div><br><div><div>On Oct 2, 2014, at 6:21 PM, Matthew Butterick <<a href="mailto:mb@mbtype.com">mb@mbtype.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">What's the best approach to:<br><br>+ defining a class whose instances can be used as procedures?<br><br>(define ci (new proc-class%))<br>(ci arg arg2 ... )<br><br>+ ... whose instances can be used as lists (or at least support direct iteration?)<br><br>(define li (new listish-class%))<br>(for-each displayln li)<br>(map ci li)<br><br>My intuition is "implement a generic interface..." But then it gets hazy. <br><br><br><br><br>____________________<br> Racket Users list:<br> <a href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a><br></blockquote></div><br></body></html>