Local Bindings
You can bind local variables inside functions using (let [name value] body). Bindings can be chained and each name is in scope for the body of the local binding.
As an example below we have a function called circle_area which:
- takes one argument
r - binds data to two local variables
piandr_squsing a localletbinding - returns the area of the circle
(let circle_area {r}
(let [pi 3.14159
r_sq (*. r r)]
(*. pi r_sq)))
Note:
- like function names local
letbindings, by convention, usesnake_caseidentifiers - this function has the type
Float -> FloatwhichMondinfers because of the use of*.