-
Notifications
You must be signed in to change notification settings - Fork 0
Functions
In Pikt, functions are essentially variables, with a block as their value, which starts with lambda.open
, ends with lambda.close
and contains the instructions that should be executed.
This is what an empty function looks like:
Now let's make the function print "ABC", and then call it via funcall
.
The output is ABC
as expected.
Every pixel between lambda.open
and the first instruction of the block is read as a function argument.
Let's try editing the previous function so that the printed value comes from an argument :
Now let's call the function with "ABC" as a parameter.
Keep in mind that each parameter is a single pixel, therefore we must store "ABC" into a temporary variable :
Functions can return values. To do so, use a return
followed by the value to be returned.
Pseudocode:
function func() {
var value = "ABC"
return value
}
print(func())
Pikt:
A return
statement can also come without any value if the function does not expect an output value.