]> gitweb.factorcode.org Git - factor.git/commitdiff
with-string is now string-out, string-in combinator, documentation updates
authorSlava Pestov <slava@factorcode.org>
Sun, 19 Jun 2005 22:53:58 +0000 (22:53 +0000)
committerSlava Pestov <slava@factorcode.org>
Sun, 19 Jun 2005 22:53:58 +0000 (22:53 +0000)
22 files changed:
contrib/algebra/tests.factor
contrib/cont-responder/cont-examples.factor
contrib/cont-responder/eval-responder.factor
contrib/cont-responder/todo-example.factor
doc/handbook.tex
library/bootstrap/boot-stage1.factor
library/eval-catch.factor
library/httpd/browser-responder.factor
library/httpd/cont-responder.factor
library/inference/test.factor
library/io/files.factor
library/io/lines.factor
library/io/stream.factor
library/test/combinators.factor
library/test/generic.factor
library/test/httpd/html.factor
library/test/httpd/httpd.factor
library/test/image.factor
library/test/interpreter.factor
library/test/io/io.factor
library/test/stream.factor
library/tools/jedit-wire.factor

index ec1b73810cefdae3a9481bcebaf2fa28a009259c..9796296e7604b5e053765fb1ca3ed1c6810a8a44 100644 (file)
@@ -9,4 +9,4 @@ USING: algebra test math kernel prettyprint io ;
 [ [ + x 1/2 ] ] [ ([ x + 3 / 6 ]) fold-consts ] unit-test
 [ 1 ] [ 5 3 [ x ] ([ sq x + 6 ]) install-mod eval-infix call ] unit-test
 [ 1.0 -1.0 ] [ 1 0 -1 quadratic-formula ] unit-test
-[ "IN: algebra :| quadratic-formula a b c |:\n    [ [ [ - b ] / 2 * a ] +- [ sqrt [ sq b ] - 4 * a * c ] / 2 * a ] ;\n" ] [ [ \ quadratic-formula  see ] with-string ] unit-test
+[ "IN: algebra :| quadratic-formula a b c |:\n    [ [ [ - b ] / 2 * a ] +- [ sqrt [ sq b ] - 4 * a * c ] / 2 * a ] ;\n" ] [ [ \ quadratic-formula  see ] string-out ] unit-test
index 0d94a61f1d320af5b17c4038c350881b324e94e3..42303c101a94c1f77c7f76cf58761add86b4618c 100644 (file)
@@ -67,7 +67,7 @@ USE: sequences
 
 : test-cont-responder2 ( - )
   #! Test the cont-responder responder by displaying a few pages in a loop.
-  [ "one" "two" "three" "four" ] [ display-page [ .s ] with-string display-page ]  each 
+  [ "one" "two" "three" "four" ] [ display-page [ .s ] string-out display-page ]  each 
   "Done!" display-page  ;
 
 : test-cont-responder3 ( - )
@@ -79,7 +79,7 @@ USE: sequences
     "Menu" [ 
       <ol> 
         <li> "Test responder1" [ test-cont-responder ] quot-href </li>
-        <li> "Test responder2" [ [ .s ] with-string display-page test-cont-responder2 [ .s ] with-string display-page ] quot-href </li>
+        <li> "Test responder2" [ [ .s ] string-out display-page test-cont-responder2 [ .s ] string-out display-page ] quot-href </li>
       </ol>
     ] html-document 
   ] show drop ;
index a1fe8e1e2d7efa59a639d7175883f9147d6fb983..d0bfa814cb7768dda0abfa117e788da81fcbc0aa 100644 (file)
@@ -89,7 +89,7 @@ USE: sequences
   #! Write out html to display the stack.
   <table border= "1" table> 
     <tr> <th> "Callstack" write </th> </tr>
-    [ <tr> <td> [ unparse write ] with-string write-eval-link </td> </tr> ] each
+    [ <tr> <td> [ unparse write ] string-out write-eval-link </td> </tr> ] each
   </table> ;
 
 : display-clear-history-link ( -- )
index 120e256105e78af109a1ad7086024aaa555bc40b..287e22b5acbe27e73fa71602f02818a25ca5d1ab 100644 (file)
@@ -114,7 +114,7 @@ USE: sequences
 
 : show-stack-page ( -- )
   #! Debug function to show a page containing the current call stack.
-  [ .s ] with-string chars>entities show-message-page ;
+  [ .s ] string-out chars>entities show-message-page ;
 
 : row ( list -- )
   #! Output an html TR row with each element of the list
index 3cea508d6ac806f5a5fe16c8ff664cbc18e7594c..7fe65dd47fe6bb538048ecd9c08cc049f43c8449 100644 (file)
@@ -2528,7 +2528,7 @@ Tests if the object at the top of the stack is a string buffer.
 }
 Turns any type of sequence into a string buffer. Given a string buffer, this makes a fresh copy.
 
-String buffers support the stream output protocol (\ref{stream-protocol}).
+String buffers support the stream input and output protocol (\ref{string-streams}).
 
 \section{Virtual sequences}\label{virtual-seq}
 
@@ -3725,7 +3725,7 @@ description={a stream that implements the \texttt{stream-write-attr}, \texttt{st
 There are various subsets of the stream protocol that a class can implement so that its instances may be used as streams. The following generic word is mandatory.
 
 \wordtable{
-\vocabulary{streams}
+\vocabulary{io}
 \genericword{stream-close}{stream-close ( s -- )}
 }
 Releases any external resources associated with the stream, such as file handles and network connections. No further operations can be performed on the stream after this call.
@@ -3734,12 +3734,18 @@ You must close streams after you are finished working with them. A convenient wa
 
 The following two words are optional, and should be implemented on input streams.
 \wordtable{
-\vocabulary{streams}
+\vocabulary{io}
 \genericword{stream-readln}{stream-readln ( s -- str/f )}
 }
 Reads a line of text and outputs it on the stack. If the end of the stream has been reached, outputs \texttt{f}. The precise meaning of a ``line'' depends on the stream; with file and network streams, it is a range of characters terminated by \verb|\n|, \verb|\r| or \verb|\r\n|.
 \wordtable{
-\vocabulary{streams}
+\vocabulary{io}
+\genericword{stream-read1}{stream-read1 ( s -- char/f )}
+}
+Reads a character from the stream. If the end of the stream is reached, outputs \verb|f|.
+
+\wordtable{
+\vocabulary{io}
 \genericword{stream-read}{stream-read ( n s -- str )}
 }
 Reads \texttt{n} characters from the stream. If less than \texttt{n} characters are available before the end of the stream, a shorter string is output.
@@ -3747,7 +3753,7 @@ Reads \texttt{n} characters from the stream. If less than \texttt{n} characters
 The following three words are optional, and should be implemented on output streams.
 
 \wordtable{
-\vocabulary{streams}
+\vocabulary{io}
 \genericword{stream-write-attr}{stream-write-attr ( str/ch attrs s -- )}
 }
 Outputs a character or string to the stream. This might not result in immediate output to the underlying resource if the stream performs buffering, like all file and network streams do. 
@@ -3755,13 +3761,13 @@ Outputs a character or string to the stream. This might not result in immediate
 The \texttt{attrs} parameter is an association list holding style information, and it is ignored by most streams -- one exception is HTML streams (\ref{html}). Most of the time either the \texttt{stream-write} or \texttt{stream-print} word is used. They are described in the next section.
 
 \wordtable{
-\vocabulary{streams}
+\vocabulary{io}
 \genericword{stream-flush}{stream-flush ( s -- )}
 }
 Ensures all pending output operations are been complete. With many output streams, written output is buffered and not sent to the underlying resource until either the buffer is full, or an explicit call to \texttt{stream-flush} is made.
 
 \wordtable{
-\vocabulary{streams}
+\vocabulary{io}
 \genericword{stream-auto-flush}{stream-auto-flush ( s -- )}
 }
 Ensures the user sees prior output. It is not as strong as \texttt{stream-flush}. The contract is as follows: if the stream is connected to an interactive end-point such as a terminal, \texttt{stream-auto-flush} should execute \texttt{stream-flush}. If the stream is a file or network stream used for ``batch'' operations, this word should have an empty definition.
@@ -3774,13 +3780,13 @@ With some streams, the above operations may suspend the current thread and execu
 
 The following three words are implemented in terms of the stream protocol, and should work with any stream supporting the required underlying operations.
 \wordtable{
-\vocabulary{streams}
+\vocabulary{io}
 \ordinaryword{stream-read1}{stream-read1 ( stream -- ch/f )}
 
 }
 Reads a single character using \texttt{stream-read} and outputs the character. If the end of the stream has been reached, outputs \texttt{f}.
 \wordtable{
-\vocabulary{streams}
+\vocabulary{io}
 \ordinaryword{stream-write}{stream-write ( string stream -- )}
 
 }
@@ -3790,7 +3796,7 @@ Outputs a character or string to the stream, without any specific style informat
     f swap stream-write-attr ;
 \end{verbatim}
 \wordtable{
-\vocabulary{streams}
+\vocabulary{io}
 \ordinaryword{stream-print}{stream-print ( string stream -- )}
 
 }
@@ -3803,7 +3809,7 @@ description={the value of the \texttt{stdio} variable, used by various words as
 description={see default stream}}
 Various words take an implicit stream parameter from the \texttt{stdio} variable to reduce stack shuffling.
 \wordtable{
-\vocabulary{stdio}
+\vocabulary{io}
 \ordinaryword{close}{close ( -- )}
 
 }
@@ -3811,7 +3817,7 @@ Various words take an implicit stream parameter from the \texttt{stdio} variable
 : close stdio get stream-close ;
 \end{verbatim}
 \wordtable{
-\vocabulary{stdio}
+\vocabulary{io}
 \ordinaryword{read-line}{read-line ( -- str/f )}
 
 }
@@ -3819,7 +3825,7 @@ Various words take an implicit stream parameter from the \texttt{stdio} variable
 : read-line stdio get stream-readln ;
 \end{verbatim}
 \wordtable{
-\vocabulary{stdio}
+\vocabulary{io}
 \ordinaryword{read}{read ( n -- str )}
 
 }
@@ -3827,7 +3833,7 @@ Various words take an implicit stream parameter from the \texttt{stdio} variable
 : read stdio get stream-read ;
 \end{verbatim}
 \wordtable{
-\vocabulary{stdio}
+\vocabulary{io}
 \ordinaryword{read1}{read1 ( n -- str )}
 
 }
@@ -3835,7 +3841,7 @@ Various words take an implicit stream parameter from the \texttt{stdio} variable
 : read1 stdio get stream-read1 ;
 \end{verbatim}
 \wordtable{
-\vocabulary{stdio}
+\vocabulary{io}
 \ordinaryword{write}{write ( str -- )}
 
 }
@@ -3843,7 +3849,7 @@ Various words take an implicit stream parameter from the \texttt{stdio} variable
 : write stdio get stream-write ;
 \end{verbatim}
 \wordtable{
-\vocabulary{stdio}
+\vocabulary{io}
 \ordinaryword{write-attr}{write-attr ( str attrs -- )}
 
 }
@@ -3851,7 +3857,7 @@ Various words take an implicit stream parameter from the \texttt{stdio} variable
 : write-attr stdio get stream-write-attr ;
 \end{verbatim}
 \wordtable{
-\vocabulary{stdio}
+\vocabulary{io}
 \ordinaryword{print}{print ( str -- )}
 
 }
@@ -3859,7 +3865,7 @@ Various words take an implicit stream parameter from the \texttt{stdio} variable
 : print stdio get stream-print ;
 \end{verbatim}
 \wordtable{
-\vocabulary{stdio}
+\vocabulary{io}
 \ordinaryword{terpri}{terpri ( -- )}
 
 }
@@ -3867,7 +3873,7 @@ Various words take an implicit stream parameter from the \texttt{stdio} variable
 : terpri "\n" stdio get stream-write ;
 \end{verbatim}
 \wordtable{
-\vocabulary{stdio}
+\vocabulary{io}
 \ordinaryword{flush}{flush ( -- )}
 
 }
@@ -3878,25 +3884,42 @@ Various words take an implicit stream parameter from the \texttt{stdio} variable
 The value of the \texttt{stdio} variable can be rebound inside a quotation with the following combinators.
 
 \wordtable{
-\vocabulary{stdio}
+\vocabulary{io}
 \ordinaryword{with-stream}{with-stream ( stream quot -- )}
 }
 Calls the quotation in a new dynamic scope, with the \texttt{stdio} variable set to \texttt{stream}. The stream is closed when the quotation returns or if an exception
 is thrown.
 \wordtable{
-\vocabulary{stdio}
+\vocabulary{io}
 \ordinaryword{with-stream*}{with-stream* ( stream quot -- )}
 }
 Like \verb|with-stream| extend the stream is only closed in the case of an error.
 
-\wordtable{
-\vocabulary{stdio}
-\ordinaryword{with-string}{with-string ( quot -- string )}
+\section{String streams}\label{string-streams}
 
+Calling stream output words on a string buffer will append text to the string buffer.
+
+\wordtable{
+\vocabulary{io}
+\ordinaryword{string-out}{string-out ( quot -- string )}
 }
 Calls the quotation in a new dynamic scope, with the \texttt{stdio} variable set to a new string buffer. Executing \texttt{write}, \texttt{write-attr} or \texttt{print} will append text to the string buffer. When the quotation returns, the string buffer is coverted to
 a string and returned.
 
+String buffers also support the input stream protocol, with the exception of \verb|stream-readln|. Characters are read in reverse. Usually, string buffers are not used as input streams directly, since lines cannot be read and the input string must be reversed. Instead, the following pair of words is used.
+
+\wordtable{
+\vocabulary{io}
+\ordinaryword{<string-reader>}{<string-reader> ( string -- stream )}
+}
+Creates a new stream for reading the characters of the string in order. This converts the string to a string buffer, reverses it, and wraps it in a line stream (\ref{special-streams})..
+
+\wordtable{
+\vocabulary{io}
+\ordinaryword{string-in}{string-in ( string quot -- )}
+}
+Calls the quotation in a new dynamic scope, with the \texttt{stdio} variable set to a new string reader that reads from the given string. Executing \texttt{read1}, \texttt{read} or \texttt{read-line} will take text from the string reader.
+
 \section{Reading and writing binary data}
 
 \glossary{name=big endian,
@@ -3926,13 +3949,13 @@ Value:&\verb|ca|&\verb|fe|&\verb|ba|&\verb|be|\\
 With the above explanation of byte ordering, the behavior of the following words should be clear.
 
 \wordtable{
-\vocabulary{stdio}
+\vocabulary{io}
 \ordinaryword{be>}{be> ( seq -- x )}
 \ordinaryword{le>}{le> ( seq -- x )}
 }
 Converts a sequence of bytes in big or little endian order into an unsigned integer.
 \wordtable{
-\vocabulary{stdio}
+\vocabulary{io}
 \ordinaryword{>be}{>be ( x n -- string )}
 \ordinaryword{>le}{>le ( x n -- string )}
 }
@@ -3941,7 +3964,7 @@ Converts an integer into a string of $n$ bytes in big or little endian order. Tr
 These words are then composed with \verb|read| and \verb|write| to form a set of words for reading and writing packed integers on the default stream (\ref{stdio}).
 
 \wordtable{
-\vocabulary{stdio}
+\vocabulary{io}
 \ordinaryword{read-be2}{read-be2 ( -- n )}
 \ordinaryword{read-le2}{read-le2 ( -- n )}
 \ordinaryword{read-be4}{read-be4 ( -- n )}
@@ -3965,13 +3988,13 @@ description=an input stream reading from a file}
 \glossary{name=file writer,
 description=an output stream writing to a file}
 \wordtable{
-\vocabulary{streams}
+\vocabulary{io}
 \ordinaryword{<file-reader>}{<file-reader> ( path -- stream )}
 
 }
 Opens the file for reading and returns an input stream. An exception is thrown if the file could not be opened.
 \wordtable{
-\vocabulary{streams}
+\vocabulary{io}
 \ordinaryword{<file-writer>}{<file-writer> ( path -- stream )}
 
 }
@@ -3980,7 +4003,7 @@ Opens the file for writing and returns an output stream. An exception is thrown
 The following set of words provide access to file system metadata.
 
 \wordtable{
-\vocabulary{files}
+\vocabulary{io}
 \ordinaryword{file-extension}{file-extension~( path -- string/f )}
 
 }
@@ -3990,25 +4013,25 @@ Outputs the remainder of the file's name after the last occurrence of a period,
 \textbf{"txt"}
 \end{alltt}
 \wordtable{
-\vocabulary{files}
+\vocabulary{io}
 \ordinaryword{exists?}{exists?~( path -- ?~)}
 
 }
 Tests if a file exists.
 \wordtable{
-\vocabulary{files}
+\vocabulary{io}
 \ordinaryword{directory?}{directory?~( path -- ?~)}
 
 }
 Tests if a file is a directory. Outputs \texttt{f} if the file does not exist..
 \wordtable{
-\vocabulary{files}
+\vocabulary{io}
 \ordinaryword{file-length}{file-length~( path -- n/f~)}
 
 }
 Outputs the size of the file, or \texttt{f} if it does not exist.
 \wordtable{
-\vocabulary{files}
+\vocabulary{io}
 \ordinaryword{stat}{stat~( path -- list~)}
 
 }
@@ -4027,32 +4050,32 @@ description=a stream listening on a TCP/IP socket}
 \glossary{name=client stream,
 description=a bidirectional stream for an to end-point of a TCP/IP connection}
 \wordtable{
-\vocabulary{streams}
+\vocabulary{io}
 \ordinaryword{<client>}{<client>~( host port -- stream~)}
 
 }
 Connects to TCP/IP port number \texttt{port} on the host named by \texttt{host}, and returns a bidirectional stream. An exception is thrown if the connection attempt fails.
 \wordtable{
-\vocabulary{streams}
+\vocabulary{io}
 \ordinaryword{<server>}{<server>~( port -- server~)}
 
 }
 Begins listening for connections to \texttt{port} on all network interfaces. An exception is thrown if the port cannot be opened. The returned object can be used as an input to the \texttt{stream-close} and \texttt{accept} words.
 \wordtable{
-\vocabulary{streams}
+\vocabulary{io}
 \ordinaryword{accept}{accept~( server -- stream~)}
 
 }
 Waits for a connection to the port number that \texttt{server} is listening on, and outputs a bidirectional stream when the connection has been established.  An exception is thrown if an error occurs.
 \wordtable{
-\vocabulary{streams}
+\vocabulary{io}
 \ordinaryword{client-stream-host}{client-stream-host~( stream -- port~)}
 \ordinaryword{client-stream-port}{client-stream-port~( stream -- port~)}
 
 }
 Outputs the IP address as a dotted-quad string, and the local port number, respectively, of a client socket returned from \texttt{accept}.
 
-\section{Special streams}
+\section{Special streams}\label{special-streams}
 
 \glossary{name=null stream,
 description=a bidirectional stream that ignores output and returns end of file on input}
@@ -4060,26 +4083,34 @@ description=a bidirectional stream that ignores output and returns end of file o
 description=a bidirectional delegating to an input stream for input and an output stream for output}
 \glossary{name=wrapper stream,
 description=a bidirectional stream delegating to an underlying stream and providing a namespace where the delegated stream is the default stream}
+\glossary{name=line stream,
+description=an input stream that reads lines a character at a time from an underlying stream}
 
 \wordtable{
-\vocabulary{streams}
+\vocabulary{io}
 \ordinaryword{<null-stream>}{<null-stream>~( -- stream~)}
 }
 Creates a null stream, which ignores output written to it, and returns end of file if an attempt is made to read.
 \wordtable{
-\vocabulary{streams}
+\vocabulary{io}
 \ordinaryword{<duplex-stream>}{<duplex-stream>~( in out -- stream~)}
 }
 Creates a duplex stream. Writing to a duplex stream will write to \texttt{out}, and reading from a duplex stream will read from \texttt{in}. Closing a duplex stream closes both the input and output streams.
 \wordtable{
-\vocabulary{streams}
+\vocabulary{io}
+\ordinaryword{<line-stream>}{<line-stream>~( stream -- stream~)}
+}
+Wrapping a stream in a line stream saves you from having to implement the \verb|stream-readln| generic word. Calling \verb|stream-readln| on a line stream reads a line a character at a time from the underlying stream. Lines are terminated by either \verb|\n|, \verb|\r| or \verb|\r\n|.
+
+\wordtable{
+\vocabulary{io}
 \ordinaryword{<wrapper-stream>}{<wrapper-stream>~( stream -- stream~)}
 }
 Creates a stream wrapping \texttt{stream}. The given stream becomes the delegate of the new wrapper stream, so calling any stream operation on the wrapper passes it on to the delegate.
 You can then define your own tuple class that delegates to a wrapper stream, then override methods on this new tuple class, and use the following combinator in your method definitions.
 
 \wordtable{
-\vocabulary{streams}
+\vocabulary{io}
 \ordinaryword{with-wrapper}{with-wrapper~( stream quot -- ~)}
 }
 Executes the quotation in a dynamic scope where the \texttt{stdio} variable is set to the wrapped stream.
index 680164ee96d2c6929a42cf3ac6facaf12752c03d..4742d80c58665b921ac230a1674fdf3f4911520d 100644 (file)
@@ -51,9 +51,9 @@ parser prettyprint sequences io vectors words ;
 
         "/library/io/stream.factor"
         "/library/io/duplex-stream.factor"
-        "/library/io/string-streams.factor"
         "/library/io/stdio.factor"
         "/library/io/lines.factor"
+        "/library/io/string-streams.factor"
         "/library/io/c-streams.factor"
         "/library/io/files.factor"
 
index 53c0bf8f6632fab48b8d49fa92509802eec17070..68b8833f8ce7894930d23d8edf8082c5a6423e81 100644 (file)
@@ -6,4 +6,4 @@ IN: parser USING: kernel errors io ;
     [ eval ] [ [ print-error debug-help drop ] when* ] catch ;
 
 : eval>string ( in -- out )
-    [ eval-catch ] with-string ;
+    [ eval-catch ] string-out ;
index 0322e95a0cb5647613bfa1c79c9fae9b9e7b7893..7a665b852504cb8a85e3cf6be940db6ed692fa2d 100644 (file)
@@ -72,7 +72,7 @@ sequences ;
   <textarea name= "eval" rows= "30" cols= "80" textarea> 
     [
       >r words r> swap [ over swap dup word-name rot = [ see ] [ drop ] ifte ] each drop    
-    ] with-string chars>entities write
+    ] string-out chars>entities write
   </textarea> <br/>
   "Accept" button ;
 
index eb41b889fb9d60091592a4af52bda6a4aa2ce4d8..746e65364ded433f3dd1c22944fec80374f0882d 100644 (file)
@@ -232,7 +232,7 @@ SYMBOL: callback-cc
   store-callback-cc  redirect-to-here 
   [ 
     expirable register-continuation id>url swap 
-    \ serving-html swons with-string call-exit-continuation
+    \ serving-html swons string-out call-exit-continuation
   ] callcc1 
   nip ;
 
@@ -244,7 +244,7 @@ SYMBOL: callback-cc
   #! use is an optimisation to save having to generate and save a continuation
   #! in that special case.
   store-callback-cc  redirect-to-here 
-  \ serving-html swons with-string call-exit-continuation ;
+  \ serving-html swons string-out call-exit-continuation ;
 
 #! Name of variable for holding initial continuation id that starts
 #! the responder.
index 1cfd98bd136645e60f99bdde2a4dce221bc8fb42..c15ddad68fbd43d6c6e0b6214a223d585d7b688f 100644 (file)
@@ -9,10 +9,10 @@ io strings unparser ;
 
 : infer-fail ( quot error -- )
     "! " , dup string? [ unparse ] unless , "\n" ,
-    [ [ infer ] cons . \ unit-test-fails . ] with-string , ;
+    [ [ infer ] cons . \ unit-test-fails . ] string-out , ;
 
 : infer-pass ( quot effect -- )
-    [ unit . [ infer ] cons . \ unit-test . ] with-string , ;
+    [ unit . [ infer ] cons . \ unit-test . ] string-out , ;
 
 : infer>test ( quot -- str )
     #! Make a string representing a unit test for the stack
index 99e64a924609e9e1d1ed144bd7021bc571bf46be..2543dbdab761719cf92bec0830391ee57da9f91a 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2004, 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: io
-USING: kernel lists sequences strings ;
+USING: kernel lists namespaces sequences strings ;
 
 ! Words for accessing filesystem meta-data.
 
@@ -12,3 +12,12 @@ USING: kernel lists sequences strings ;
 : file-length ( file -- length ) stat third ;
 : file-extension ( filename -- extension )
     "." split cdr dup [ peek ] when ;
+
+DEFER: <file-reader>
+
+: resource-path ( -- path )
+    "resource-path" get [ "." ] unless* ;
+
+: <resource-stream> ( path -- stream )
+    #! Open a file path relative to the Factor source code root.
+    resource-path swap path+ <file-reader> ;
index 2ac316364d0f9ad8d6c64773206cbb87e12c1946..5e2cb50bb0ed32a2826b816049567cbf7668c985 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2004, 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
-USING: errors generic io kernel namespaces sequences ;
+USING: errors generic io kernel math namespaces sequences ;
 
 TUPLE: line-reader cr ;
 
index 5cbd7032329cf89cdd3f4733083bc5b619f97171..d08eff4ca105c8198b027008e1e23760a476c48e 100644 (file)
@@ -64,12 +64,3 @@ C: wrapper-stream ( stream -- stream )
     #! For each element of the alist, change the value to
     #! path " " value
     [ uncons >r swap " " r> append3 cons ] map-with ;
-
-DEFER: <file-reader>
-
-: resource-path ( -- path )
-    "resource-path" get [ "." ] unless* ;
-
-: <resource-stream> ( path -- stream )
-    #! Open a file path relative to the Factor source code root.
-    resource-path swap path+ <file-reader> ;
index aa8b3c18228d1eb9d411c9488cdabc84fbba979a..4ed848bd37ae2279b8a6a3abd5807be597eb6650 100644 (file)
@@ -27,8 +27,8 @@ USE: namespaces
 [ 0 ] [ f [ 0 ] unless* ] unit-test
 [ t ] [ t [ "Hello" ] unless* ] unit-test
 
-[ "2\n" ] [ [ 1 2 [ . ] [ sq . ] ?ifte ] with-string ] unit-test
-[ "9\n" ] [ [ 3 f [ . ] [ sq . ] ?ifte ] with-string ] unit-test
+[ "2\n" ] [ [ 1 2 [ . ] [ sq . ] ?ifte ] string-out ] unit-test
+[ "9\n" ] [ [ 3 f [ . ] [ sq . ] ?ifte ] string-out ] unit-test
 
 [ [ 9 8 7 6 5 4 3 2 1 ] ]
 [ [ 10 [ , ] [ 1 - dup dup 0 = [ drop f ] when ] while ] make-list nip ]
index 056ba90e492d02f6044996e78fd2db4aa989ef26..0cbecc62348756d125a3df4021ec35fb515dc499 100644 (file)
@@ -123,13 +123,13 @@ TUPLE: another-one ;
 
 ! Test generic see and parsing
 [ "IN: temporary\nSYMBOL: bah \nUNION: bah fixnum alien ;\n" ]
-[ [ \ bah see ] with-string ] unit-test
+[ [ \ bah see ] string-out ] unit-test
 
 [ t ] [
     DEFER: not-fixnum
     "IN: temporary\nSYMBOL: not-fixnum \nCOMPLEMENT: not-fixnum fixnum\n"
     dup eval
-    [ \ not-fixnum see ] with-string =
+    [ \ not-fixnum see ] string-out =
 ] unit-test
 
 ! Weird bug
index 4f99890b0c24fbb5c1f6bc2e4b84fd0b56b2c879..3d3a9100e6fefcd20fc566f7a6073aecdceb69ab 100644 (file)
@@ -24,14 +24,14 @@ USE: kernel
         ""
         [ [[ "icon" "library/icons/File.png" ]] ]
         [ drop ] icon-tag
-    ] with-string
+    ] string-out
 ] unit-test
 
 [ "" ]
 [
     [
         [ ] [ drop ] span-tag
-    ] with-string
+    ] string-out
 ] unit-test
 
 [ "<span style='color: #ff00ff; font-family: Monospaced; '>car</span>" ]
@@ -40,7 +40,7 @@ USE: kernel
         [ [ "fg" 255 0 255 ] [[ "font" "Monospaced" ]] ]
         [ drop "car" write ]
         span-tag
-    ] with-string
+    ] string-out
 ] unit-test
 
 : html-write-attr ( string style -- string )
@@ -48,7 +48,7 @@ USE: kernel
 
 [ "hello world" ]
 [
-    [ "hello world" [ ] html-write-attr ] with-string
+    [ "hello world" [ ] html-write-attr ] string-out
 ] unit-test
 
 [ "<span style='color: #ff00ff; font-family: Monospaced; '>car</span>" ]
@@ -57,7 +57,7 @@ USE: kernel
         "car"
         [ [ "fg" 255 0 255 ] [[ "font" "Monospaced" ]] ]
         html-write-attr
-    ] with-string
+    ] string-out
 ] unit-test
 
 [
@@ -65,7 +65,7 @@ USE: kernel
 ] [
     [
         "Foo" [ ] html-document
-    ] with-string
+    ] string-out
 ] unit-test
 
 [
@@ -73,5 +73,5 @@ USE: kernel
 ] [
     [
         "Foo" [ "Hi" write ] simple-html-document
-    ] with-string
+    ] string-out
 ] unit-test
index 7475a68ea976efb0cc5ee0224dc9e7f61921e770..5289aa309cd757fc4c4e7baaf7517bc3b2103511 100644 (file)
@@ -10,7 +10,7 @@ USE: lists
 
 [ "HTTP/1.0 200 OK\nContent-Length: 12\nContent-Type: text/html\n\n" ]
 [
-    [ "text/html" 12 file-response ] with-string
+    [ "text/html" 12 file-response ] string-out
 ] unit-test
 
 [ 5430 ]
index 309806caf5c2bf1674538004fe8f436923e3bc76..25d1a9a1ec6ff6a01794c3382da6185583eeaea1 100644 (file)
@@ -23,7 +23,7 @@ USE: math
 
 [ "\0\0\0\0\u000f\u000e\r\u000c" ]
 [
-    [ image-magic 8 >be write ] with-string
+    [ image-magic 8 >be write ] string-out
 ] unit-test
 
 [
index 5e118060987ec73ef60673cf334790b1f50ca095..7115d7bb1edd68f6a257970d1447a6aa1868f82b 100644 (file)
@@ -77,17 +77,17 @@ USE: sequences
 ] unit-test
 
 [ { "hi\n" } ] [
-    [ [ "hi" print ] with-string ] test-interpreter
+    [ [ "hi" print ] string-out ] test-interpreter
 ] unit-test
 
 [ { "4\n" } ] [
-    [ [ 2 2 + unparse print ] with-string ] test-interpreter
+    [ [ 2 2 + unparse print ] string-out ] test-interpreter
 ] unit-test
 
 [ { "4" } ] [
-    [ [ 0 2 2 + prettyprint* drop ] with-string ] test-interpreter
+    [ [ 0 2 2 + prettyprint* drop ] string-out ] test-interpreter
 ] unit-test
 
 [ { "4\n" } ] [
-    [ [ 2 2 + . ] with-string ] test-interpreter
+    [ [ 2 2 + . ] string-out ] test-interpreter
 ] unit-test
index 87f7613489a7717642e29cfd22b5e8ef47cdf4c7..6accf705010cf449fa17a2dff40e2f675bfa65c3 100644 (file)
@@ -1,5 +1,5 @@
 IN: temporary
-USING: math parser io strings test ;
+USING: io kernel math parser strings test ;
 
 [ 4 ] [ "/library/test/io/no-trailing-eol.factor" run-resource ] unit-test
 
@@ -49,3 +49,14 @@ USING: math parser io strings test ;
 [ "" ] [ 0 read ] unit-test
 
 [ ] [ "123" write 9000 CHAR: x fill write flush ] unit-test
+
+[ "line 1" CHAR: l ]
+[
+    "line 1\nline 2\nline 3" <string-reader>
+    dup stream-readln swap stream-read1
+]
+unit-test
+
+[ f ]
+[ "" <string-reader> stream-readln ]
+unit-test
index fafa3c721e70a0104d59a409154a85b63d78e041..7045359b62a360fae698eb6872f25b508bb12aa1 100644 (file)
@@ -5,4 +5,4 @@ USE: test
 USE: generic
 USE: kernel
 
-[ "xyzzy" ] [ [ "xyzzy" write ] with-string ] unit-test
+[ "xyzzy" ] [ [ "xyzzy" write ] string-out ] unit-test
index ed23e65be3c0ad6e85bd6063d58c1beb230d03fd..bf35f2ffe9c307dfcb918b9e7f09f1f2f03ccef8 100644 (file)
@@ -11,7 +11,7 @@ prettyprint sequences io strings words ;
 ! <n> bytes data
 !
 ! jEdit sends a packet with code to eval, it receives the output
-! captured with with-string.
+! captured with string-out.
 
 : write-len ( seq -- ) length 4 >be write ;
 
@@ -39,7 +39,7 @@ prettyprint sequences io strings words ;
 ! remaining -- input
 : jedit-write-attr ( str style -- )
     CHAR: w write
-    [ swap . . ] with-string
+    [ swap . . ] string-out
     dup write-len write ;
 
 TUPLE: jedit-stream ;