Button handy | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
Info |
---|
This page provides a foundational overview of how Simple Issue Language (SIL™) programs are organized and gives a concrete example of the structure of a SIL program. Understanding the basic components of the structure will help you contextualize all other concepts introduced later in this guide. |
Structural components
Inclusions
Include statements must appear first or after use declarations.
They use the
#include
directive.They allow you to import libraries of user-defined functions or add code fragments to your program.
Imported files' names typically end with the
.sil
extension.
Info |
---|
Learn moreFor more information, see |
Use declarations
SIL uses packages to streamline function naming and usage and make code more concise.
Packages allow functions to be called by short names, reducing typing effort.
To use short names for functions, you must declare package uses.
Info |
---|
Learn moreFor more information and usage, see Packages. |
Variable declarations
In this section of the SIL program, you declare global variables available throughout the program.
You can declare various types of variables, such as
string
,number
, andarray
.Variables can be initialized with default values.
It is a best practice to group related variables together.
Info |
---|
Learn moreFor more information and usage, see the Variables section on the SIL Syntax and types introduction page. |
User-defined functions declarations
In this section of your SIL program, you can define any functions you want to use in the main code. These user-defined functions (UDFs) can considerably improve the readability and maintainability of the code.
UDRs must be defined before use, and their names cannot contain spaces.
Each function should have:
Clear name indicating its purpose
Defined parameter types
Return type specification
Proper documentation
Info |
---|
Learn moreFor more information, see User-defined functions (UDFs). |
Actual code
This is the main body of the program, which contains the primary logic. This is where you input the modifications you want the program to accomplish. The main body can also contain the definition of local variables and calls to the imported or user-defined functions in the steps above. It should end with a return
statement.
SIL program example
This SIL program example demonstrates the basic structure of a SIL program while performing a common task:
Process an issue record to ensure its description field doesn't exceed a maximum length.
Truncate the text and add an ellipsis if the description field exceeds the maximum length.
Code Block |
---|
// ================== INCLUSIONS ================== include "custom_utils.incl" // ================== USE DECLARATIONS ================== use "file"; // ================== VARIABLE DECLARATIONS ================== const int max_length = 50; // ================== USER-DEFINED functionS ================== function truncateDescription(string desc) { if (length(desc) > max_length) { return substring(desc, 0, max_length) + "..."; } return desc; } // ================== ACTUAL CODE (MAIN BODY) ================== description = truncateDescription(description); int fid = open(key + "-file.txt"); write(fid, description); close(fid); |
The use of inclusions, standard packages, global variables, and custom functions in this example demonstrates the structural organization and modularity of SIL programs.
This breakdown highlights how the different sections of the SIL program work together to achieve the overall goal of truncating long issue descriptions:
Component | Description |
---|---|
Inclusions | The Files must exist in the root of the hierarchy (that is silprograms directory). |
Package declarations |
|
Variable declarations | The |
User-defined functions | The |
Actual code (main body) |
|