Custom Blocks#
Custom blocks, also known as procedures can take input arguments, but unlike functions, they do not return values.
Declaring a Custom Block#
Use the proc
keyword to define a custom block. List argument names separated by
commas.
Use the nowarp
keyword before proc
to make the custom block
run without screen refresh unchecked.
Struct-Typed Arguments#
You can take in struct values by specifying the type name before the argument name.
Default Argument Values#
Just like functions, procedures support default argument values. This allows a caller to skip certain arguments when calling the block.
greet
→ says "Hello, world!"greet "aspizu"
→ says "Hello, aspizu!"
Keyword Arguments#
Procedures can also be called using keyword arguments, specifying each parameter by name. This improves readability, especially when not all parameters are passed or when calling with many arguments.
proc introduce name, title = "developer", location = "unknown" {
say $name & " is a " & $title & " from " & $location;
}
Call it using keyword arguments:
Keyword arguments can be used in any order, as long as required arguments are provided:
Calling Custom Blocks#
Call a procedure using positional or keyword arguments:
Use $argname
inside the block to access the arguments.