Hello, Hirundo
You need two things to use Hirundo: the hirundo binary and your favourite
text editor. Write a file, run it. There is no project to configure and no
build step to wait through.
Installing
Get Hirundo from your platform’s package manager:
$ brew install hirundo # macOS
$ apt install hirundo # Debian & friends
$ winget install hirundo # Windows
For the programs in this chapter, the version you just installed will do. Hirundo will also handle a project’s version requirement when you encounter one later.
Your first program
Make a file called hello.hir:
let name = "world"
print("hello, \(name)")
hello, world
The panel below the code shows the result. Run the file yourself:
$ hirundo hello.hir
That’s the whole loop: write a file, run it. Everything else in this book builds on it.
Two things happened in those two lines. let name = "world" bound a value
to a name, and you didn’t have to say the value was text; Hirundo could
see that for itself. Then "hello, \(name)" spliced the value into the
middle of a string. Try a friend’s name, or the nearest houseplant’s. The
interpolation will keep up.
[!note] When we embed a program, the panel below it shows the expected output or, for a program that cannot run, the expected diagnostic.
Your first oops
Two numbers can look compatible and still have different types. Change the program to do some arithmetic:
let price = 2.5
let items = 2
print(price * items)
error: 3:13 cannot multiply a Double by an Int
Hirundo stopped before running the program. 3:13 means line 3, column 13:
the multiplication. price is a decimal number (Double), while items is
a whole number (Int). Hirundo points to the mismatch rather than choosing
a conversion behind your back. Chapter 2 shows how to make that choice
explicitly.
Hirundo reads the file before running it. When it objects, it points.
Trying things out
You don’t need a file for everything. Run hirundo with nothing after it
and you get a prompt:
1> let x = 1
x: Int = 1
2> x * 7
7
3> print("hi")
hi
Type a line and the REPL tells you what it means. Bind a name and it
echoes the type Hirundo inferred (x: Int = 1); type an expression and it
shows the value. Try changing the 7. Keep a prompt open as you read if you
want to test an idea without making another file.
(Ctrl-D to leave.)
Where you are
You can run a program from a file, read a type error while the program is
still just text, and experiment at a prompt. Chapter 2 picks up price
and items where we left them.