Learn: Control Flow
The global Module provide some symbols that can be used for the most common control flow statements. Unlike most programming languages, min does not differentiate between functions and statements – control flow statements are just ordinary symbols that manipulate the main stack.
Conditionals
The following symbols provide ways to implement common conditional statements:
For example, consider the following program:
This program defines a symbol display-file-info that takes a file name and outputs a message displaying its type if known.
Loops
The following symbols provide ways to implement common loops:
For example, consider the following program:
This program defines a symbol factorial that calculates the factorial of an integer iteratively using the symbol while.
Error handling
The following symbols provide ways to manage errors in min:
For example, consider the following program:
This program calculates the size in bytes of all files included in the current directory. Because the fs.size symbol throws an error if the argument provided is not a file (for example, if it is a directory), the try symbol is used to remove the error from the stack and push 0 on the stack instead.
→ Continue to Shell