Parameters vs Arguments
Compile-time values versus runtime values.
Parameters vs Arguments is a free Mojo Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Mojo Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Two Kinds of Input
Mojo functions can take two kinds of input: parameters known at compile time, and arguments known at runtime. Knowing the difference is the key.
Arguments Live at Runtime
An argument is an ordinary value you pass when the program runs. Its actual number can change every single time you call the function.
fn square(x: Int) -> Int:
return x * xParameters Live at Compile Time
A parameter is a value the compiler already knows before your program runs. It is fixed and baked right into the generated code. ⚙️
Brackets vs Parentheses
Mojo keeps them visually separate: parameters go in square brackets, while arguments stay in the familiar parentheses.
fn repeat[count: Int](msg: String):
print(msg)Reading the Signature
In repeat[count: Int](msg: String), the count is set at compile time and msg is supplied later when you actually call it.
Compile Time Means Earlier
Think of compile time as the moment Mojo translates your code, long before it runs. Parameters are decided in that earlier phase.
Why Separate Them
Keeping compile-time and runtime values separate lets the compiler specialize and optimize code that the runtime simply cannot.
Passing a Parameter
You supply a parameter in brackets at the call site, just like you supply arguments in parentheses right after it.
repeat[3]("hi")Parameters Must Be Known
A parameter value must be a compile-time constant. You cannot pass a number you only computed while the program was running.
A Familiar Example
The built-in SIMD type takes its element type and width as parameters, then holds real numbers as runtime values inside it.
var v = SIMD[DType.int32, 4](1, 2, 3, 4)The Mental Model
Picture two slots: the bracket slot for compile-time facts, the parenthesis slot for runtime data. Mojo treats them very differently.
Quick Check
Tell apart parameters and arguments in Mojo.
Recap
You learned the split: parameters are compile-time values in brackets, arguments are runtime values in parentheses. That divide powers Mojo's speed. 🎯
Frequently asked questions
Is the “Parameters vs Arguments” lesson free?
Yes — the full text of “Parameters vs Arguments” is free to read here on the web, and the Mojo Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Mojo Academy course, upgrade to CoddyKit PRO.
What will I learn in “Parameters vs Arguments”?
Compile-time values versus runtime values. You practise Mojo Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Mojo Academy?
No prior experience is required. Mojo Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Parameters vs Arguments” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Mojo Academy lesson?
Yes. Every Mojo Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Parameters vs Arguments
- Parameterized Functions
- Parameterized Structs
- Why Compile-Time Wins Speed