A first program
Work in the root of your checkout, where the std/ directory is. Create a file named first.qdx with one line in it.
fn main() -> int { 42 }Every program has a function named main that takes nothing and returns an int. That number becomes the program’s exit status.
Compile and run
bootstrap/qdx std/*.qdx first.qdx -o first
./first
echo $?The last command prints the exit status of the one before it.
42The compiler was given two things: the standard library, as every file in std/, and your own file. qdx has no import statement. A program is simply all the files you name on the command line, and the order you name them in does not matter.
Print something
A number as an exit status is a narrow way to talk. Replace the contents of first.qdx with this.
fn main() -> int {
print("Mira rolled a six\n")
}print comes from the standard library. It writes bytes to standard output and returns 0, which here also becomes the exit status. The text between quotes is a bytes literal, and \n inside it is a line end.
This time, compile and run in one step.
bootstrap/qdx run std/*.qdx first.qdxMira rolled a sixrun compiles the program in memory and starts it straight away, without writing an executable to disk. It is the quick way to try something, and the rest of this guide uses it.
The program can print now, but it cannot yet work anything out. The next chapter gives it numbers and functions.