diff --git a/basis/delegate/protocols/protocols.factor b/basis/delegate/protocols/protocols.factor index edbec804c1..f568a3e388 100644 --- a/basis/delegate/protocols/protocols.factor +++ b/basis/delegate/protocols/protocols.factor @@ -1,27 +1,25 @@ ! Copyright (C) 2007 Daniel Ehrenberg ! See http://factorcode.org/license.txt for BSD license. USING: delegate sequences.private sequences assocs -io io.styles definitions kernel continuations ; +io definitions kernel continuations ; IN: delegate.protocols PROTOCOL: sequence-protocol - clone clone-like like new-sequence new-resizable nth - nth-unsafe set-nth set-nth-unsafe length set-length - lengthen ; +like new-sequence new-resizable nth nth-unsafe +set-nth set-nth-unsafe length set-length +lengthen ; PROTOCOL: assoc-protocol - at* assoc-size >alist set-at assoc-clone-like - delete-at clear-assoc new-assoc assoc-like ; +at* assoc-size >alist set-at assoc-clone-like +delete-at clear-assoc new-assoc assoc-like ; PROTOCOL: input-stream-protocol - stream-read1 stream-read stream-read-partial stream-readln - stream-read-until ; +stream-read1 stream-read stream-read-partial stream-readln +stream-read-until ; PROTOCOL: output-stream-protocol - stream-flush stream-write1 stream-write stream-format - stream-nl make-span-stream make-block-stream - make-cell-stream stream-write-table ; +stream-flush stream-write1 stream-write stream-nl ; PROTOCOL: definition-protocol - where set-where forget uses - synopsis* definer definition ; +where set-where forget uses +synopsis* definer definition ; diff --git a/basis/io/streams/duplex/duplex.factor b/basis/io/streams/duplex/duplex.factor index 02b56d9ab2..2eb5cc602a 100644 --- a/basis/io/streams/duplex/duplex.factor +++ b/basis/io/streams/duplex/duplex.factor @@ -1,7 +1,7 @@ -! Copyright (C) 2005, 2008 Slava Pestov. +! Copyright (C) 2005, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: kernel continuations destructors io io.encodings -io.encodings.private io.timeouts io.ports summary +io.encodings.private io.timeouts io.ports io.styles summary accessors delegate delegate.protocols ; IN: io.streams.duplex @@ -10,35 +10,33 @@ TUPLE: duplex-stream in out ; C: duplex-stream CONSULT: input-stream-protocol duplex-stream in>> ; - CONSULT: output-stream-protocol duplex-stream out>> ; +CONSULT: formatted-output-stream-protocol duplex-stream out>> ; + +: >duplex-stream< ( stream -- in out ) [ in>> ] [ out>> ] bi ; inline M: duplex-stream set-timeout - [ in>> set-timeout ] [ out>> set-timeout ] 2bi ; + >duplex-stream< [ set-timeout ] bi-curry@ bi ; M: duplex-stream dispose #! The output stream is closed first, in case both streams #! are attached to the same file descriptor, the output #! buffer needs to be flushed before we close the fd. - [ - [ in>> &dispose drop ] - [ out>> &dispose drop ] - bi - ] with-destructors ; + [ >duplex-stream< [ &dispose drop ] bi@ ] with-destructors ; : ( stream-in stream-out encoding -- duplex ) [ re-decode ] [ re-encode ] bi-curry bi* ; : with-stream* ( stream quot -- ) - [ [ in>> ] [ out>> ] bi ] dip with-streams* ; inline + [ >duplex-stream< ] dip with-streams* ; inline : with-stream ( stream quot -- ) - [ [ in>> ] [ out>> ] bi ] dip with-streams ; inline + [ >duplex-stream< ] dip with-streams ; inline ERROR: invalid-duplex-stream ; M: duplex-stream underlying-handle - [ in>> underlying-handle ] - [ out>> underlying-handle ] bi + >duplex-stream< + [ underlying-handle ] bi@ [ = [ invalid-duplex-stream ] when ] keep ;