Lesson 7 of 15
Multiple Parameters
Functions with Multiple Parameters
Add more parameters by listing them in parentheses:
def add (a : Nat) (b : Nat) : Nat := a + b
#eval add 3 5 -- 8
Parameters of the same type can be grouped:
def multiply (x y : Nat) : Nat := x * y
#eval multiply 6 7 -- 42
When calling a function, separate arguments with spaces:
#eval add 10 20 -- 30
Your Turn
Define a function power that computes base ^ exp (base raised to the exponent).
Use the ^ operator for exponentiation.
Lean loading...
Loading...
Click "Run" to execute your code.