Download Firefox: WindowsMac OS X
logo       
Google Custom Search
    AddThis Social Bookmark Button

Re: [Sisc-users] (non-)Binary ports and warnings: msg#00013

Subject: Re: [Sisc-users] (non-)Binary ports and warnings
On 3/13/06, Matthias Radestock <matthias@xxxxxxxxxx> wrote:
> "Alessandro Colomba" <acolomba@xxxxxxxxx> writes:
>
> > I have started such a library in Scheme, and I'd be glad to
> > contribute.
>
> Excellent. May I suggest that you post the API design on the sisc-devel
> list.

Here we go. This is a first pass at the signatures for a Scheme-Java
I/O conversion library. I discuss one issue below.

--8<----8<----8<----8<----8<----8<----8<----8<----8<--
;; *** Java Stream to non-character ports
;; ** INPUT
;; 1. InputStream -> <native-input-port>
(define-method (->binary-input-port (<java.io.input-stream> is))
    => <native-input-port>

;; ** OUTPUT
;; 2. OutputStream -> <native-output-port>
(define-method (->binary-output-port (<java.io.output-stream> os)
    => <native-output-port>


;; *** Java Stream and Read/Writer to character ports
;; ** INPUT
;; 3. InputStream -> <native-character-input-port>
(define-method (->character-input-port (<java.io.input-stream> is)
                                       [(<string> encoding)]) ;; optional
    => <native-character-input-port>

;; 4. Reader -> <native-character-input-port>
(define-method (->character-input-port (<java.io.reader> reader))
    => <native-character-input-port>

;; ** OUTPUT
;; 5. OutputStream -> <native-character-output-port>
(define-method (->character-output-port (<java.io.output-stream> os)
                                        [(<string> encoding)] ;; optional
                                        (<boolean> aflush?))
    => <native-character-output-port>

;; 6. Writer -> <native-character-output-port>
(define-method (->character-output-port (<java.io.writer> writer)
                                        (<boolean> aflush?))
    => <native-character-output-port>

;; *** port -> Java Stream
;; ** INPUT
;; 7. <filter-input-port> -> InputStream
(define-method (->jinput-stream (<filter-input-port> in-port))
    => InputStream

;; 8. <character-input-port> -> InputStream (error)
(define-method (->jinput-stream (<character-input-port> in-port))
    => ERROR

;; ** OUTPUT
;; 9. <filter-output-port> -> OutputStream
(define-method (->joutput-stream (<filter-output-port> out-port))
    => OutputStream

;; 10. <character-output-port> -> OutputStream (error)
(define-method (->joutput-stream (<character-output-port> out-port))
    => ERROR

;; *** character port -> Java Read/Writer
;; ** INPUT
;; 11. <native-character-input-port> => Reader
(define-method (->jreader (<native-character-input-port> in-port))
    => Reader

;; ** OUTPUT
;; 12. <native-character-output-port> => Writer
(define-method (->jwriter (<native-character-output-port> out-port))
--8<----8<----8<----8<----8<----8<----8<----8<----8<--

One thing that bothers me with this API is that it lacks closure.
Because Java allows one to build Read/Writers from Streams but (AFAIK)
not viceversa, functions 3 and 5 do not have their inverse. This and
SISC's port hierarchy are the reason 8 and 10 must return an error.

One could opt to leave 3 and 5 out, and have users adopt the
open-character-*-port methods from the generic-io module (since they
"upgrade" a port to a chracter port). Even so, because
<native-character-*-port>s are <filter-*-port>s, it seems to me that 8
and 10 have to stay.

I'll be glad to hear about this issue and any other I have not considered.
___
Alessandro


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642


<Prev in Thread] Current Thread [Next in Thread>