ludus-scripts/arguments.ld

40 lines
1.1 KiB
Plaintext

& Lesson 5: Passing arguments
& Recall our last function:
& fn box! () -> repeat 4 { fd! (100); rt! (0.25) }
& This function can only draw a box with a side of `100`
& To make our function more flexible, we can add an argument:
fn box! (size) -> repeat 4 {
& ^^^^ This is our size parameter
fd! (size)
& ^^^^ Which we use here: the parameter is a name.
& This name only lasts as long as our function.
rt! (0.25)
}
& How do you call out new `box!` function?
& A note:
& * a *parameter* is the name for a thing we _don't yet know the value of_
& * an *argument* is the name for a parameter _when it is given a concrete value_
& fn box! (size) ...
& ^^^^ This is a parameter: in the function definition
& box! (50)
& ^^ This is an argument: in the function call
& It's a subtle difference, and not especially important
& Plenty of programmers use these words interchangeably
& I just wanted to alert you to these words, their difference, their use.
& In all Ludus documentation, we'll be using them correctly.