Ink by Example: IO

Ink has access to standard input (stdin) and standard output (stdout). You can pipe input to an Ink program in the form echo "Hello, World!" | ink program.ink.

std := load('../vendor/std')
scan := std.scan
log := std.log
f := std.format


To send data to standard output we can use the builtin out, which accepts a string, or the helper std.log which accepts strings and non-strings and adds a linebreak.

out('Hello, with a manual linebreak.
')
log(7) `` print a number
log([1, 2]) `` a composite
log(() => ()) `` a function
log(()) `` or null

For reading in data from standard input, there is the builtin in as well as the helper std.scan which reads in a line.

prompt := (msg, cb) => (
    log(msg)
    scan(cb)
)
` usage:
prompt('Are you sure?', msg => (
    log(msg)
))`

std.format allows us to build template strings and pass in a map of values.

log(f('A message without any passed in values.', {}))
log(f('The time is: {{ time }}.', {time: time()}))

$ ink io.ink
Hello, with a manual linebreak.
7
{0: 1, 1: 2}
(function)
()
A message without any passed in values.
The time is: 1599459668.31363463.

Next example: Loops.