Skip to content
Several files

Several files

A program is every file named on the command line. There is nothing to import and nothing to export: a function in one file can call a function in any other.

Put the rule of the game in dice.qdx.

fn dice_round_score(first_die: int, second_die: int) -> int {
  let sum = first_die + second_die;
  if first_die == second_die { sum * 2 } else { sum }
}

And the program that uses it in game.qdx.

fn main() -> int {
  print(concat3("a double six scores ", int_to_text(dice_round_score(6, 6)), "\n"))
}
bootstrap/qdx run std/*.qdx dice.qdx game.qdx
a double six scores 24

One set of names

Every top-level name is shared by the whole program: functions, records, unions and union cases, in your files and in the standard library alike. Declaring print or slice yourself is an error, because the library already has them.

Since nothing is private, a name has to carry its own context. Start the names in a file with the same word, as dice_round_score does. The standard library and the compiler follow the same habit.

Order

Files can be given in any order, and a file can use something declared in a later one. The compiler collects every declaration first.

Which file is the program

With run, the program’s own name, arg(0), is the last file on the command line. Put the file that holds main last.

Leaving the library out

The standard library is not special. A program that calls nothing from it compiles without it. With fn main() -> int { 6 * 7 } in answer.qdx:

bootstrap/qdx answer.qdx -o answer
./answer
echo $?
42