-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstringio.tem
22 lines (21 loc) · 1.55 KB
/
stringio.tem
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
(page "String Port I/O"
(text "See <a href='http://download.plt-scheme.org/doc/372/html/mzscheme/mzscheme-Z-H-11.html#node_sec_11.1.5'>String Ports</a> for background on String Port I/O. ")
(newtable "String Port I/O"
(mac tostring "[body ...]" "Executes the body and returns any output to stdout as a string." (tests (tostring (prn "hello") (prn "world"))))
(mac fromstring "str [body ...]" "Executes the body, using the contents of <code>str</code> as stdin." (tests (fromstring "(+ 1 1)" (sread))))
(op inside "string-output-port" "Returns (as a string) the bytes accumulated
in a string-output-port generated by outstring. This is MzScheme's get-output-string."
(tests (let sop (outstring) (write "hello" sop) (inside sop))))
(op instring "string [name]" "Creates an input port to read UTF-8 bytes from the
string. This is MzScheme's open-input-string."
(tests (readline (instring "hello"))))
(op outstring "[name]" "Creates an output-port that accumulates the output
into a byte string. The string can be retrieved with inside. This is
MzScheme's open-output-string."
(tests (outstring))
)
(mac w/instring "var str [body ...]" "Creates an string input-port from str with instring, assigns it to var, executes body, and then closes the input port." (tests))
(mac w/outstring "var [body ...]" "Creates a string output-port with outstring, assigns it to var, and executes body." (tests))
(def readstring1 "string [eof]" "Reads a Lisp form from the string. If the end of file is reached, nil is returned or the specified eof value." (tests))
)
)