Basics of I/O¶
This chapter explains how to use IO operation in Egison.
Let’s start this tutorial by greeting the world. The following is the “Hello world” program in Egison.
-- Save this code as a "hello.egi" file main args := write "Hello, World!\n"
We can execute the above program as follows.
$ egison hello.egi Hello, World!
Egison I/O works via a function named
In main, we can use I/O functions such as
(The list of I/O primitive functions is given in List of Primitive Functions.)
Command Line Arguments¶
Command line arguments are given to the
main as its argument as a collection of strings.
For instance, assume the following program.
-- Save this code as a "args.egi" file main args := write (show args)
If you execute the following commands, you will see that the arguments are given to
$ egison args.egi  $ egison args.egi We can write scripts in Egison ["We", "can", "write", "scripts", "in", "Egison"]
To combine several I/O operations to one, we can use
The feature of
do expressions is serial execution; the I/O functions in the
do expressions are executed from the top in order.
If you know Haskell, you probably notice that it is the same with the
do expressions in Haskell.
-- Save this code as a "repl.egi" file repl := do write "input: " flush () let input := readLine () write input print "" repl main args := repl
Then, execute it as follow.
write "input: ",
readLine () and
write input are executed in the order.
$ egison repl.egi input: Hi Hi input: Hello Hello input: Repl Repl input: ^C $
Check out do expression for more detail.