Skip to main content

Declaring Parameters

The let or use keyword can be used to declare parameters in a function call as variables. The parameters can then be reused later in the parameter list, or in the subblock. This enables more expressive code.

fn Example() {
DoSomethingCool(let numPoints=3, angle=0.5rev / numPoints) { // numPoints reused in the parameter list
DrawSpiral(numPoints) // numPoints reused in the subblock
}
}

If no let or use keyword is used, then a named parameter automatically gets declared as a variable, but only if there is no existing variable of the same name in the current scope.

fn Example() {
DoSomethingCool(
numPoints = 3,
angle = 0.5rev / numPoints, // reuses numPoints parameter as a variable
)
}

If there was already a variable named numPoints in the current scope, then the named parameter would not be declared as a variable.

fn Example() {
let numPoints = 5
DoSomethingCool(
numPoints = 3,
angle = 0.5rev / numPoints, // This uses numPoints=5
)
}

The let keyword could be used to be sure that the named parameter is declared as a variable.