This chapter describes I/O of Egison. Since Egison is purely functional, Egison I/O has its own special syntax.
First of all, let's greet the world using Egison. The following is a "Hello world" program in Egison.
We can execute the above program as follow.
The collection of them is given for main as its argument.
If you run the interpreter with a filename as its first argument, the interpreter executes the function main. Like the above case, the arguments other than the filename hand main.
For instance, assume we create args.egi.
Then, executing the following commands, you can find the arguments are given for main as $args.
To do more complicated I/O tasks, we can use do expressions, which is similar to the let and letrec expressions. The feature of the do expressions is serial execution. If you know Haskell, you probably notice that it is the same with the do expressions in Haskell. Recall many I/O functions have no return values. In such cases, we can omit to write a variable.
Then, execute it as follow.
When the code is executed, (write "args: "), (read-line) and (write input) are executed in the order.
There are several samples in the directory sample/io/. Please check them.
We can use an io expression to call an IO function as an ordinary function. The following is a definition of the pure-rand function in lib/core/io.egi.
We can use an io expression on the interpreter, too.