Hello World
Your First Program
Section titled “Your First Program”Create a file called hello.zap:
fn main() { print("Hello, World!")}Run it:
zap run hello.zapOutput:
Hello, World!What Just Happened?
Section titled “What Just Happened?”Let’s break down every part of that tiny program:
fn main()
Section titled “fn main()”Every Zap program starts execution in the main function. It takes no
arguments and returns nothing (implicitly returns void).
print(...)
Section titled “print(...)”print is a built-in function available everywhere without an import. It
writes its argument to standard output followed by a newline.
"Hello, World!"
Section titled “"Hello, World!"”This is a string literal — a sequence of characters enclosed in double quotes. Zap strings are UTF-8 encoded and immutable by default.
Adding Variables
Section titled “Adding Variables”Let’s make it slightly more interesting:
fn main() { let name = "Zap" let version = 1 print("Welcome to " + name + " v" + str(version) + "!")}Welcome to Zap v1!letdeclares an immutable binding.+concatenates strings.str()converts a value to its string representation.
Next Steps
Section titled “Next Steps”Now that you’ve seen Zap in action, explore the Language Reference to learn about types, functions, and control flow.