]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/io/pipes/pipes.factor
Delete empty unit tests files, remove 1- and 1+, reorder IN: lines in a lot of places...
[factor.git] / basis / io / pipes / pipes.factor
index ca4046fe0783abbb62cb86ddac4e44a82d14b604..8d747086a7b1a32f7367e0388f14c4ec4b856980 100644 (file)
@@ -1,8 +1,8 @@
-! Copyright (C) 2008 Slava Pestov.
+! Copyright (C) 2008, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: io.encodings io.backend io.ports io.streams.duplex
 io splitting grouping sequences namespaces kernel
-destructors math concurrency.combinators accessors
+destructors math concurrency.combinators accessors fry
 arrays continuations quotations system vocabs.loader combinators ;
 IN: io.pipes
 
@@ -15,9 +15,10 @@ HOOK: (pipe) io-backend ( -- pipe )
 
 : <pipe> ( encoding -- stream )
     [
-        >r (pipe) |dispose
-        [ in>> <input-port> ] [ out>> <output-port> ] bi
-        r> <encoder-duplex>
+        [
+            (pipe) |dispose
+            [ in>> <input-port> ] [ out>> <output-port> ] bi
+        ] dip <encoder-duplex>
     ] with-destructors ;
 
 <PRIVATE
@@ -28,12 +29,12 @@ HOOK: (pipe) io-backend ( -- pipe )
 : ?writer ( handle/f -- stream )
     [ <output-port> &dispose ] [ output-stream get ] if* ;
 
-GENERIC: run-pipeline-element ( input-fd output-fd obj -- quot )
+GENERIC: run-pipeline-element ( input-fd output-fd obj -- result )
 
 M: callable run-pipeline-element
     [
-        >r [ ?reader ] [ ?writer ] bi*
-        r> with-streams*
+        [ [ ?reader ] [ ?writer ] bi* ] dip
+        '[ _ call( -- result ) ] with-streams*
     ] with-destructors ;
 
 : <pipes> ( n -- pipes )
@@ -46,14 +47,14 @@ M: callable run-pipeline-element
 PRIVATE>
 
 : run-pipeline ( seq -- results )
-    [ length dup zero? [ drop { } ] [ 1- <pipes> ] if ] keep
+    [ length dup zero? [ drop { } ] [ 1 - <pipes> ] if ] keep
     [
-        >r [ first in>> ] [ second out>> ] bi
-        r> run-pipeline-element
+        [ [ first in>> ] [ second out>> ] bi ] dip
+        run-pipeline-element
     ] 2parallel-map ;
 
 {
-    { [ os unix? ] [ "io.unix.pipes" require ] }
-    { [ os winnt? ] [ "io.windows.nt.pipes" require ] }
+    { [ os unix? ] [ "io.pipes.unix" require ] }
+    { [ os winnt? ] [ "io.pipes.windows.nt" require ] }
     [ ]
 } cond