Simple input and output
In the previous examples, we used the built-in print
and say
functions to print something to the console (speaking more strictly, to the standard output attached to the program). In this section, you will learn how to perform basic reading from the standard input. This is basically how the program gets what you type onto the console.
To read the input, there are a few functions that you may use directly without loading any modules. They are listed in the following table:
Function | What it does |
| This reads one line from the input and returns it |
| This returns the list of lines containing the data lines that came from the standard input |
| This returns a string that contains the whole input |
The get
and line
functions may be used when you need to parse the input data line by line. For example, call get
as many times as you need if you know the structure of the input, or create a loop and iterate over the array that is returned by lines.
The slurp
function does the job...