On this page:
Port.Output
Port.Output.String
Port.Output.Special
Port.Output.current
Port.Output.current_  error
stdout
stderr
Port.Output.using
Port.Output.open_  file
Port.Output.open_  bytes
Port.Output.open_  string
Port.Output.String.get_  bytes
Port.Output.String.get_  string
Port.Output.open_  nowhere
Port.Output.write_  byte
Port.Output.write_  char
Port.Output.write_  bytes
Port.Output.write_  string
Port.Output.print
Port.Output.println
Port.Output.show
Port.Output.showln
Port.Output.flush
Port.Output.Special.write
Port.Output.Exists  Mode
Port.Output.Exists  Mode.error
Port.Output.Exists  Mode.append
Port.Output.Exists  Mode.update
Port.Output.Exists  Mode.can_  update
Port.Output.Exists  Mode.replace
Port.Output.Exists  Mode.truncate
Port.Output.Exists  Mode.must_  truncate
Port.Output.Exists  Mode.truncate_  replace
8.16.0.1

13.3 Output Ports🔗ℹ

An output port is a port specifically for output, and an output string port writes to a byte string.

annotation

Port.Output

 

annotation

Port.Output.String

 

annotation

Port.Output.Special

The Port.Output annotation recognizes output ports, the Port.Output.String annotation recognizes output string ports, and the Port.Output.Special annotation recognizes ports that support Port.Output.Special.write.

context parameter

Parameter.def Port.Output.current :: Port.Output

 

context parameter

Parameter.def Port.Output.current_error :: Port.Output

 

expression

stdout

 

expression

stderr

 

expression

Port.Output.using port_expr:

  body

  ...

 

expression

Port.Output.using ~file path_expr:

  option; ...

  body

  ...

 

option

 = 

~exists exist_mode_expr

 | 

~exists: exist_mode_body; ...

The Port.Output.current context parameter determines a default port to use when printing, and Port.Output.current determines the default port to use when printing errors.

The stdout form is a shorthand for Port.Output.current(), and the stderr form is a shorthand for Port.Output.current_error().

The Port.Output.using form is analogous to Port.Input.using, but for setting the current output port while evaluating the body sequence. When the ~file variant is used, an ~exists option before the body sequence indicates how to handle the case that a file with the indicated path exists, the same as the ~exists argument to Port.Output.open_file.

function

fun Port.Output.open_file(

  path :: PathString,

  ~exists: exists_flag :: Port.Output.ExistsMode = #'error,

  ~mode: mode :: Port.Mode = #'binary,

  ~permissions: permissions :: Int.in(0, 65535) = 0o666,

  ~replace_permissions: replace_permissions = #false

) :: Port.Output && Port.FileStream

Creates an output port that writes to the path file. The exists_flag argument specifies how to handle/require files that already exist:

Creates an output string port that accumulates the output into a byte string. The optional name argument is used as the name for the returned port.

Port.Output.open_string does the same as Port.Output.open_bytes, but can be used to clarify the intention together with Port.Output.get_string.

Port.Output.String.get_bytes returns the bytes accumulated in the output string port out so far in a freshly allocated byte string (including any bytes written after the port’s current position, if any).

Port.Output.String.get_string is like Port.Output.String.get_bytes, but returns a string converted from the byte string instead.

function

fun Port.Output.open_nowhere(name :: Symbol = #'nowhere)

  :: Port.Output

Creates an output port that discards all output written to the port. The optional name is used as the name for the returned port.

method

method (out :: Port.Output).write_byte(b :: Byte) :: Void

 

method

method (out :: Port.Output).write_char(ch :: Char) :: Void

Writes a single byte or a single (UTF-8 encoded) character to out.

method

method (out :: Port.Output).write_bytes(

  bytes :: ReadableBytes,

  ~start: start :: NonnegInt = 0,

  ~end: end :: NonnegInt = bytes.length(),

  ~wait: wait :: Port.WaitMode = #'all

) :: NonnegInt

Writes bytes from the start to end substring of bytes and returns the number of bytes that are written.

Writing to out may block, depending on the backing device. If wait is #'all, then all bytes are written, but not necessarily flushed (see Port.Output.flush), and the result is end-start. If wait is #'one, then writing will block until at least one byte is written and immediately flushed, and the result is the number of bytes written. If wait is #'none, then writing never blocks, and the result is the number of bytes written and immediately flushed. If wait is #'enable_break, then writing blocks in the same way as for #'one, but asynchronous break exceptions are enabled during the wait; in that case, if breaks are disabled before the call to Port.Output.write_bytes either some bytes will be written or a break exception will be thrown, but not both.

method

method (out :: Port.Output).write_string(

  str :: ReadableString,

  ~start: start :: NonnegInt = 0,

  ~end: end :: NonnegInt = bytes.length()

) :: NonnegInt

Like Port.Output.write_bytes with #'all waiting, but writing a (UTF-8 encoded) substring of str from start to end. The result is the number of characters written.

method

method (out :: Port.Output).print(v :: Any, ...,

                                  ~mode: mode :: PrintMode = #'text)

  :: Void

 

method

method (out :: Port.Output).println(v :: Any, ...,

                                    ~mode: mode :: PrintMode = #'text)

  :: Void

 

method

method (out :: Port.Output).show(v :: Any, ...,

                                 ~mode: mode :: PrintMode = #'text)

  :: Void

 

method

method (out :: Port.Output).showln(v :: Any, ...,

                                   ~mode: mode :: PrintMode = #'text)

  :: Void

The same as print, println, show, and showln, but with an output provided as a required initial argument instead of an optional ~out keyword argument.

Flushes the content of out’s buffer.

Writes an arbitrary “special” value to a port that supports content other than just bytes.

Flags for handling existing files when opening output ports.