Home / Learn

Release v0.4.0

1 Hello, Una

Page 1 of 11

This chapter is your first Una program. It assumes you have written code in another language and have never seen Una: every Una term is explained the first time it appears. If you work with an AI agent, each section ends with what the agent needs to know. You start from an empty directory and write a program that prints "Hello, world". Then you learn the parts every Una program is made of: modules, the main function, functions of your own, and printing. You end with a small program that a store prints every morning, checked, run and tested.

What you'll build

The morning notices of a store: the lines its console prints when the store opens, with the hours, the shipping cutoff, the offer of the day and the café. The program prints:

Output
Harbor Street store
12 Harbor Street, by the ferry
Good morning
------------------------------
Hours
Open today from 9:00 to 18:00
------------------------------
Shipping
Orders placed before 17:00 ship today
------------------------------
Offer
Today's special: desk lamps
------------------------------
Café
The café opens at 10:00
------------------------------
Questions? Ask at the help desk by the main door

You will learn to:

  • set up a package from an empty directory, and run una check and una run in it;
  • read what a module is, and what its first line says;
  • write the main function, where a program starts;
  • write functions of your own, with parameters and a result, and call them;
  • print on the console, and say in a function's header that it prints.

Download this chapter's packages: each step is a package under steps/, and the chapter's program is day-to-day/; run una check . and una run . in one.

Why it works this way

A program grows. The first version prints one line; a year later it has hundreds of lines, written by several people. Two things make such a program hard to change. The first is not knowing where anything is: the same sentence typed in five places, so that a change misses one. The second is not knowing what a piece of code does to the world outside the program: whether it only computes, or also prints, writes files or sends messages.

Una answers both from the first program on. Code lives in modules, files with a name, and the work is split into functions, each with a name, its inputs and its result, so that each thing is written once. The first lines of a public function, its header, also say what it may do outside the program. A public function that prints says so, and Una refuses one that prints without saying it. You can read such a header and know what the function may do, without reading its body.

Key idea

In Una, a public function's first lines say what it takes, what it gives back, and what it may do outside the program, such as printing.

View the Markdown

Next:1.1 Your first program: hello world