Skip to content
TurtleKitty edited this page May 18, 2017 · 3 revisions

stream

A stream is a window to the world outside: a source of data or a sink. It can be a connection to a file, a pipe, a socket, or even a text. Some methods work on both stream types; others make sense only for one or the other.

predicate

(stream? x)

messages

x.type -> stream

x.to-bool -> true

x.input? -> true if input stream, false otherwise

x.output? -> true if output stream, false otherwise

x.open? -> true if the stream is open, false if it has been closed

x.close -> closes the stream

source messages

x.ready? -> returns true if there are runes waiting to be read

x.read -> reads a Vaquero object

(def sexprs "(foo (bar baz)) (quux 2 3)")
sexprs.to-stream.read
     -> (foo (bar baz))

x.read-rune -> reads a single character

x.peek-rune -> looks at the next character on the stream without removing it

(def fb "foonballardy!!!")
(let (p fb.to-stream)
    p.peek-rune -> "f"
    p.read-rune -> "f"
    p.peek-rune -> "o"
    p.peek-rune -> "o"

x.read-line -> reads runes up to the next newline and returns a text

(def lines "uno\ndos\ntres")
(let (p lines.to-stream)
    p.read-line)
        -> "uno"

x.to-list -> reads all lines until EOF and returns a list of texts

(def lines "uno\ndos\ntres")
(let (p lines.to-stream)
    p.to-list)
        -> ("uno" "dos" "tres")

x.to-text -> reads all characters until EOF and returns a single text

x.to-seq -> reads all Vaquero objects until EOF and returns a list of them

(def sexprs "(foo (bar baz)) (quux 2 3)")
sexprs.to-stream.to-seq
    -> ((foo (bar baz)) (quux 2 3))

(x.read-n n) -> reads n runes and returns a text

(def fb "foonballardy!!!")
(let (p fb.to-stream)
    (p.read-token 6)) -> "foonba"

(x.read-while "runes") -> reads runes as like as they are found in the given text and returns a text of the read runes

(def fb "foonballardy!!!")
(let (p fb.to-stream)
    (p.read-token-while "fon")) -> "foon"

(x.read-until "runes") -> reads runes until one is found from the given text and returns a text of the read runes

(def fb "foonballardy!!!")
(let (p fb.to-stream)
    (p.read-token-until "!")) -> "foonballardy"

(x.skip n) -> discards n runes from the stream

(def fb "foonballardy!!!")
(let (p fb.to-stream)
    (p.skip 4)
    p.peek-rune) -> "b"

(x.skip-while "runes") -> discards runes as long as the rune is found in the given text

(def fb "foonballardy!!!")
(let (p fb.to-stream)
    (p.skip-while "fo")
    p.peek-rune) -> "n"

(x.skip-until "runes") -> discards runes until it finds one from the given text

(def fb "foonballardy!!!")
(let (p fb.to-stream)
    (p.skip-until "b")
    p.peek-rune) -> "b"

sink messages

(x.write object) -> Calls the view method of the object and prints the result in a way that can be read back in by the input stream method read.

(x.print object) -> Prints the object. Differs from write primarily for text objects.

(x.say object) -> Like print, but adds a newline to the end.

x.nl -> prints a newline

x.flush -> flushes any buffered output.

Clone this wiki locally