Nested block structures

Block forms can be defined and/or called within the context of other block structures, providing a powerful and expressive mechanism for controlling query execution and behavior.

The block layer of the 1010data Macro Language provides the mechanism by which queries can be modularized and parameterized. It is often very useful to define and/or call one block during the execution of another. In other words, blocks can behave like nested functions and closures.

There are numerous block forms that can be used to specify the way query execution behaves. This topic will cover each, but the first distinction that needs to be drawn is that between named and unnamed block forms.

Unnamed block forms execute within a query wherever they are defined. They cannot be named and cannot accept parameters.

The following block forms can be used to define logic that will execute as soon as it appears within a query:
  • <isolate> - A non-closure nested form. <isolate> cannot capture values from its enclosing context.
  • <blocklet> - A partial closure. <blocklet> can capture values from its enclosing context, but modifications to values it captured do not persist after its execution is complete.
  • <let> - A full closure. <expand> can capture values from its enclosing context, and modifications to values it captured persist after execution is complete.

Named block forms are defined in one place, such as a <library>, and can be called within the context of another block form.

The following block forms can be named and called explicitly using <call>, <insert>, or<expand>:
  • <block> - If defined as part of a library, it must be named and will only execute when explicitly called by name using one of the invocation methods listed below.
  • <defblock> - Must be named and will only execute when explicitly called by name using one of the invocation methods listed below.
There are three different ways to invoke a named block. Each of the methods below will cause the named block being invoked to behave differently within the execution context of its enclosing form. The following methods may be used to invoke a named block:
  • <call> - When invoked using <call>, a named block cannot capture values from its enclosing context. Causes the named block to behave like an <isolate> structure.
  • <insert> - When invoked using <insert>, a named block can capture values from its enclosing context, but modifications to values it captured do not persist after execution. Causes a named block to behave like a <blocklet> structure.
  • <expand> - When invoked using <expand>, a named block can capture values from its enclosing context, and modifications to values it captured persist after execution. Causes a named block to behave like a <let> form.