Your First Program
Follow each step from download to your first result.
In this tutorial, you will save a short CK program, ask the compiler to check it, and run it. You only need the CalcKernel release for your computer; you do not need to install Rust or another compiler.
You can use any plain-text editor. If you prefer VS Code, the optional CalcKernel extension adds highlighting, live error messages, and code navigation while you write.
1. Download and open the compiler#
Download the latest CalcKernel archive for your computer from the release page. Choose the package for your operating system. Most Windows and Linux computers use x64. On a Mac, Apple chip means arm64 and Intel means x64; you can see this under Apple menu → About This Mac. The Windows processor type is shown in Settings → System → About. The archive contains a compiler file with a platform name, such as ckc-darwin-arm64 or ckc-win32-x64.exe.
Create a folder named CalcKernel inside Downloads and extract the archive into it. Rename the compiler file to ckc on macOS or Linux, or ckc.exe on Windows. It should be directly inside the folder, at Downloads/CalcKernel/ckc (or Downloads/CalcKernel/ckc.exe). You can rename the file in Finder or File Explorer. Then open a terminal in this folder. On macOS or Linux, enter:
cd "$HOME/Downloads/CalcKernel"
./ckc --version
On Windows, open PowerShell and enter:
Set-Location "$HOME\Downloads\CalcKernel"
.\ckc.exe --version
If you chose a different folder, change Downloads/CalcKernel in the command to its location. If the version command prints a CalcKernel version, the compiler is ready. Keep this terminal open for the next steps. You can optionally check the downloaded archive against the .sha256 file linked on the release page; this is a download-integrity check and is not needed to follow the tutorial.
2. Create hello.ck#
Choose either the text-editor steps or the terminal commands. Save the file as hello.ck in the CalcKernel folder you just made.
Using a text editor:
- On macOS, open TextEdit, choose Format → Make Plain Text, paste the program below, and save it in the
CalcKernelfolder ashello.ck. - On Linux, open your text editor, paste the program below, and save it in the
CalcKernelfolder ashello.ck. Make sure it saves plain text and keeps the.ckfile extension. - On Windows, open Notepad, paste the program below, then choose Save As. Save it in the
CalcKernelfolder with the file namehello.ck, choose All files as the file type, and select UTF-8 encoding so Notepad does not add.txt.
Using the terminal instead:
macOS or Linux:
cat > hello.ck <<'EOF'
fn main() -> i32 {
let answer: i32 = 6 * 7;
print_i32(answer);
print_newline();
return 0;
}
EOF
Windows PowerShell:
$program = @'
fn main() -> i32 {
let answer: i32 = 6 * 7;
print_i32(answer);
print_newline();
return 0;
}
'@
[System.IO.File]::WriteAllText("hello.ck", $program, [System.Text.UTF8Encoding]::new($false))
The $program lines hold the CK code as text. The final line saves that text as UTF-8 without an extra marker at the start of the file.
3. Check the file, then run it#
First, check that the code is written in valid CK.
macOS or Linux:
./ckc check hello.ck
./ckc run hello.ck
Windows PowerShell:
.\ckc.exe check .\hello.ck
.\ckc.exe run .\hello.ck
The first command checks the program and reports OK: hello.ck if it is valid. It does not create a program file. The second command runs the program. Its output is:
42
4. What each line does#
fn main() -> i32 {
let answer: i32 = 6 * 7;
print_i32(answer);
print_newline();
return 0;
}
fn main()names the starting point of a small program. CK starts here when you useckc run.-> i32says that the program finishes by returning a whole number. Returning0means it finished successfully.let answer: i32 = 6 * 7;works out6 * 7and gives the result the nameanswer.i32is CK's type for a whole number that can be positive, zero, or negative.print_i32(answer);writes that number to the terminal.print_newline();moves the terminal to the next line. CK's number-printing command does not add a line break by itself.}marks the end ofmain.
Every instruction in this example ends with ;. Braces { } mark the beginning and end of a group of instructions.
5. Make one small change#
Change the calculation to 20 + 22:
fn main() -> i32 {
let answer: i32 = 20 + 22;
print_i32(answer);
print_newline();
return 0;
}
Save hello.ck and run the same run command again. It still prints 42. Try 20 + 23 next; the output becomes 43. You have changed the calculation without changing the part that prints the answer.
If something goes wrong#
The terminal says the command cannot be found. Make sure you renamed the downloaded compiler to
ckcorckc.exe, and that your terminal is in theCalcKernelfolder. The command is./ckc --versionon macOS or Linux, or.\ckc.exe --versionin PowerShell.macOS or Linux says permission denied. In the same terminal and folder, run this command, then try
./ckc --versionagain:chmod +x ./ckcIt cannot find
hello.ck. The file may have been saved in a different folder, or your editor may have named ithello.ck.txt. Make sure the terminal and file are in the same folder and that the full name ends with.ck.It says
mainis missing. Check that the first line is exactlyfn main() -> i32 {and that the braces are present.It says Native support is unavailable. You may have opened a different
ckcfile. Download the official release archive linked above, then use the platform file from that archive.It points to a line in your program. Look for a missing
;, a missing brace, or a spelling difference. Run./ckc check hello.ckon macOS or Linux, or.\ckc.exe check .\hello.ckin PowerShell, after each correction.
Next, learn the language one small idea at a time, then try the practice exercises.