Section concept

Level define sections of code to split a large program into smaller, manageable parts. It is an abstract concept used to implement separation of concerns architecture principle. The section keyword do not actually exist in Level.

Sections are a general language structure. This can help compiler developers to organize the code. Compiler will decide what kind of section to deal with and parse the code accordingly. In this article we explain section syntax and enumerate the sections types implemented.

Unnamed sections

These sections start with “let” or “for” keyword:

[let | for] 
end <section_type>;

Note: “let”  keyword is optional. It can be used with all anonymous blocks except “for”.

section scope:
Keyword “let” define a local scope. User can define one or more local variables here. This variables are called “control variables” and can be initialized with a literal or expression from parent scope or use type inference to define new variables.

section body:
The section body contains one or more statements that execute once or multiple times depending on section type. Executable region can be terminated normally or early using a conditional exit point or exception.

Named sections

Named sections are larger then the anonymous sections. These kind of sections have a name and can receive parameters.

<section_type> section_name(<parameters>) is
end <section_type>;


Anonymous sections are introduced in Level-1 and 2:

  • Level-1: { do, if, loop, switch, check, step}
  • Level-2: { for, job }

Named sections are gradually defined in Level (1,2,3):

  • Level-1: { program,  procedure,  function  };
  • Level-2: { method, closure, generator, coroutine };
  • Level-3: { class, feature };

Nested Sections

Sections can be nested in a parent child relation. Each section has a local scope. The visibility of member elements is from outer scope to inner scope as a hierarchical tree. Declared elements of a parent section are visible in a child section but elements defined in a child section are not visible in the parent section.


Programs can be implemented only in the module scope not in the local scope of another section.  Procedures can have nested procedures or static functions. Static functions can have local functions but not procedures. Methods can be defined only in the module scope after type definition. Methods can have local functions. Local scope created using Let do not allow creation of local procedures, functions, types and methods.

Relation is 1:M in this direction.



Section regions

A section of code have two regions: The “declaration” regions and the “executable” region. The regions are divided in sub-regions using keywords: {is, begin, step, recover, finalize}. Keywords {step, recover, finalize} are optional. Steps are indented 2 spaces after begin keyword.

Declaration region

For named sections declaration region start after the name of section before “begin” or “export”. This region create a “name space” that contains definition of members: {variable, procedure, method, function }.

For unnamed sections we use “let” keyword to create a local scope. This scope is available in section: {if, switch, check, loop, job} and is terminated with keywords: end <section_type>. Let region can contain only variables no types and no local functions.

Executable region

Usually there is only one executable region for a section. Executable region is between “begin” keyword and recover or finalize or end of program. This region contains steps, expressions, procedure calls and nested unnamed sections.

Executable region can be normally terminated when all the statements are executed. In case of exception the normal execution is intrerupted and the recover region is executed. After first executable region is executed the finalization region is executed also all the time even if we had an error.

Recover region

Define an “exception handling region”. This region is executed when an exception is raised. Consist of a series of decision statements based on “error.code”. The recover section is executed before the finalization region. Here we can use decision statements: (if, when, switch) or selector  (check … match). The most common way is to use “when” decisions.

  when exception.code == <code> then
  when exception.code == <code> then 
end <section>;

Finalize Region

This region is executed before the program control is released to the parent section. Finalize region is executed regardless of termination case. Normal termination or early termination will continue with finalize. Notice finalize is executed after recover region.

Programmer will close any file or connection to databases or other resources that may be reserved for the section. Resources that are locked and not released may remain locked for a while until the program terminates and the operating system release the locked resources.

Note: The recover and finalize regions are available for named sections: { program, module, procedure, function, class } and not available for unnamed sections.

You need to login to view the rest of the content. Please . Not a Member? Join Us