First program
Create a project, run it, change it, build an executable, format the code and see what a runtime error looks like.
In this page you create a small project, run it, change it, and build an
executable. You need Actus installed. If actus --version does not work
yet, start with Install.
Create a project
Run this in a terminal:
actus new makes a new folder called hello. It also starts a Git
repository in it. If you do not want that, use actus new hello --no-git.
Move into the folder:
What is in the project
The project has four files:
Actus.toml describes the project:
nameandversionidentify your package.edition = "alpha"selects the language edition.entry = "main"says that the program starts at the verb calledmain.target = "host"builds for the computer you are using.profile = "debug"is the default build mode. Add--releaseto a command to get an optimized build.runtime = "std"lets the program use the standard library.
src/main.act is your program:
A verb is a function. main is where the program starts. println writes a
line of text. The word before the colon, string, is the label that says
what kind of value follows. The text between the """ marks above the verb is its
documentation. The compiler keeps it with the verb, and
strict checking asks for it on
every verb.
The .gitignore file keeps build output out of Git.
Run it
actus run builds the program, runs it once, and removes the temporary
executable. The first line is printed by your program. The second line is
printed by actus run to tell you how the program ended. Status 0 means
success.
Actus.lock was written by actus new. It records what the build depends
on, and the other commands read it. You rarely touch it.
Change the program
Open src/main.act and replace its contents with this:
Some things to notice:
println(string: ...)prints text andprintln(int: ...)prints an integer. Each one ends the line. Printing lists the other forms, includingprint, which does not.for erg i in 0..3repeats the loop body foriequal to 0, 1 and 2. The end of the range, 3, is not included.erg temperature: Int = 18;creates a variable that you own. The name comes first, then the type, then the value.if,else ifandelsepick one branch. The condition must be a true-or-false value.
Run it again:
Build an executable
actus run does not keep anything. To get a file you can run on its own,
use actus build:
The message names the file that was built. Your path will be different.
The folder name contains the name of your system, for example
x86_64-unknown-linux-gnu. Run the file by typing the path it printed:
The capsula folder holds everything the compiler generates. You can delete
it at any time. It comes back the next time you build.
Without --emit exe, actus build stops early and only writes an object
file (main.obj). That file is not a program you can run.
Linking an executable needs a linker from your system. On Linux and macOS
Actus calls cc, so a C compiler such as gcc or clang must be
installed. On Windows you need the MSVC toolset and the Windows SDK, which
come with "Build Tools for Visual Studio". See
Install. actus run links an executable too,
so it needs the same tools.
Format the code
actus fmt puts your source in the standard layout, so every Actus program
looks the same. To only check, without changing anything, add --check:
Now make the code untidy on purpose. Change the first println line so it
has no indent and extra spaces:
Check again. The command exits with status 1 when a file needs formatting:
Run actus fmt without --check to fix the file:
The line is back to println(string: "Hello, world!");. If a file is already
formatted, actus fmt leaves it alone and says so:
Check the code
actus check reads your program and looks for mistakes, but it does not
build anything. It is faster than a build.
When something is wrong, check tells you where. Replace the program with
this one, which puts text in an Int variable:
The message gives the file, the error code, the line and column (2:5), and
what went wrong. actus run and actus build report the same error and
stop.
A runtime error
Some mistakes can only be found when the program runs. Replace the program with this one:
A u8 holds numbers from 0 to 255, so 250 plus 10 does not fit. The file is
valid, and actus check accepts it. Run it:
The program printed its first line, then stopped at the addition. The
message says what happened (integer overflow) and where (src/main.act,
line 4, column 13). The line Done. never prints. Status 101 is the status
Actus uses when a runtime check fails. Overflow, division by zero and an
index outside an array are checked in the same way. An executable you built reports the same
message and exits with status 101, which you can see with echo $? in a
Unix shell.
Actus stops here instead of giving a wrong number. If you do want the
number to wrap around or to stay at the largest value, say so with a
different operator. +% wraps and +| saturates:
Where to go next
You have created a project, run it, built it, formatted it and checked it. Continue with Variables and values to learn the language step by step. You can also go back to the Introduction for the ideas behind the language, or look at the releases (opens in a new tab) for what is new.