Skip to content

std.io ​

The input/output module. It provides standard output and standard input reading. Whole-file reading and writing, as well as directory and path operations, are covered in std.fs; incremental I/O at the handle level is covered in std.os.

yaoxiang
use std.io

Platform Availability ​

read_line relies on operating system I/O and is not exported on the wasm32 target. print / println / format_fallback are available on all targets.

Function Overview ​

FunctionSignature
print(...args) -> Void
println(...args) -> ()
read_line() -> String
format_fallback(value, type_name: &String) -> String

Functions ​

print ​

yaoxiang
print: (...args) -> Void

Outputs all arguments in order, without a trailing newline. Multiple arguments are separated by a single space.

Arguments are formatted as follows: String values output their contents directly; List / Dict / Tuple values are expanded recursively; all other values are output as literals.

yaoxiang

main: () -> Void = {
    print("hello")
    print(" ")
    print("world")
    println("")
}

println ​

yaoxiang
println: (...args) -> ()

Behaves like print, but appends a newline to the output.

When called without arguments, println() outputs a blank line:

yaoxiang
main: () -> Void = {
    println("Hello, YaoXiang!")
}

read_line ​

yaoxiang
read_line: () -> String

Reads a line from standard input.

Returns: the entire line read, with the trailing newline removed (\n or \r\n). Error: throws E6007 if the read fails.

Interactive examples cannot be run automatically in the documentation. The following is for reference only.

yaoxiang
use std.io

main: () -> Void = {
    println("请输入你的名字:")
    name = io.read_line()
    println("你好," + name)
}

format_fallback ​

yaoxiang
format_fallback: (value, type_name: &String) -> String

Formats a value according to its type name, producing a prefixed representation such as int(42) / array([1, 2, 3]). Structures are printed by field value (Point(1, 2)), without heap addresses—the address differs on every run, and printing it would make the program's output irreproducible.

This is an internal helper function used by the runtime's generic formatting path callback. In everyday code, use std.convert.to_string directly.

  • value —— any value
  • type_name —— type-name string

Returns: a string representation with a type prefix.

yaoxiang
use std.assert
use std.io
use std.string

main: () -> Void = {
    s = io.format_fallback(42, "int")
    assert(string.contains(s, "42"))
}
  • std.fs —— File, directory, and path operations
  • std.os —— File handles and environment variables
  • std.convert —— Converting values to strings