Skip to content
This repository was archived by the owner on Jul 9, 2022. It is now read-only.

Implicit IO

LyricLy edited this page Aug 14, 2017 · 4 revisions

A recent addition to Ly is implicit input and output, so that you don't always have to explicitly use the input and output functions.

If you don't want to use this feature, that's fine. You don't have to. It's totally avoidable and flexible. Use it only if you want to.

Implicit input

Implicit input will occur whenever an instruction attempts to pop from the stack when it is empty.
Instead of raising an error, the interpreter will read a number (character I/O is not supported implicitly) from STDIN and push it to the stack.
This is slightly different from the n instruction in that it reads the input backwards for convenience. For example, an input of 43 54 will return [43, 54] and not [54, 43].
If there is no more input to take implicitly, 0will be used instead.
Implicit input is never pushed to the stack; it is delivered straight to instructions that attempt to pop from the stack.

In addition to normal implicit input, instructions that perform an action on the entire stack will implicitly dump STDIN (take lines of input until EOF/empty line) onto the stack.

If an invalid input is passed implicitly, an EmptyStackError is raised.

Implicit output

Implicit output occurs at the end of a program if that program is still running. Thus, ending execution with the ; instruction before the end of the program will disable implicit output. Implicit output will print the entire stack that is under the stack pointer, with a space in between numbers.

Clone this wiki locally